* core/all.hh
* debug/all.hh
* text/all.hh
* filter/all.hh
* table/all.hh
* demo/Makefile.am
* src/Makefile.am
* src/extract/primitive/Makefile.am
* core/erase_bboxes.hh: move...
* core/erase_objects.hh: ...here.
* debug/save_textbboxes_image.hh: move...
* debug/save_bboxes_image.hh: ...here.
* debug/save_label_image.hh,
* debug/save_linked_bboxes_image.hh,
* debug/save_linked_textbboxes_image.hh,
* debug/usage.hh,
* extract/lines_discontinued.hh,
* extract/primitive/canvas.hh,
* extract/primitive/cells.hh,
* extract/primitive/lines_discontinued.hh,
* filter/small_objects.hh,
* filter/thin_objects.hh,
* make/influence_zone_graph.hh,
* src/binarization/simple.cc,
* src/extract/primitive/extract_discontinued_hlines.cc,
* src/extract/primitive/extract_discontinued_lines.cc,
* src/extract/primitive/extract_discontinued_vlines.cc,
* src/extract/primitive/extract_thick_hlines.cc,
* src/extract/primitive/extract_thick_vlines.cc,
* src/extract/primitive/find_discontinued_lines.cc,
* src/extract_text_double_link.cc,
* src/extract_text_double_several_links.cc,
* src/extract_text_graph.cc,
* src/extract_text_several_graph.cc,
* src/extract_text_several_left_links.cc,
* src/extract_text_single_link.cc,
* src/morpho.cc,
* src/negate.cc,
* src/preprocess.cc,
* src/preprocessing/unskew.cc,
* src/recognition.cc,
* src/superpose.cc,
* src/table/erase.cc,
* src/table/extract.cc,
* src/table_rebuild_opening.cc,
* src/table_rebuild_rank.cc,
* src/text_in_photo.cc,
* src/thin_bboxes.cc,
* table/align_lines_horizontaly.hh,
* table/align_lines_verticaly.hh,
* table/connect_horizontal_lines.hh,
* table/connect_vertical_lines.hh,
* table/erase.hh,
* table/extract.hh,
* table/internal/align_lines.hh,
* table/internal/connect_lines.hh,
* table/internal/repair_lines.hh,
* table/rebuild.hh,
* table/repair_horizontal_lines.hh,
* table/repair_vertical_lines.hh,
* tests/filter/small_and_large_bboxes.cc,
* tests/preprocessing/unskew.cc,
* tests/table/extract_lines_with_rank.cc,
* tests/table/repair_lines.cc,
* text/clean.hh,
* text/extract_lines.hh,
* text/grouping/group_from_double_link.hh,
* text/grouping/group_from_graph.hh,
* text/grouping/group_from_single_link.hh,
* text/grouping/group_with_graph.hh,
* text/grouping/group_with_several_graphes.hh,
* text/grouping/group_with_several_right_links.hh,
* text/grouping/internal/find_graph_link.hh,
* text/grouping/internal/find_right_link.hh,
* text/grouping/internal/update_graph_link.hh,
* text/grouping/internal/update_link_array.hh: fix compilation.
- Add missing includes.
- Use object image.
* tests/unit_test/build_unit_test.sh: do not use some files for unit
tests.
* tests/unit_test/unit-tests.mk: update list.
---
scribo/ChangeLog | 92 +++++++
scribo/core/all.hh | 6 +-
scribo/core/{erase_bboxes.hh => erase_objects.hh} | 39 ++--
scribo/debug/all.hh | 4 +-
...ve_textbboxes_image.hh => save_bboxes_image.hh} | 30 +-
scribo/debug/save_label_image.hh | 14 +-
scribo/debug/save_linked_bboxes_image.hh | 268 ++++++++++++++++++++
scribo/debug/save_linked_textbboxes_image.hh | 253 ------------------
scribo/debug/usage.hh | 67 ++++-
scribo/demo/Makefile.am | 8 +-
.../extract/{primitive => }/lines_discontinued.hh | 66 ++++-
scribo/extract/primitive/canvas.hh | 5 +-
scribo/extract/primitive/cells.hh | 38 ++-
scribo/extract/primitive/lines_discontinued.hh | 8 +-
scribo/filter/all.hh | 8 +-
scribo/filter/small_objects.hh | 11 +-
scribo/filter/thin_objects.hh | 3 +-
scribo/make/influence_zone_graph.hh | 13 +-
scribo/src/Makefile.am | 54 ++--
scribo/src/binarization/simple.cc | 6 +-
scribo/src/extract/primitive/Makefile.am | 6 +-
.../primitive/extract_discontinued_hlines.cc | 4 +-
...ued_vlines.cc => extract_discontinued_lines.cc} | 28 ++-
.../primitive/extract_discontinued_vlines.cc | 4 +-
.../src/extract/primitive/extract_thick_hlines.cc | 4 +-
.../src/extract/primitive/extract_thick_vlines.cc | 4 +-
...tinued_vlines.cc => find_discontinued_lines.cc} | 32 ++-
scribo/src/extract_text_double_link.cc | 40 ++--
scribo/src/extract_text_double_several_links.cc | 36 ++--
scribo/src/extract_text_graph.cc | 32 ++--
scribo/src/extract_text_several_graph.cc | 31 +--
scribo/src/extract_text_several_left_links.cc | 32 ++--
scribo/src/extract_text_single_link.cc | 58 ++--
scribo/src/morpho.cc | 4 +-
scribo/src/negate.cc | 6 +-
.../src/{binarization/simple.cc => preprocess.cc} | 35 ++-
scribo/src/preprocessing/unskew.cc | 6 +-
scribo/src/recognition.cc | 7 +-
scribo/src/superpose.cc | 8 +-
scribo/src/table/erase.cc | 14 +-
scribo/src/table/extract.cc | 8 +-
scribo/src/table_rebuild_opening.cc | 36 ++-
scribo/src/table_rebuild_rank.cc | 36 ++-
scribo/src/text_in_photo.cc | 20 +-
scribo/src/thin_bboxes.cc | 10 +-
scribo/table/align_lines_horizontaly.hh | 18 +-
scribo/table/align_lines_verticaly.hh | 10 +-
scribo/table/all.hh | 13 +-
scribo/table/connect_horizontal_lines.hh | 17 +-
scribo/table/connect_vertical_lines.hh | 12 +-
scribo/table/erase.hh | 34 ++--
scribo/table/extract.hh | 20 +-
scribo/table/internal/align_lines.hh | 14 +-
scribo/table/internal/connect_lines.hh | 29 ++-
scribo/table/internal/repair_lines.hh | 18 +-
scribo/table/rebuild.hh | 24 +-
scribo/table/repair_horizontal_lines.hh | 8 +-
scribo/table/repair_vertical_lines.hh | 8 +-
scribo/tests/filter/small_and_large_bboxes.cc | 36 ++--
scribo/tests/preprocessing/unskew.cc | 9 +-
scribo/tests/table/extract_lines_with_rank.cc | 12 +-
scribo/tests/table/repair_lines.cc | 7 -
scribo/tests/unit_test/build_unit_test.sh | 8 +-
scribo/tests/unit_test/unit-tests.mk | 16 +-
scribo/text/all.hh | 4 +-
scribo/text/clean.hh | 19 ++-
scribo/text/extract_lines.hh | 44 ++--
scribo/text/grouping/group_from_double_link.hh | 2 +
scribo/text/grouping/group_from_graph.hh | 36 ++--
scribo/text/grouping/group_from_single_link.hh | 52 ++---
scribo/text/grouping/group_with_graph.hh | 20 +-
scribo/text/grouping/group_with_several_graphes.hh | 39 ++--
.../grouping/group_with_several_right_links.hh | 3 +
scribo/text/grouping/internal/find_graph_link.hh | 14 +-
scribo/text/grouping/internal/find_right_link.hh | 21 +-
scribo/text/grouping/internal/update_graph_link.hh | 13 +
scribo/text/grouping/internal/update_link_array.hh | 13 +-
77 files changed, 1246 insertions(+), 841 deletions(-)
rename scribo/core/{erase_bboxes.hh => erase_objects.hh} (67%)
rename scribo/debug/{save_textbboxes_image.hh => save_bboxes_image.hh} (74%)
create mode 100644 scribo/debug/save_linked_bboxes_image.hh
delete mode 100644 scribo/debug/save_linked_textbboxes_image.hh
copy scribo/extract/{primitive => }/lines_discontinued.hh (70%)
copy scribo/src/extract/primitive/{extract_discontinued_vlines.cc =>
extract_discontinued_lines.cc} (73%)
copy scribo/src/extract/primitive/{extract_discontinued_vlines.cc =>
find_discontinued_lines.cc} (69%)
copy scribo/src/{binarization/simple.cc => preprocess.cc} (64%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 7129cb2..d6ce297 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,97 @@
2009-06-10 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Fix Scribo
+
+ * core/all.hh
+ * debug/all.hh
+ * text/all.hh
+ * filter/all.hh
+ * table/all.hh
+
+ * demo/Makefile.am
+ * src/Makefile.am
+ * src/extract/primitive/Makefile.am
+
+ * core/erase_bboxes.hh: move...
+ * core/erase_objects.hh: ...here.
+
+ * debug/save_textbboxes_image.hh: move...
+ * debug/save_bboxes_image.hh: ...here.
+
+ * debug/save_label_image.hh,
+ * debug/save_linked_bboxes_image.hh,
+ * debug/save_linked_textbboxes_image.hh,
+ * debug/usage.hh,
+ * extract/lines_discontinued.hh,
+ * extract/primitive/canvas.hh,
+ * extract/primitive/cells.hh,
+ * extract/primitive/lines_discontinued.hh,
+ * filter/small_objects.hh,
+ * filter/thin_objects.hh,
+ * make/influence_zone_graph.hh,
+ * src/binarization/simple.cc,
+ * src/extract/primitive/extract_discontinued_hlines.cc,
+ * src/extract/primitive/extract_discontinued_lines.cc,
+ * src/extract/primitive/extract_discontinued_vlines.cc,
+ * src/extract/primitive/extract_thick_hlines.cc,
+ * src/extract/primitive/extract_thick_vlines.cc,
+ * src/extract/primitive/find_discontinued_lines.cc,
+ * src/extract_text_double_link.cc,
+ * src/extract_text_double_several_links.cc,
+ * src/extract_text_graph.cc,
+ * src/extract_text_several_graph.cc,
+ * src/extract_text_several_left_links.cc,
+ * src/extract_text_single_link.cc,
+ * src/morpho.cc,
+ * src/negate.cc,
+ * src/preprocess.cc,
+ * src/preprocessing/unskew.cc,
+ * src/recognition.cc,
+ * src/superpose.cc,
+ * src/table/erase.cc,
+ * src/table/extract.cc,
+ * src/table_rebuild_opening.cc,
+ * src/table_rebuild_rank.cc,
+ * src/text_in_photo.cc,
+ * src/thin_bboxes.cc,
+ * table/align_lines_horizontaly.hh,
+ * table/align_lines_verticaly.hh,
+ * table/connect_horizontal_lines.hh,
+ * table/connect_vertical_lines.hh,
+ * table/erase.hh,
+ * table/extract.hh,
+ * table/internal/align_lines.hh,
+ * table/internal/connect_lines.hh,
+ * table/internal/repair_lines.hh,
+ * table/rebuild.hh,
+ * table/repair_horizontal_lines.hh,
+ * table/repair_vertical_lines.hh,
+ * tests/filter/small_and_large_bboxes.cc,
+ * tests/preprocessing/unskew.cc,
+ * tests/table/extract_lines_with_rank.cc,
+ * tests/table/repair_lines.cc,
+ * text/clean.hh,
+ * text/extract_lines.hh,
+ * text/grouping/group_from_double_link.hh,
+ * text/grouping/group_from_graph.hh,
+ * text/grouping/group_from_single_link.hh,
+ * text/grouping/group_with_graph.hh,
+ * text/grouping/group_with_several_graphes.hh,
+ * text/grouping/group_with_several_right_links.hh,
+ * text/grouping/internal/find_graph_link.hh,
+ * text/grouping/internal/find_right_link.hh,
+ * text/grouping/internal/update_graph_link.hh,
+ * text/grouping/internal/update_link_array.hh: fix compilation.
+ - Add missing includes.
+ - Use object image.
+
+ * tests/unit_test/build_unit_test.sh: do not use some files for unit
+ tests.
+
+ * tests/unit_test/unit-tests.mk: update list.
+
+2009-06-10 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add Scribo's demo GUI.
* demo/Makefile.am,
diff --git a/scribo/core/all.hh b/scribo/core/all.hh
index 39f0f90..76177b0 100644
--- a/scribo/core/all.hh
+++ b/scribo/core/all.hh
@@ -41,9 +41,9 @@ namespace scribo
} // end of namespace scribo
-#include <scribo/core/component_bboxes.hh>
-#include <scribo/core/macros.hh>
#include <scribo/core/central_sites.hh>
-#include <scribo/core/erase_bboxes.hh>
+#include <scribo/core/erase_objects.hh>
+#include <scribo/core/macros.hh>
+#include <scribo/core/object_image.hh>
#endif // ! SCRIBO_CORE_ALL_HH
diff --git a/scribo/core/erase_bboxes.hh b/scribo/core/erase_objects.hh
similarity index 67%
rename from scribo/core/erase_bboxes.hh
rename to scribo/core/erase_objects.hh
index 06a930c..da003b1 100644
--- a/scribo/core/erase_bboxes.hh
+++ b/scribo/core/erase_objects.hh
@@ -23,10 +23,10 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_CORE_ERASE_BBOXES_HH
-# define SCRIBO_CORE_ERASE_BBOXES_HH
+#ifndef SCRIBO_CORE_ERASE_OBJECTS_HH
+# define SCRIBO_CORE_ERASE_OBJECTS_HH
-/// \file scribo/core/erase_bboxes.hh
+/// \file scribo/core/erase_objects.hh
///
/// Remove the content of bounding boxes from an image.
@@ -37,39 +37,46 @@
# include <mln/util/array.hh>
# include <scribo/core/macros.hh>
+# include <scribo/core/object_image.hh>
namespace scribo
{
using namespace mln;
- /// Remove the content of bounding boxes from an image.
- template <typename I>
+ /// Remove labeled components from a binary image.
+ ///
+ /// \param[in,out] input_ A binary image.
+ /// \param[in] objects An object image. Objects will be set to
+ /// false in \p input_.
+ ///
+ //
+ template <typename I, typename L>
void
- erase_bboxes(Image<I>& input_,
- const util::array< box<mln_site(I)> >& bboxes);
+ erase_objects(Image<I>& input_,
+ const object_image(L)& objects);
# ifndef MLN_INCLUDE_ONLY
- template <typename I>
+ template <typename I, typename L>
void
- erase_bboxes(Image<I>& input_,
- const util::array< box<mln_site(I)> >& bboxes)
+ erase_objects(Image<I>& input_,
+ const object_image(L)& objects)
{
- trace::entering("scribo::erase_bboxes");
+ trace::entering("scribo::erase_objects");
mlc_equal(mln_value(I),bool)::check();
I& input = exact(input_);
mln_precondition(input.is_valid());
+ mln_precondition(objects.is_valid());
- for_all_components(i, bboxes)
- data::paste((pw::cst(false) | bboxes[i] |
- (pw::value(input) == true)), input);
+ data::fill((input | (pw::value(objects) != pw::cst(literal::zero))).rw(),
+ false);
- trace::exiting("scribo::erase_bboxes");
+ trace::exiting("scribo::erase_objects");
}
@@ -77,4 +84,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_CORE_ERASE_BBOXES_HH
+#endif // ! SCRIBO_CORE_ERASE_OBJECTS_HH
diff --git a/scribo/debug/all.hh b/scribo/debug/all.hh
index ecb3608..a6f3294 100644
--- a/scribo/debug/all.hh
+++ b/scribo/debug/all.hh
@@ -41,9 +41,9 @@ namespace scribo
} // end of namespace scribo
+# include <scribo/debug/save_bboxes_image.hh>
# include <scribo/debug/save_label_image.hh>
-# include <scribo/debug/save_linked_textbboxes_image.hh>
+# include <scribo/debug/save_linked_bboxes_image.hh>
# include <scribo/debug/save_table_image.hh>
-# include <scribo/debug/save_textbboxes_image.hh>
#endif // ! SCRIBO_DEBUG_ALL_HH
diff --git a/scribo/debug/save_textbboxes_image.hh b/scribo/debug/save_bboxes_image.hh
similarity index 74%
rename from scribo/debug/save_textbboxes_image.hh
rename to scribo/debug/save_bboxes_image.hh
index a7b23ce..0265ee4 100644
--- a/scribo/debug/save_textbboxes_image.hh
+++ b/scribo/debug/save_bboxes_image.hh
@@ -23,10 +23,10 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_DEBUG_SAVE_TEXTBBOXES_IMAGE_HH
-# define SCRIBO_DEBUG_SAVE_TEXTBBOXES_IMAGE_HH
+#ifndef SCRIBO_DEBUG_SAVE_BBOXES_IMAGE_HH
+# define SCRIBO_DEBUG_SAVE_BBOXES_IMAGE_HH
-/// \file scribo/draw/bounding_boxes.hh
+/// \file
///
/// Draw a list of bounding boxes and their associated mass center.
@@ -51,10 +51,10 @@ namespace scribo
/// Draw a list of bounding boxes and their associated mass center.
template <typename I>
void
- save_textbboxes_image(const Image<I>& input,
- const mln::util::array< box<mln_site(I)> >& textbboxes,
- const value::rgb8& value,
- const std::string& filename);
+ save_bboxes_image(const Image<I>& input,
+ const mln::util::array< box<mln_site(I)> >& bboxes,
+ const value::rgb8& value,
+ const std::string& filename);
# ifndef MLN_INCLUDE_ONLY
@@ -62,19 +62,19 @@ namespace scribo
template <typename I>
inline
void
- save_textbboxes_image(const Image<I>& input,
- const mln::util::array< box<mln_site(I)> >& textbboxes,
- const value::rgb8& value,
- const std::string& filename)
+ save_bboxes_image(const Image<I>& input,
+ const mln::util::array< box<mln_site(I)> >& bboxes,
+ const value::rgb8& value,
+ const std::string& filename)
{
- trace::entering("scribo::debug::save_textbboxes_image");
+ trace::entering("scribo::debug::save_bboxes_image");
mln_precondition(exact(input).is_valid());
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
- draw::bounding_boxes(tmp, textbboxes, value);
+ draw::bounding_boxes(tmp, bboxes, value);
io::ppm::save(tmp, filename);
- trace::exiting("scribo::debug::save_textbboxes_image");
+ trace::exiting("scribo::debug::save_bboxes_image");
}
# endif // ! MLN_INCLUDE_ONLY
@@ -84,4 +84,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_DEBUG_SAVE_TEXTBBOXES_IMAGE_HH
+#endif // ! SCRIBO_DEBUG_SAVE_BBOXES_IMAGE_HH
diff --git a/scribo/debug/save_label_image.hh b/scribo/debug/save_label_image.hh
index cf66b7c..b35dbc5 100644
--- a/scribo/debug/save_label_image.hh
+++ b/scribo/debug/save_label_image.hh
@@ -30,13 +30,25 @@
///
/// Save a labeled image in a color image.
+# include <mln/core/concept/image.hh>
+# include <mln/labeling/colorize.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/io/ppm/save.hh>
+
namespace scribo
{
namespace debug
{
+ using namespace mln;
+
/// Save a labeled image in a color image.
+ ///
+ /// \param[in] lbl A label image.
+ /// \param[in] nlabels The number of labels.
+ /// \param[in] filename The output file name.
+ //
template <typename I>
void
save_label_image(const Image<I>& lbl, const mln_value(I)& nlabels,
@@ -55,7 +67,7 @@ namespace scribo
mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
mln_precondition(exact(lbl).is_valid());
- io::ppm::save(labeling::colorize(rgb8(), lbl, nlabels), filename);
+ io::ppm::save(labeling::colorize(value::rgb8(), lbl, nlabels), filename);
trace::exiting("scribo::debug::save_label_image");
}
diff --git a/scribo/debug/save_linked_bboxes_image.hh
b/scribo/debug/save_linked_bboxes_image.hh
new file mode 100644
index 0000000..91d58b4
--- /dev/null
+++ b/scribo/debug/save_linked_bboxes_image.hh
@@ -0,0 +1,268 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_DEBUG_SAVE_LINKED_BBOXES_IMAGE_HH
+# define SCRIBO_DEBUG_SAVE_LINKED_BBOXES_IMAGE_HH
+
+/// \file scribo/draw/bounding_boxes.hh
+///
+/// Save the bounding box links image.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/graph.hh>
+# include <mln/labeling/compute.hh>
+# include <mln/accu/center.hh>
+# include <mln/data/convert.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/util/array.hh>
+# include <mln/io/ppm/save.hh>
+
+# include <scribo/core/object_image.hh>
+# include <scribo/draw/bounding_boxes.hh>
+# include <scribo/draw/bounding_box_links.hh>
+
+
+namespace scribo
+{
+
+ namespace debug
+ {
+
+ using namespace mln;
+
+
+ /// Save the line of objects links image.
+ ///
+ /// \param[in,out] input The binary from where the objects are extracted.
+ /// \param[in] objects An object image.
+ /// \param[in] link_array Lines of objects links.
+ /// \param[in] box_value Value used to draw line bounding boxes.
+ /// \param[in] link_value Value used to draw line links.
+ /// \param[in] filename The target file name.
+ template <typename I, typename L>
+ void
+ save_linked_bboxes_image(const Image<I>& input,
+ const object_image(L)& objects,
+ const mln::util::array<unsigned>& link_array,
+ const value::rgb8& box_value,
+ const value::rgb8& link_value,
+ const std::string& filename);
+
+ /// Save the line of objects left and right links image.
+ ///
+ /// \param[in,out] input The binary from where the objects are extracted.
+ /// \param[in] objects An object image.
+ /// \param[in] left_link Lines of objects left links.
+ /// \param[in] right_link Lines of objects right links.
+ /// \param[in] box_value Value used to draw line bounding boxes.
+ /// \param[in] link_value Value used to draw line links.
+ /// \param[in] filename The target file name.
+ template <typename I, typename L>
+ void
+ save_linked_bboxes_image(const Image<I>& input,
+ const object_image(L)& objects,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ const value::rgb8& box_value,
+ const value::rgb8& link_value,
+ const std::string& filename);
+
+ /// Save the line of objects left and right links image.
+ /// Draw also validated links.
+ ///
+ /// \param[in,out] input The binary from where the objects are extracted.
+ /// \param[in] objects An object image.
+ /// \param[in] left_link Lines of objects left links.
+ /// \param[in] right_link Lines of objects right links.
+ /// \param[in] box_value Value used to draw line bounding boxes.
+ /// \param[in] left_link_value Value used to draw line left links.
+ /// \param[in] right_link_value Value used to draw line left links.
+ /// \param[in] validated_link_value Value used to draw line validated links.
+ /// \param[in] filename The target file name.
+ template <typename I, typename L>
+ inline
+ void
+ save_linked_bboxes_image(const Image<I>& input,
+ const object_image(L)& objects,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ const value::rgb8& box_value,
+ const value::rgb8& left_link_value,
+ const value::rgb8& right_link_value,
+ const value::rgb8& validated_link_value,
+ const std::string& filename);
+
+
+ /// Save the line link graph image.
+ ///
+ /// \param[in,out] input The binary from where the objects are extracted.
+ /// \param[in] objects An object image.
+ /// \param[in] g The link graph.
+ /// \param[in] box_value Value used to draw line bounding boxes.
+ /// \param[in] link_value Value used to draw line links.
+ /// \param[in] filename The target file name.
+ template <typename I, typename L, typename G>
+ void
+ save_linked_bboxes_image(const Image<I>& input,
+ const object_image(L)& objects,
+ const Graph<G>& g,
+ const value::rgb8& box_value,
+ const value::rgb8& link_value,
+ const std::string& filename);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I, typename L>
+ inline
+ void
+ save_linked_bboxes_image(const Image<I>& input,
+ const object_image(L)& objects,
+ const mln::util::array<unsigned>& link_array,
+ const value::rgb8& box_value,
+ const value::rgb8& link_value,
+ const std::string& filename)
+ {
+ trace::entering("scribo::debug::save_linked_bboxes_image");
+ mln_precondition(exact(input).is_valid());
+
+ mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
+
+ mln::util::array<mln_result(accu::center<mln_psite(L)>)>
+ mass_center = labeling::compute(accu::meta::center(),
+ objects,
+ objects.nlabels());
+
+ draw::bounding_boxes(tmp, objects.bboxes(), box_value);
+ draw::bounding_box_links(tmp, mass_center, link_array, link_value);
+
+ io::ppm::save(tmp, filename);
+
+ trace::exiting("scribo::debug::save_linked_bboxes_image");
+ }
+
+
+ template <typename I, typename L>
+ inline
+ void
+ save_linked_bboxes_image(const Image<I>& input,
+ const object_image(L)& objects,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ const value::rgb8& box_value,
+ const value::rgb8& value,
+ const std::string& filename)
+ {
+ trace::entering("scribo::debug::save_linked_bboxes_image");
+ mln_precondition(exact(input).is_valid());
+
+ mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
+
+ mln::util::array<mln_result(accu::center<mln_psite(L)>)>
+ mass_center = labeling::compute(accu::meta::center(),
+ objects,
+ objects.nlabels());
+
+ draw::bounding_boxes(tmp, objects.bboxes(), box_value);
+ draw::bounding_box_links(tmp, mass_center,
+ left_link, right_link,
+ value);
+
+ io::ppm::save(tmp, filename);
+
+ trace::exiting("scribo::debug::save_linked_bboxes_image");
+ }
+
+
+ template <typename I, typename L>
+ inline
+ void
+ save_linked_bboxes_image(const Image<I>& input,
+ const object_image(L)& objects,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ const value::rgb8& box_value,
+ const value::rgb8& left_link_value,
+ const value::rgb8& right_link_value,
+ const value::rgb8& validated_link_value,
+ const std::string& filename)
+ {
+ trace::entering("scribo::debug::save_linked_bboxes_image");
+ mln_precondition(exact(input).is_valid());
+
+ mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
+
+ mln::util::array<mln_result(accu::center<mln_psite(L)>)>
+ mass_center = labeling::compute(accu::meta::center(),
+ objects,
+ objects.nlabels());
+
+ draw::bounding_boxes(tmp, objects.bboxes(), box_value);
+ draw::bounding_box_links(tmp, mass_center,
+ left_link, right_link,
+ left_link_value, right_link_value,
+ validated_link_value);
+
+ io::ppm::save(tmp, filename);
+
+ trace::exiting("scribo::debug::save_linked_bboxes_image");
+ }
+
+
+
+ template <typename I, typename L, typename G>
+ inline
+ void
+ save_linked_bboxes_image(const Image<I>& input,
+ const object_image(L)& objects,
+ const Graph<G>& g,
+ const value::rgb8& box_value,
+ const value::rgb8& link_value,
+ const std::string& filename)
+ {
+ trace::entering("scribo::debug::save_linked_bboxes_image");
+ mln_precondition(exact(g).is_valid());
+ mln_precondition(exact(input).is_valid());
+
+ mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
+
+ draw::bounding_boxes(tmp, objects.bboxes(), box_value);
+ draw::bounding_box_links(tmp, objects.bboxes(), g, link_value);
+
+ io::ppm::save(tmp, filename);
+
+ trace::exiting("scribo::debug::save_linked_bboxes_image");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::debug
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_DEBUG_SAVE_LINKED_BBOXES_IMAGE_HH
diff --git a/scribo/debug/save_linked_textbboxes_image.hh
b/scribo/debug/save_linked_textbboxes_image.hh
deleted file mode 100644
index b98defc..0000000
--- a/scribo/debug/save_linked_textbboxes_image.hh
+++ /dev/null
@@ -1,253 +0,0 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
-//
-// This file is part of Olena.
-//
-// Olena is free software: you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free
-// Software Foundation, version 2 of the License.
-//
-// Olena is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Olena. If not, see <http://www.gnu.org/licenses/>.
-//
-// As a special exception, you may use this file as part of a free
-// software project without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to produce
-// an executable, this file does not by itself cause the resulting
-// executable to be covered by the GNU General Public License. This
-// exception does not however invalidate any other reasons why the
-// executable file might be covered by the GNU General Public License.
-
-#ifndef SCRIBO_DEBUG_SAVE_LINKED_TEXTBBOXES_IMAGE_HH
-# define SCRIBO_DEBUG_SAVE_LINKED_TEXTBBOXES_IMAGE_HH
-
-/// \file scribo/draw/bounding_boxes.hh
-///
-/// Save the bounding box links image.
-
-# include <mln/core/concept/image.hh>
-# include <mln/core/concept/graph.hh>
-# include <mln/labeling/compute.hh>
-# include <mln/accu/center.hh>
-# include <mln/data/convert.hh>
-# include <mln/value/rgb8.hh>
-# include <mln/util/array.hh>
-# include <mln/io/ppm/save.hh>
-
-# include <scribo/draw/bounding_boxes.hh>
-# include <scribo/draw/bounding_box_links.hh>
-# include <scribo/util/text.hh>
-
-
-namespace scribo
-{
-
- namespace debug
- {
-
- using namespace mln;
-
-
- /// Save the line of text links image.
- ///
- /// \param[in,out] input The binary from where the text is extracted.
- /// \param[in] text The lines of text.
- /// \param[in] link_array Lines of text links.
- /// \param[in] box_value Value used to draw line bounding boxes.
- /// \param[in] link_value Value used to draw line links.
- /// \param[in] filename The target file name.
- template <typename I, typename L>
- void
- save_linked_textbboxes_image(const Image<I>& input,
- const scribo::util::text<L>& text,
- const mln::util::array<unsigned>& link_array,
- const value::rgb8& box_value,
- const value::rgb8& link_value,
- const std::string& filename);
-
- /// Save the line of text left and right links image.
- ///
- /// \param[in,out] input The binary from where the text is extracted.
- /// \param[in] text The lines of text.
- /// \param[in] left_link Lines of text left links.
- /// \param[in] right_link Lines of text right links.
- /// \param[in] box_value Value used to draw line bounding boxes.
- /// \param[in] link_value Value used to draw line links.
- /// \param[in] filename The target file name.
- template <typename I, typename L>
- void
- save_linked_textbboxes_image(const Image<I>& input,
- const scribo::util::text<L>& text,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
- const value::rgb8& box_value,
- const value::rgb8& link_value,
- const std::string& filename);
-
- /// Save the line of text left and right links image.
- /// Draw also validated links.
- ///
- /// \param[in,out] input The binary from where the text is extracted.
- /// \param[in] text The lines of text.
- /// \param[in] left_link Lines of text left links.
- /// \param[in] right_link Lines of text right links.
- /// \param[in] box_value Value used to draw line bounding boxes.
- /// \param[in] left_link_value Value used to draw line left links.
- /// \param[in] right_link_value Value used to draw line left links.
- /// \param[in] validated_link_value Value used to draw line validated links.
- /// \param[in] filename The target file name.
- template <typename I, typename L>
- inline
- void
- save_linked_textbboxes_image(const Image<I>& input,
- const scribo::util::text<L>& text,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
- const value::rgb8& box_value,
- const value::rgb8& left_link_value,
- const value::rgb8& right_link_value,
- const value::rgb8& validated_link_value,
- const std::string& filename);
-
-
- /// Save the line link graph image.
- ///
- /// \param[in,out] input The binary from where the text is extracted.
- /// \param[in] text The lines of text.
- /// \param[in] g The link graph.
- /// \param[in] box_value Value used to draw line bounding boxes.
- /// \param[in] link_value Value used to draw line links.
- /// \param[in] filename The target file name.
- template <typename I, typename L, typename G>
- void
- save_linked_textbboxes_image(const Image<I>& input,
- const scribo::util::text<L>& text,
- const Graph<G>& g,
- const value::rgb8& box_value,
- const value::rgb8& link_value,
- const std::string& filename);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
-
- template <typename I, typename L>
- inline
- void
- save_linked_textbboxes_image(const Image<I>& input,
- const scribo::util::text<L>& text,
- const mln::util::array<unsigned>& link_array,
- const value::rgb8& box_value,
- const value::rgb8& link_value,
- const std::string& filename)
- {
- trace::entering("scribo::debug::save_linked_textbboxes_image");
- mln_precondition(exact(input).is_valid());
-
- mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
-
- draw::bounding_boxes(tmp, text.bboxes(), box_value);
- draw::bounding_box_links(tmp, text.mass_centers(), link_array, link_value);
-
- io::ppm::save(tmp, filename);
-
- trace::exiting("scribo::debug::save_linked_textbboxes_image");
- }
-
-
- template <typename I, typename L>
- inline
- void
- save_linked_textbboxes_image(const Image<I>& input,
- const scribo::util::text<L>& text,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
- const value::rgb8& box_value,
- const value::rgb8& value,
- const std::string& filename)
- {
- trace::entering("scribo::debug::save_linked_textbboxes_image");
- mln_precondition(exact(input).is_valid());
-
- mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
-
- draw::bounding_boxes(tmp, text.bboxes(), box_value);
- draw::bounding_box_links(tmp, text.mass_centers(),
- left_link, right_link,
- value);
-
- io::ppm::save(tmp, filename);
-
- trace::exiting("scribo::debug::save_linked_textbboxes_image");
- }
-
-
- template <typename I, typename L>
- inline
- void
- save_linked_textbboxes_image(const Image<I>& input,
- const scribo::util::text<L>& text,
- const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link,
- const value::rgb8& box_value,
- const value::rgb8& left_link_value,
- const value::rgb8& right_link_value,
- const value::rgb8& validated_link_value,
- const std::string& filename)
- {
- trace::entering("scribo::debug::save_linked_textbboxes_image");
- mln_precondition(exact(input).is_valid());
-
- mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
-
- draw::bounding_boxes(tmp, text.bboxes(), box_value);
- draw::bounding_box_links(tmp, text.mass_centers(),
- left_link, right_link,
- left_link_value, right_link_value,
- validated_link_value);
-
- io::ppm::save(tmp, filename);
-
- trace::exiting("scribo::debug::save_linked_textbboxes_image");
- }
-
-
-
- template <typename I, typename L, typename G>
- inline
- void
- save_linked_textbboxes_image(const Image<I>& input,
- const scribo::util::text<L>& text,
- const Graph<G>& g,
- const value::rgb8& box_value,
- const value::rgb8& link_value,
- const std::string& filename)
- {
- trace::entering("scribo::debug::save_linked_textbboxes_image");
- mln_precondition(exact(g).is_valid());
- mln_precondition(exact(input).is_valid());
-
- mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
-
- draw::bounding_boxes(tmp, text.bboxes(), box_value);
- draw::bounding_box_links(tmp, text.bboxes(), g, link_value);
-
- io::ppm::save(tmp, filename);
-
- trace::exiting("scribo::debug::save_linked_textbboxes_image");
- }
-
-
-# endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace scribo::debug
-
-} // end of namespace scribo
-
-
-#endif // ! SCRIBO_DEBUG_SAVE_LINKED_TEXTBBOXES_IMAGE_HH
diff --git a/scribo/debug/usage.hh b/scribo/debug/usage.hh
index 9fc7ff6..f821ead 100644
--- a/scribo/debug/usage.hh
+++ b/scribo/debug/usage.hh
@@ -23,19 +23,56 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-int usage(char* argv[], const char *desc, const char* args,
- const char*args_desc[][2], const char *out_desc)
+#ifndef SCRIBO_DEBUG_USAGE_HH
+# define SCRIBO_DEBUG_USAGE_HH
+
+#include <iostream>
+
+namespace scribo
{
- std::cout << desc << std::endl;
- std::cout << "-----------" << std::endl;
- std::cout << "Usage: " << argv[0] << " " <<
args << std::endl;
-
- for (unsigned i = 0; args_desc[i][0] != 0; ++i)
- std::cout << " " << args_desc[i][0] << ": "
<< args_desc[i][1]
- << std::endl;
-
- std::cout << std::endl << "Output: " << out_desc <<
std::endl;
- std::cout << "-----------" << std::endl;
- std::cout << "EPITA/LRDE - Scribo 2009" << std::endl;
- return 1;
-}
+
+ namespace debug
+ {
+
+ /// Format a standard usage output.
+ ///
+ /// \param[in] argv Arguments passed to the program.
+ /// \param[in] desc Description of the program.
+ /// \param[in] args The expected arguments.
+ /// \param[in] args_desc The description of the expected arguments.
+ /// \param[in] out_desc The description of the output.
+ ///
+ /// \return Return 1.
+ //
+ int usage(char* argv[], const char *desc, const char* args,
+ const char*args_desc[][2], const char *out_desc);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ inline
+ int
+ usage(char* argv[], const char *desc, const char* args,
+ const char*args_desc[][2], const char *out_desc)
+ {
+ std::cout << desc << std::endl;
+ std::cout << "-----------" << std::endl;
+ std::cout << "Usage: " << argv[0] << " "
<< args << std::endl;
+
+ for (unsigned i = 0; args_desc[i][0] != 0; ++i)
+ std::cout << " " << args_desc[i][0] << ": "
<< args_desc[i][1]
+ << std::endl;
+
+ std::cout << std::endl << "Output: " << out_desc
<< std::endl;
+ std::cout << "-----------" << std::endl;
+ std::cout << "EPITA/LRDE - Scribo 2009" << std::endl;
+ return 1;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::debug
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_DEBUG_USAGE_HH
diff --git a/scribo/demo/Makefile.am b/scribo/demo/Makefile.am
index a5f584b..ab8c1a2 100644
--- a/scribo/demo/Makefile.am
+++ b/scribo/demo/Makefile.am
@@ -2,8 +2,8 @@
include $(top_srcdir)/scribo/scribo.mk
+Makefile.demo:
+ qmake-qt4 $(top_srcdir)/scribo/src/demo/demo.pro -o Makefile.demo
-Makefile:
- qmake-qt4 $(top_srcdir)/scribo/src/demo/demo.pro -o Makefile
-
-all-local: Makefile
+demo: Makefile.demo
+ make -f Makefile.demo all
diff --git a/scribo/extract/primitive/lines_discontinued.hh
b/scribo/extract/lines_discontinued.hh
similarity index 70%
copy from scribo/extract/primitive/lines_discontinued.hh
copy to scribo/extract/lines_discontinued.hh
index 3a1b6ea..b790320 100644
--- a/scribo/extract/primitive/lines_discontinued.hh
+++ b/scribo/extract/lines_discontinued.hh
@@ -34,15 +34,20 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/window.hh>
# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/site_set/box.hh>
# include <mln/labeling/blobs.hh>
+# include <mln/labeling/compute.hh>
# include <mln/morpho/rank_filter.hh>
# include <mln/morpho/dilation.hh>
+# include <mln/accu/bbox.hh>
+
+# include <mln/util/array.hh>
+# include <mln/util/couple.hh>
+
# include <scribo/core/macros.hh>
-# include <scribo/core/object_image.hh>
-# include <scribo/extract/primitive/objects.hh>
namespace scribo
{
@@ -62,15 +67,25 @@ namespace scribo
*
* \param[in] input_ A binary image.
* \param[in] nbh_ The neighborhood used for labeling image
- * the lines.
+ * components.
* \param[in,out] nlines The label type used for labeling.
* \param[in] win_ A Window used to extract lines.
* \param[in] rank_k Rank used for filtering.
+ * \param[in,out] line_bboxes line bounding boxes.
*
* \return An image in which lines are labeled.
*/
template <typename I, typename N, typename V, typename W>
- object_image(mln_ch_value(I,V))
+ mln_ch_value(I,V)
+ lines_discontinued(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_, unsigned rank_k,
+ util::array<box<mln_site(I)> >& line_bboxes);
+
+
+ /// \overload
+ template <typename I, typename N, typename V, typename W>
+ mln_ch_value(I,V)
lines_discontinued(const Image<I>& input_,
const Neighborhood<N>& nbh_, V& nlines,
const Window<W>& win_, unsigned rank_k);
@@ -108,7 +123,7 @@ namespace scribo
template <typename I, typename N, typename V, typename W>
inline
- object_image(mln_ch_value(I,V))
+ mln_ch_value(I,V)
lines_discontinued(const Image<I>& input_,
const Neighborhood<N>& nbh_, V& nlines,
const Window<W>& win_, unsigned rank_k)
@@ -121,10 +136,8 @@ namespace scribo
const N& nbh = exact(nbh_);
const W& win = exact(win_);
- mln_ch_value(I,bool) filter
- = morpho::dilation(morpho::rank_filter(input, win, rank_k), W(win.length() / 2));
- object_image(mln_ch_value(I,V)) output
- = extract::primitive::objects(filter, nbh, nlines);
+ mln_ch_value(I,bool) filter = morpho::rank_filter(input, win, rank_k);
+ mln_ch_value(I,V) output = labeling::blobs(filter, nbh, nlines);
//FIXME: we would like to enlarge the component in the right direction,
// in order to avoid rank filter side effects (smaller components).
@@ -134,6 +147,41 @@ namespace scribo
}
+
+
+ template <typename I, typename N, typename V, typename W>
+ inline
+ mln_ch_value(I,V)
+ lines_discontinued(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_, unsigned rank_k,
+ util::array<box<mln_site(I)> >& line_bboxes)
+ {
+ trace::entering("scribo::primitive::lines_discontinued");
+
+ internal::lines_discontinued_tests(input_, nbh_, nlines, win_, rank_k);
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ const W& win = exact(win_);
+
+ mln_ch_value(I,V)
+ output = lines_discontinued(input, nbh, nlines, win, rank_k);
+
+ line_bboxes = labeling::compute(accu::meta::bbox(), output, nlines);
+ mln_postcondition(line_bboxes.nelements() == nlines.next());
+
+ //FIXME: is it correct?
+ for_all_components(i, line_bboxes)
+ {
+ line_bboxes[i].enlarge(W::dir, win.delta_() - rank_k);
+ line_bboxes[i].crop_wrt(input.domain());
+ }
+
+ trace::exiting("scribo::primitive::lines_discontinued");
+ return output;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/extract/primitive/canvas.hh b/scribo/extract/primitive/canvas.hh
index fd271a7..0c78662 100644
--- a/scribo/extract/primitive/canvas.hh
+++ b/scribo/extract/primitive/canvas.hh
@@ -35,6 +35,7 @@
# include <mln/util/array.hh>
# include <mln/util/couple.hh>
# include <mln/value/label_8.hh>
+# include <mln/util/couple.hh>
# include <scribo/table/align_lines_verticaly.hh>
# include <scribo/table/align_lines_horizontaly.hh>
@@ -84,7 +85,7 @@ namespace scribo
canvas(const Image<I>& input_,
const util::array<box<mln_site(I)> >& hlines,
const util::array<box<mln_site(I)> >& vlines,
- unsigned max_dist_lines);
+ unsigned max_dist_lines)
{
trace::entering("scribo::primitive::canvas");
const I& input = exact(input_);
@@ -93,7 +94,7 @@ namespace scribo
mln_precondition(input.is_valid());
typedef util::array<box<mln_site(I)> > lines_t;
- util::couple<lines_t, lines_t> lines = make::couple(hlines, vlines);
+ util::couple<lines_t, lines_t> lines = mln::make::couple(hlines, vlines);
util::array<int> rows = align_lines_horizontaly(input, hlines, 5);
util::array<int> cols = align_lines_verticaly(input, vlines, 5);
diff --git a/scribo/extract/primitive/cells.hh b/scribo/extract/primitive/cells.hh
index f5b6d71..764d228 100644
--- a/scribo/extract/primitive/cells.hh
+++ b/scribo/extract/primitive/cells.hh
@@ -31,6 +31,8 @@
/// Extract canvas cells from a binary image.
# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/site_set/box.hh>
# include <mln/accu/bbox.hh>
@@ -42,7 +44,7 @@
# include <scribo/table/rebuild.hh>
# include <scribo/table/erase.hh>
-# include <scribo/primitive/discontinued_lines.hh>
+# include <scribo/extract/primitive/lines_discontinued.hh>
# include <scribo/make/debug_filename.hh>
@@ -56,16 +58,19 @@ namespace scribo
namespace primitive
{
+ using namespace mln;
+
/// Extract canvas cells from a binary image.
/// Use arbitrary criterions.
- /*
- ** \param[in] input_ A binary image.
- ** \param[in,out] ncells Will store the number of cells found.
- **
- ** \return A list of cell bounding boxes.
- */
- template <typename I, typename V>
- util::couple<util::array<box<mln_site(I)> >
+ ///
+ /// \param[in] input_ A binary image.
+ /// \param[in,out] ncells Will store the number of cells found.
+ ///
+ /// \return A list of cell bounding boxes.
+ //
+ template <typename I, typename N, typename V>
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >
cells(const Image<I>& input_,
const Neighborhood<N>& nbh_, const V& label_type);
@@ -74,7 +79,8 @@ namespace scribo
template <typename I, typename N, typename V>
inline
- util::couple<util::array<box<mln_site(I)> >
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >
cells(const Image<I>& input_,
const Neighborhood<N>& nbh_, const V& label_type)
{
@@ -86,21 +92,23 @@ namespace scribo
mln_precondition(nbh.is_valid());
mlc_equal(mln_value(I), bool)::check();
- typedef util::array< box<mln_site(I)> > boxarray_t;
+ typedef mln::util::array< box<mln_site(I)> > boxarray_t;
V ncells;
win::line<mln_grid(I::site), 0, mln_coord(I::site)> vline(51);
win::line<mln_grid(I::site), 1, mln_coord(I::site)> hline(51);
boxarray_t
- vlines = primitive::discontinued_lines(input, nbh, ncells, vline, 6),
- hlines = primitive::discontinued_lines(input, nbh, ncells, hline, 6);
+ vlines = extract::primitive::lines_discontinued(input, nbh,
+ ncells, vline, 6),
+ hlines = extract::primitive::lines_discontinued(input, nbh,
+ ncells, hline, 6);
typedef mln_ch_value(I,V) cells_ima_t;
cells_ima_t
- cells = scribo::table::rebuild(input, make::couple(vlines,hlines),
+ cells = scribo::table::rebuild(input, mln::make::couple(vlines,hlines),
30, ncells).first();
- util::array<box<mln_site(I)> >
+ mln::util::array<box<mln_site(I)> >
cellbboxes = labeling::compute(accu::meta::bbox(), cells, ncells);
trace::exiting("scribo::primitive::cells");
diff --git a/scribo/extract/primitive/lines_discontinued.hh
b/scribo/extract/primitive/lines_discontinued.hh
index 3a1b6ea..50792fa 100644
--- a/scribo/extract/primitive/lines_discontinued.hh
+++ b/scribo/extract/primitive/lines_discontinued.hh
@@ -121,8 +121,14 @@ namespace scribo
const N& nbh = exact(nbh_);
const W& win = exact(win_);
+ int dil;
+ if (!(rank_k % 2))
+ dil = win.length() / 2 + rank_k;
+ else
+ dil = win.length() / 2 + rank_k + 1;
+
mln_ch_value(I,bool) filter
- = morpho::dilation(morpho::rank_filter(input, win, rank_k), W(win.length() / 2));
+ = morpho::dilation(morpho::rank_filter(input, win, rank_k), W(dil));
object_image(mln_ch_value(I,V)) output
= extract::primitive::objects(filter, nbh, nlines);
diff --git a/scribo/filter/all.hh b/scribo/filter/all.hh
index b7a08b1..ba8ac7f 100644
--- a/scribo/filter/all.hh
+++ b/scribo/filter/all.hh
@@ -41,9 +41,9 @@ namespace scribo
} // end of namespace scribo
-# include <scribo/filter/thin_bboxes.hh>
-# include <scribo/filter/small_components.hh>
-# include <scribo/filter/large_components.hh>
-# include <scribo/filter/thick_bboxes.hh>
+# include <scribo/filter/large_objects.hh>
+# include <scribo/filter/small_objects.hh>
+# include <scribo/filter/thick_objects.hh>
+# include <scribo/filter/thin_objects.hh>
#endif // ! SCRIBO_FILTER_ALL_HH
diff --git a/scribo/filter/small_objects.hh b/scribo/filter/small_objects.hh
index b23b2de..9fcd153 100644
--- a/scribo/filter/small_objects.hh
+++ b/scribo/filter/small_objects.hh
@@ -170,15 +170,16 @@ namespace scribo
mln_precondition(nbh.is_valid());
V nlabels;
- typedef object_image(mln_ch_value(I,V)) lbl_t;
- lbl_t lbl = extract::primitive::objects(input, nbh, nlabels);
+ typedef mln_ch_value(I,V) lbl_t;
+ object_image(lbl_t) lbl = extract::primitive::objects(input, nbh, nlabels);
- typedef internal::small_objects_filter<lbl_t> func_t;
+ typedef internal::small_objects_filter<mln_ch_value(I,V)> func_t;
func_t fv2b(lbl, min_size);
- labeling::relabel_inplace(lbl, nlabels, fv2b);
+ lbl.relabel(fv2b);
mln_concrete(I) output = duplicate(input);
- data::fill((output | pw::value(lbl) == literal::zero).rw(), false);
+ data::fill((output | pw::value(lbl) == pw::cst(literal::zero)).rw(),
+ false);
trace::exiting("scribo::filter::small_objects");
return output;
diff --git a/scribo/filter/thin_objects.hh b/scribo/filter/thin_objects.hh
index af800d1..1a40c49 100644
--- a/scribo/filter/thin_objects.hh
+++ b/scribo/filter/thin_objects.hh
@@ -151,7 +151,8 @@ namespace scribo
objects.relabel(fv2b);
mln_concrete(I) output = duplicate(input);
- data::fill((output | pw::value(objects) == literal::zero).rw(), false);
+ data::fill((output | pw::value(objects) == pw::cst(literal::zero)).rw(),
+ false);
trace::exiting("scribo::filter::thin_objects");
return output;
diff --git a/scribo/make/influence_zone_graph.hh b/scribo/make/influence_zone_graph.hh
index b4a68c8..3df9f71 100644
--- a/scribo/make/influence_zone_graph.hh
+++ b/scribo/make/influence_zone_graph.hh
@@ -41,6 +41,9 @@
# include <mln/util/graph.hh>
+# include <mln/make/influence_zone_adjacency_graph.hh>
+
+# include <mln/pw/all.hh>
namespace scribo
{
@@ -64,7 +67,7 @@ namespace scribo
/// \param[in] iz_dmax Max distance of the influence zone.
///
/// \return a region adjacency graph.
- template <typename I, typename V>
+ template <typename I, typename N, typename V>
util::graph
influence_zone_graph(const Image<I>& input_,
const Neighborhood<N>& nbh_,
@@ -74,7 +77,7 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
- template <typename I, typename V>
+ template <typename I, typename N, typename V>
util::graph
influence_zone_graph(const Image<I>& input_,
const Neighborhood<N>& nbh_,
@@ -87,7 +90,7 @@ namespace scribo
I& input = exact(input_);
const N& nbh = exact(nbh_);
- mlc_is_equal(mln_value(I), bool)::check();
+ mlc_equal(mln_value(I), bool)::check();
mln_assertion(input.is_valid());
mln_assertion(nbh.is_valid());
@@ -97,7 +100,9 @@ namespace scribo
lbl_t iz = transform::influence_zone_geodesic(lbl, nbh, iz_dmax);
- util::graph g = make::graph(iz | (pw::value(iz) != pw::cst(literal::zero)),
+ util::graph g
+ = mln::make::influence_zone_adjacency_graph(
+ iz | (pw::value(iz) != pw::cst(literal::zero)),
nbh, nlabels);
trace::exiting("scribo::make::influence_zone_graph");
diff --git a/scribo/src/Makefile.am b/scribo/src/Makefile.am
index 0e66301..5944f2d 100644
--- a/scribo/src/Makefile.am
+++ b/scribo/src/Makefile.am
@@ -26,44 +26,44 @@ SUBDIRS = \
bin_PROGRAMS = \
dmap \
+ extract_text_double_link \
+ extract_text_double_several_links \
+ extract_text_graph \
+ extract_text_several_graph \
+ extract_text_several_left_links \
+ extract_text_single_link \
morpho \
negate \
+ preprocess \
superpose \
- text_in_photo
-
-# FIXME: These files used to be in bin_PROGRAMS, but as they did not
-# compile, we moved them here.
-EXTRA_DIST = \
- extract_text_double_link \
- extract_text_double_several_links \
- extract_text_graph \
- extract_text_several_graph \
- extract_text_several_left_links \
- extract_text_single_link \
- table_rebuild_opening \
- table_rebuild_rank \
+ table_rebuild_opening \
+ table_rebuild_rank \
+ text_in_photo \
thin_bboxes
+
# FIXME: Should be enclosed in an Automake conditional like HAVE_TESSERACT.
-EXTRA_DIST += recognition
+EXTRA_DIST = recognition
-# FIXME: Deactivate source accordingly.
-dmap_SOURCES = dmap.cc
-#extract_text_double_link_SOURCES = extract_text_double_link.cc
-#extract_text_double_several_links_SOURCES = extract_text_double_several_links.cc
-#extract_text_graph_SOURCES = extract_text_graph.cc
-#extract_text_several_graph_SOURCES = extract_text_several_graph.cc
-#extract_text_several_left_links_SOURCES = extract_text_several_left_links.cc
-#extract_text_single_link_SOURCES = extract_text_single_link.cc
-morpho_SOURCES = morpho.cc
-negate_SOURCES = negate.cc
#recognition_SOURCES = recognition.cc
# FIXME: Do not use $(HOME).
#recognition_CXXFLAGS =
# -I$(HOME)/local/include $(HOME)/local/lib/libtesseract_full.a
#recognition_LDFLAGS = -lpthread
+
+# FIXME: Deactivate source accordingly.
+dmap_SOURCES = dmap.cc
+extract_text_double_link_SOURCES = extract_text_double_link.cc
+extract_text_double_several_links_SOURCES = extract_text_double_several_links.cc
+extract_text_graph_SOURCES = extract_text_graph.cc
+extract_text_several_graph_SOURCES = extract_text_several_graph.cc
+extract_text_several_left_links_SOURCES = extract_text_several_left_links.cc
+extract_text_single_link_SOURCES = extract_text_single_link.cc
+morpho_SOURCES = morpho.cc
+negate_SOURCES = negate.cc
+preprocess_SOURCES = preprocess.cc
superpose_SOURCES = superpose.cc
-#table_rebuild_opening_SOURCES = table_rebuild_opening.cc
-#table_rebuild_rank_SOURCES = table_rebuild_rank.cc
+table_rebuild_opening_SOURCES = table_rebuild_opening.cc
+table_rebuild_rank_SOURCES = table_rebuild_rank.cc
text_in_photo_SOURCES = text_in_photo.cc
-#thin_bboxes_SOURCES = thin_bboxes.cc
+thin_bboxes_SOURCES = thin_bboxes.cc
diff --git a/scribo/src/binarization/simple.cc b/scribo/src/binarization/simple.cc
index 25a1e42..4d02220 100644
--- a/scribo/src/binarization/simple.cc
+++ b/scribo/src/binarization/simple.cc
@@ -42,8 +42,10 @@ int main(int argc, char *argv[])
using value::int_u8;
if (argc != 3)
- return usage(argv, "Simple binarization of a gray-level image.",
"input.pbm output.pbm",
- args_desc, "A binary image.");
+ return scribo::debug::usage(argv,
+ "Simple binarization of a gray-level image.",
+ "input.pbm output.pbm",
+ args_desc, "A binary image.");
trace::entering("main");
diff --git a/scribo/src/extract/primitive/Makefile.am
b/scribo/src/extract/primitive/Makefile.am
index f530ff5..bab3f62 100644
--- a/scribo/src/extract/primitive/Makefile.am
+++ b/scribo/src/extract/primitive/Makefile.am
@@ -21,14 +21,18 @@ include $(top_srcdir)/scribo/scribo.mk
bin_PROGRAMS = \
+ extract_discontinued_lines \
extract_discontinued_vlines \
extract_discontinued_hlines \
extract_thick_vlines \
- extract_thick_hlines
+ extract_thick_hlines \
+ find_discontinued_lines
+extract_discontinued_lines_SOURCES = extract_discontinued_lines.cc
extract_discontinued_vlines_SOURCES = extract_discontinued_vlines.cc
extract_discontinued_hlines_SOURCES = extract_discontinued_hlines.cc
extract_thick_vlines_SOURCES = extract_thick_vlines.cc
extract_thick_hlines_SOURCES = extract_thick_hlines.cc
+find_discontinued_lines_SOURCES = find_discontinued_lines.cc
diff --git a/scribo/src/extract/primitive/extract_discontinued_hlines.cc
b/scribo/src/extract/primitive/extract_discontinued_hlines.cc
index b880e16..df682a3 100644
--- a/scribo/src/extract/primitive/extract_discontinued_hlines.cc
+++ b/scribo/src/extract/primitive/extract_discontinued_hlines.cc
@@ -27,7 +27,7 @@
#include <mln/value/label_16.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/io/pbm/all.hh>
-#include <mln/level/convert.hh>
+#include <mln/data/convert.hh>
#include <scribo/extract/primitive/lines_h_discontinued.hh>
#include <scribo/debug/usage.hh>
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
value::label_16 nlines;
image2d<bool> lines
- = level::convert(bool(),
+ = data::convert(bool(),
scribo::extract::primitive::lines_h_discontinued(input,
c8(),
nlines,
diff --git a/scribo/src/extract/primitive/extract_discontinued_vlines.cc
b/scribo/src/extract/primitive/extract_discontinued_lines.cc
similarity index 73%
copy from scribo/src/extract/primitive/extract_discontinued_vlines.cc
copy to scribo/src/extract/primitive/extract_discontinued_lines.cc
index 38a83cd..a8388ca 100644
--- a/scribo/src/extract/primitive/extract_discontinued_vlines.cc
+++ b/scribo/src/extract/primitive/extract_discontinued_lines.cc
@@ -27,8 +27,9 @@
#include <mln/value/label_16.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/io/pbm/all.hh>
-#include <mln/level/convert.hh>
+#include <mln/data/convert.hh>
+#include <scribo/extract/primitive/lines_h_discontinued.hh>
#include <scribo/extract/primitive/lines_v_discontinued.hh>
#include <scribo/debug/usage.hh>
@@ -46,23 +47,34 @@ int main(int argc, char *argv[])
using namespace mln;
if (argc != 5)
- return usage(argv, "Extract discontinued vertical lines", "input.pbm
length rank output.pbm",
- args_desc, "A binary image of vertical lines.");
+ return usage(argv, "Extract discontinued horizontal and vertical lines",
+ "input.pbm length rank output.pbm",
+ args_desc, "A binary image of horizontal and vertical lines.");
trace::entering("main");
image2d<bool> input;
io::pbm::load(input, argv[1]);
- value::label_16 nlines;
- image2d<bool> lines
- = level::convert(bool(),
+ value::label_16 nhlines;
+ image2d<bool> hlines
+ = data::convert(bool(),
+ scribo::extract::primitive::lines_h_discontinued(input,
+ c8(),
+ nhlines,
+ atoi(argv[2]),
+ atoi(argv[3])));
+ value::label_16 nvlines;
+ image2d<bool> vlines
+ = data::convert(bool(),
scribo::extract::primitive::lines_v_discontinued(input,
c8(),
- nlines,
+ nvlines,
atoi(argv[2]),
atoi(argv[3])));
- io::pbm::save(lines, argv[4]);
+
+ data::fill((hlines | pw::value(vlines)).rw(), true);
+ io::pbm::save(hlines, argv[4]);
trace::exiting("main");
}
diff --git a/scribo/src/extract/primitive/extract_discontinued_vlines.cc
b/scribo/src/extract/primitive/extract_discontinued_vlines.cc
index 38a83cd..f39086b 100644
--- a/scribo/src/extract/primitive/extract_discontinued_vlines.cc
+++ b/scribo/src/extract/primitive/extract_discontinued_vlines.cc
@@ -27,7 +27,7 @@
#include <mln/value/label_16.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/io/pbm/all.hh>
-#include <mln/level/convert.hh>
+#include <mln/data/convert.hh>
#include <scribo/extract/primitive/lines_v_discontinued.hh>
#include <scribo/debug/usage.hh>
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
value::label_16 nlines;
image2d<bool> lines
- = level::convert(bool(),
+ = data::convert(bool(),
scribo::extract::primitive::lines_v_discontinued(input,
c8(),
nlines,
diff --git a/scribo/src/extract/primitive/extract_thick_hlines.cc
b/scribo/src/extract/primitive/extract_thick_hlines.cc
index 5cc008a..ca6284d 100644
--- a/scribo/src/extract/primitive/extract_thick_hlines.cc
+++ b/scribo/src/extract/primitive/extract_thick_hlines.cc
@@ -27,7 +27,7 @@
#include <mln/value/label_16.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/io/pbm/all.hh>
-#include <mln/level/convert.hh>
+#include <mln/data/convert.hh>
#include <scribo/extract/primitive/lines_h_thick.hh>
#include <scribo/debug/usage.hh>
@@ -55,7 +55,7 @@ int main(int argc, char *argv[])
value::label_16 nlines;
image2d<bool> lines
- = level::convert(bool(),
+ = data::convert(bool(),
scribo::extract::primitive::lines_h_thick(input,
c8(),
nlines,
diff --git a/scribo/src/extract/primitive/extract_thick_vlines.cc
b/scribo/src/extract/primitive/extract_thick_vlines.cc
index 0d58955..52ab1d4 100644
--- a/scribo/src/extract/primitive/extract_thick_vlines.cc
+++ b/scribo/src/extract/primitive/extract_thick_vlines.cc
@@ -27,7 +27,7 @@
#include <mln/value/label_16.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/io/pbm/all.hh>
-#include <mln/level/convert.hh>
+#include <mln/data/convert.hh>
#include <scribo/extract/primitive/lines_v_thick.hh>
#include <scribo/debug/usage.hh>
@@ -55,7 +55,7 @@ int main(int argc, char *argv[])
value::label_16 nlines;
image2d<bool> lines
- = level::convert(bool(),
+ = data::convert(bool(),
scribo::extract::primitive::lines_v_thick(input,
c8(),
nlines,
diff --git a/scribo/src/extract/primitive/extract_discontinued_vlines.cc
b/scribo/src/extract/primitive/find_discontinued_lines.cc
similarity index 69%
copy from scribo/src/extract/primitive/extract_discontinued_vlines.cc
copy to scribo/src/extract/primitive/find_discontinued_lines.cc
index 38a83cd..09f295b 100644
--- a/scribo/src/extract/primitive/extract_discontinued_vlines.cc
+++ b/scribo/src/extract/primitive/find_discontinued_lines.cc
@@ -25,10 +25,14 @@
#include <mln/core/image/image2d.hh>
#include <mln/value/label_16.hh>
+#include <mln/value/rgb8.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/io/pbm/all.hh>
-#include <mln/level/convert.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/data/convert.hh>
+#include <mln/debug/superpose.hh>
+#include <scribo/extract/primitive/lines_h_discontinued.hh>
#include <scribo/extract/primitive/lines_v_discontinued.hh>
#include <scribo/debug/usage.hh>
@@ -46,23 +50,35 @@ int main(int argc, char *argv[])
using namespace mln;
if (argc != 5)
- return usage(argv, "Extract discontinued vertical lines", "input.pbm
length rank output.pbm",
- args_desc, "A binary image of vertical lines.");
+ return usage(argv, "Extract discontinued horizontal and vertical lines",
+ "input.pbm length rank output.pbm",
+ args_desc, "A binary image of horizontal and vertical lines.");
trace::entering("main");
image2d<bool> input;
io::pbm::load(input, argv[1]);
- value::label_16 nlines;
- image2d<bool> lines
- = level::convert(bool(),
+ value::label_16 nhlines;
+ image2d<bool> hlines
+ = data::convert(bool(),
+ scribo::extract::primitive::lines_h_discontinued(input,
+ c8(),
+ nhlines,
+ atoi(argv[2]),
+ atoi(argv[3])));
+ value::label_16 nvlines;
+ image2d<bool> vlines
+ = data::convert(bool(),
scribo::extract::primitive::lines_v_discontinued(input,
c8(),
- nlines,
+ nvlines,
atoi(argv[2]),
atoi(argv[3])));
- io::pbm::save(lines, argv[4]);
+
+ data::fill((hlines | pw::value(vlines)).rw(), true);
+ image2d<value::rgb8> out = debug::superpose(input, hlines);
+ io::ppm::save(out, argv[4]);
trace::exiting("main");
}
diff --git a/scribo/src/extract_text_double_link.cc
b/scribo/src/extract_text_double_link.cc
index 8e6b498..50706d8 100644
--- a/scribo/src/extract_text_double_link.cc
+++ b/scribo/src/extract_text_double_link.cc
@@ -33,14 +33,16 @@
#include <mln/io/pbm/load.hh>
#include <mln/core/alias/neighb2d.hh>
-#include <scribo/text/extract_bboxes.hh>
+#include <scribo/core/object_image.hh>
+
+#include <scribo/extract/primitive/objects.hh>
#include <scribo/text/grouping/group_with_single_left_link.hh>
#include <scribo/text/grouping/group_with_single_right_link.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
#include <scribo/text/grouping/group_from_double_link.hh>
-#include <scribo/filter/small_components.hh>
+#include <scribo/filter/small_objects.hh>
-#include <scribo/debug/save_textbboxes_image.hh>
+#include <scribo/debug/save_bboxes_image.hh>
#include <scribo/make/debug_filename.hh>
int usage(const char *name)
@@ -64,10 +66,10 @@ int main(int argc, char* argv[])
io::pbm::load(input, argv[1]);
value::label_16 nbboxes;
- scribo::util::text<image2d<value::label_16> > text
- = text::extract_bboxes(input, c8(), nbboxes);
+ typedef object_image(image2d<value::label_16>) text_t;
+ text_t text = extract::primitive::objects(input, c8(), nbboxes);
- text = filter::small_components(text,4);
+ text = filter::small_objects(text, 4);
mln::util::array<unsigned> left_link
= text::grouping::group_with_single_left_link(text, 30);
@@ -85,30 +87,30 @@ int main(int argc, char* argv[])
// literal::red, literal::cyan,
// scribo::make::debug_filename("right_linked.ppm"));
- scribo::debug::save_linked_textbboxes_image(input,
- text, left_link, right_link,
- literal::red, literal::cyan, literal::yellow,
- literal::green,
- scribo::make::debug_filename("links.ppm"));
+ scribo::debug::save_linked_bboxes_image(input,
+ text, left_link, right_link,
+ literal::red, literal::cyan, literal::yellow,
+ literal::green,
+ scribo::make::debug_filename("links.ppm"));
// io::ppm::save(mln::labeling::colorize(value::rgb8(),
// text.label_image(),
-// text.nbboxes()),
+// text.nlabels()),
// scribo::make::debug_filename("lbl_before.ppm"));
// With validation.
- scribo::util::text<image2d<value::label_16> > grouped_text
+ text_t grouped_text
= text::grouping::group_from_double_link(text, left_link, right_link);
io::ppm::save(mln::labeling::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
+ grouped_text,
+ grouped_text.nlabels()),
scribo::make::debug_filename("label_color.ppm"));
std::cout << "AFTER double grouping - nbboxes = " <<
grouped_text.bboxes().nelements() << std::endl;
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("bboxes.ppm"));
+ scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("bboxes.ppm"));
}
diff --git a/scribo/src/extract_text_double_several_links.cc
b/scribo/src/extract_text_double_several_links.cc
index 149b86f..7dc1bac 100644
--- a/scribo/src/extract_text_double_several_links.cc
+++ b/scribo/src/extract_text_double_several_links.cc
@@ -29,14 +29,14 @@
#include <mln/labeling/colorize.hh>
#include <mln/util/timer.hh>
-#include <scribo/text/extract_bboxes.hh>
+#include <scribo/extract/primitive/objects.hh>
#include <scribo/text/grouping/group_with_several_left_links.hh>
#include <scribo/text/grouping/group_with_several_right_links.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
#include <scribo/text/grouping/group_from_double_link.hh>
-#include <scribo/filter/small_components.hh>
+#include <scribo/filter/small_objects.hh>
-#include <scribo/debug/save_textbboxes_image.hh>
+#include <scribo/debug/save_bboxes_image.hh>
#include <scribo/make/debug_filename.hh>
int usage(const char *name)
@@ -68,15 +68,15 @@ int main(int argc, char* argv[])
std::cout << "extract bboxes" << std::endl;
t.restart();
t2.start();
- scribo::util::text<image2d<value::label_16> > text
- = text::extract_bboxes(input, c8(), nbboxes);
+ typedef object_image(image2d<value::label_16>) text_t;
+ text_t text = scribo::extract::primitive::objects(input, c8(), nbboxes);
std::cout << t << std::endl;
mln::util::timer t3;
std::cout << "Remove small components" << std::endl;
t.restart();
t3.start();
- text = filter::small_components(text,4);
+ text = filter::small_objects(text,4);
std::cout << t << std::endl;
std::cout << "Group with left link" << std::endl;
@@ -93,30 +93,30 @@ int main(int argc, char* argv[])
std::cout << "BEFORE - nbboxes = " << nbboxes <<
std::endl;
- scribo::debug::save_linked_textbboxes_image(input,
- text, left_link, right_link,
- literal::red, literal::cyan, literal::yellow,
- literal::green,
- scribo::make::debug_filename("links.ppm"));
+ scribo::debug::save_linked_bboxes_image(input,
+ text, left_link, right_link,
+ literal::red, literal::cyan, literal::yellow,
+ literal::green,
+ scribo::make::debug_filename("links.ppm"));
// With validation.
std::cout << "Group from double link" << std::endl;
t.restart();
- scribo::util::text<image2d<value::label_16> > grouped_text
+ text_t grouped_text
= text::grouping::group_from_double_link(text, left_link, right_link);
std::cout << t << std::endl;
std::cout << "Full process: " << t2 << std::endl;
std::cout << "Cleanup and grouping process: " << t3 <<
std::endl;
io::ppm::save(mln::labeling::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
+ grouped_text,
+ grouped_text.nlabels()),
scribo::make::debug_filename("label_color.ppm"));
std::cout << "AFTER double grouping - nbboxes = " <<
grouped_text.bboxes().nelements() << std::endl;
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("bboxes.ppm"));
+ scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("bboxes.ppm"));
}
diff --git a/scribo/src/extract_text_graph.cc b/scribo/src/extract_text_graph.cc
index 682fa03..91bd799 100644
--- a/scribo/src/extract_text_graph.cc
+++ b/scribo/src/extract_text_graph.cc
@@ -33,12 +33,12 @@
#include <mln/literal/colors.hh>
#include <mln/labeling/colorize.hh>
-#include <scribo/text/extract_bboxes.hh>
+#include <scribo/extract/primitive/objects.hh>
#include <scribo/text/grouping/group_with_graph.hh>
#include <scribo/text/grouping/group_from_graph.hh>
-#include <scribo/debug/save_textbboxes_image.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/debug/save_bboxes_image.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
#include <scribo/make/debug_filename.hh>
int usage(const char *name)
@@ -61,32 +61,32 @@ int main(int argc, char* argv[])
io::pbm::load(input, argv[1]);
value::label_16 nbboxes;
- scribo::util::text<image2d<value::label_16> > text
- = text::extract_bboxes(input, c8(), nbboxes);
+ typedef object_image(image2d<value::label_16>) text_t;
+ text_t text = extract::primitive::objects(input, c8(), nbboxes);
mln::util::graph g = text::grouping::group_with_graph(text, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes.next() <<
std::endl;
- scribo::debug::save_linked_textbboxes_image(input,
- text, g,
- literal::red, literal::cyan,
- scribo::make::debug_filename("left_linked.ppm"));
+ scribo::debug::save_linked_bboxes_image(input,
+ text, g,
+ literal::red, literal::cyan,
+ scribo::make::debug_filename("left_linked.ppm"));
// io::ppm::save(mln::labeling::colorize(value::rgb8(),
// text.label_image(),
-// text.nbboxes()),
+// text.nlabels()),
// scribo::make::debug_filename("lbl_before.ppm"));
- scribo::util::text<image2d<value::label_16> > grouped_text
+ text_t grouped_text
= text::grouping::group_from_graph(text, g);
std::cout << "AFTER - nbboxes = " <<
grouped_text.bboxes().nelements() << std::endl;
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("grouped_text.ppm"));
+ scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("grouped_text.ppm"));
io::ppm::save(mln::labeling::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
+ grouped_text,
+ grouped_text.nlabels()),
scribo::make::debug_filename("label_color.ppm"));
}
diff --git a/scribo/src/extract_text_several_graph.cc
b/scribo/src/extract_text_several_graph.cc
index 0fd9694..198f325 100644
--- a/scribo/src/extract_text_several_graph.cc
+++ b/scribo/src/extract_text_several_graph.cc
@@ -27,12 +27,12 @@
#include <mln/essential/2d.hh>
-#include <scribo/text/extract_bboxes.hh>
+#include <scribo/extract/primitive/objects.hh>
#include <scribo/text/grouping/group_with_several_graphes.hh>
#include <scribo/text/grouping/group_from_graph.hh>
-#include <scribo/debug/save_textbboxes_image.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/debug/save_bboxes_image.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
#include <scribo/make/debug_filename.hh>
int usage(const char *name)
@@ -55,28 +55,27 @@ int main(int argc, char* argv[])
io::pbm::load(input, argv[1]);
value::label_16 nbboxes;
- scribo::util::text<image2d<value::label_16> > text
- = text::extract_bboxes(input, c8(), nbboxes);
+ typedef object_image(image2d<value::label_16>) text_t;
+ text_t text = scribo::extract::primitive::objects(input, c8(), nbboxes);
mln::util::graph g = text::grouping::group_with_several_graphes(text, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes.next() <<
std::endl;
- scribo::debug::save_linked_textbboxes_image(input,
- text, g,
- literal::red, literal::cyan,
- scribo::make::debug_filename("left_linked.ppm"));
+ scribo::debug::save_linked_bboxes_image(input,
+ text, g,
+ literal::red, literal::cyan,
+ scribo::make::debug_filename("left_linked.ppm"));
- scribo::util::text<image2d<value::label_16> > grouped_text
- = text::grouping::group_from_graph(text, g);
+ text_t grouped_text = text::grouping::group_from_graph(text, g);
std::cout << "AFTER - nbboxes = " <<
grouped_text.bboxes().nelements() << std::endl;
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("grouped_text.ppm"));
+ scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("grouped_text.ppm"));
io::ppm::save(mln::labeling::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
+ grouped_text,
+ grouped_text.nlabels()),
scribo::make::debug_filename("label_color.ppm"));
}
diff --git a/scribo/src/extract_text_several_left_links.cc
b/scribo/src/extract_text_several_left_links.cc
index d67df60..f717a63 100644
--- a/scribo/src/extract_text_several_left_links.cc
+++ b/scribo/src/extract_text_several_left_links.cc
@@ -27,12 +27,12 @@
#include <mln/essential/2d.hh>
-#include <scribo/text/extract_bboxes.hh>
+#include <scribo/extract/primitive/objects.hh>
#include <scribo/text/grouping/group_with_several_left_links.hh>
#include <scribo/text/grouping/group_from_single_link.hh>
-#include <scribo/debug/save_textbboxes_image.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/debug/save_bboxes_image.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
#include <scribo/make/debug_filename.hh>
int usage(const char *name)
@@ -55,8 +55,8 @@ int main(int argc, char* argv[])
io::pbm::load(input, argv[1]);
value::label_16 nbboxes;
- scribo::util::text<image2d<value::label_16> > text
- = text::extract_bboxes(input, c8(), nbboxes);
+ typedef object_image(image2d<value::label_16>) text_t;
+ text_t text = scribo::extract::primitive::objects(input, c8(), nbboxes);
{
std::cout << "* Left grouping" << std::endl;
@@ -64,22 +64,22 @@ int main(int argc, char* argv[])
= text::grouping::group_with_several_left_links(text, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes <<
std::endl;
- scribo::debug::save_linked_textbboxes_image(input,
- text, left_link,
- literal::red, literal::cyan,
- scribo::make::debug_filename("left_links.ppm"));
+ scribo::debug::save_linked_bboxes_image(input,
+ text, left_link,
+ literal::red, literal::cyan,
+ scribo::make::debug_filename("left_links.ppm"));
- scribo::util::text<image2d<value::label_16> > grouped_text
- = text::grouping::group_from_single_link(text, left_link);
+ text_t grouped_text
+ = text::grouping::group_from_single_link(text, left_link);
std::cout << "AFTER - nbboxes = " <<
grouped_text.bboxes().nelements() << std::endl;
io::ppm::save(mln::labeling::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
+ grouped_text,
+ grouped_text.nlabels()),
scribo::make::debug_filename("left_label_color.ppm"));
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("left_bboxes.ppm"));
+ scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("left_bboxes.ppm"));
}
}
diff --git a/scribo/src/extract_text_single_link.cc
b/scribo/src/extract_text_single_link.cc
index 77b655a..e29b1c4 100644
--- a/scribo/src/extract_text_single_link.cc
+++ b/scribo/src/extract_text_single_link.cc
@@ -37,13 +37,13 @@
#include <mln/io/pbm/load.hh>
-#include <scribo/text/extract_bboxes.hh>
+#include <scribo/extract/primitive/objects.hh>
#include <scribo/text/grouping/group_with_single_left_link.hh>
#include <scribo/text/grouping/group_with_single_right_link.hh>
#include <scribo/text/grouping/group_from_single_link.hh>
-#include <scribo/debug/save_textbboxes_image.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/debug/save_bboxes_image.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
#include <scribo/make/debug_filename.hh>
@@ -68,8 +68,8 @@ int main(int argc, char* argv[])
io::pbm::load(input, argv[1]);
value::label_16 nbboxes;
- scribo::util::text<image2d<value::label_16> > text
- = text::extract_bboxes(input, c8(), nbboxes);
+ typedef object_image(image2d<value::label_16>) text_t;
+ text_t text = scribo::extract::primitive::objects(input, c8(), nbboxes);
{
std::cout << "* Left grouping" << std::endl;
@@ -77,26 +77,26 @@ int main(int argc, char* argv[])
= text::grouping::group_with_single_left_link(text, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes <<
std::endl;
- scribo::debug::save_linked_textbboxes_image(input,
- text, left_link,
- literal::red, literal::cyan,
- scribo::make::debug_filename("left_links.ppm"));
+ scribo::debug::save_linked_bboxes_image(input,
+ text, left_link,
+ literal::red, literal::cyan,
+ scribo::make::debug_filename("left_links.ppm"));
// io::ppm::save(mln::labeling::colorize(value::rgb8(),
-// text.label_image(),
-// text.nbboxes()),
+// text,
+// text.nlabels()),
// scribo::make::debug_filename("lbl_before.ppm"));
- scribo::util::text<image2d<value::label_16> > grouped_text
+ text_t grouped_text
= text::grouping::group_from_single_link(text, left_link);
std::cout << "AFTER - nbboxes = " <<
grouped_text.bboxes().nelements() << std::endl;
io::ppm::save(mln::labeling::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
+ grouped_text,
+ grouped_text.nlabels()),
scribo::make::debug_filename("left_label_color.ppm"));
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("left_bboxes.ppm"));
+ scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("left_bboxes.ppm"));
}
{
@@ -105,27 +105,27 @@ int main(int argc, char* argv[])
= text::grouping::group_with_single_right_link(text, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes <<
std::endl;
- scribo::debug::save_linked_textbboxes_image(input,
- text, right_link,
- literal::red, literal::cyan,
- scribo::make::debug_filename("right_links.ppm"));
+ scribo::debug::save_linked_bboxes_image(input,
+ text, right_link,
+ literal::red, literal::cyan,
+ scribo::make::debug_filename("right_links.ppm"));
// io::ppm::save(mln::labeling::colorize(value::rgb8(),
-// text.label_image(),
-// text.nbboxes()),
+// text,
+// text.nlabels()),
// scribo::make::debug_filename("lbl_before.ppm"));
- scribo::util::text<image2d<value::label_16> > grouped_text
+ text_t grouped_text
= text::grouping::group_from_single_link(text, right_link);
io::ppm::save(mln::labeling::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
+ grouped_text,
+ grouped_text.nlabels()),
scribo::make::debug_filename("right_label_color.ppm"));
std::cout << "AFTER - nbboxes = " <<
grouped_text.bboxes().nelements() << std::endl;
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("right_bboxes.ppm"));
+ scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("right_bboxes.ppm"));
}
diff --git a/scribo/src/morpho.cc b/scribo/src/morpho.cc
index 7121e57..91a089a 100644
--- a/scribo/src/morpho.cc
+++ b/scribo/src/morpho.cc
@@ -26,7 +26,7 @@
#include <mln/essential/2d.hh>
#include <mln/transform/distance_and_influence_zone_geodesic.hh>
#include <mln/core/var.hh>
-#include <mln/fun/v2v/wrap.hh>
+#include <mln/labeling/wrap.hh>
#include <mln/win/hline2d.hh>
#include <mln/morpho/watershed/flooding.hh>
#include <mln/morpho/watershed/superpose.hh>
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
mln_VAR(res, transform::distance_and_influence_zone_geodesic(lbl, c8(),
mln_max(unsigned)));
- io::pgm::save(data::transform(res.first(), fun::v2v::wrap<label_8>()),
"dmap.pgm");
+ io::pgm::save(labeling::wrap(res.first()), "dmap.pgm");
io::ppm::save(labeling::colorize(rgb8(), res.second(), nlabels), "iz.ppm");
image2d<unsigned>& dmap = res.first();
diff --git a/scribo/src/negate.cc b/scribo/src/negate.cc
index c2ff8e6..9c35f1c 100644
--- a/scribo/src/negate.cc
+++ b/scribo/src/negate.cc
@@ -43,8 +43,10 @@ int main(int argc, char *argv[])
using namespace mln;
if (argc != 3)
- return usage(argv, "Negate a binary image", "input.pbm
output.pbm",
- args_desc, "A binary image.");
+ return scribo::debug::usage(argv,
+ "Negate a binary image",
+ "input.pbm output.pbm",
+ args_desc, "A binary image.");
image2d<bool> input;
io::pbm::load(input, argv[1]);
diff --git a/scribo/src/binarization/simple.cc b/scribo/src/preprocess.cc
similarity index 64%
copy from scribo/src/binarization/simple.cc
copy to scribo/src/preprocess.cc
index 25a1e42..bc1a1c7 100644
--- a/scribo/src/binarization/simple.cc
+++ b/scribo/src/preprocess.cc
@@ -23,37 +23,56 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
+#include <mln/core/image/image2d.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/label_16.hh>
+
#include <mln/io/pgm/load.hh>
#include <mln/io/pbm/save.hh>
+#include <mln/logical/not.hh>
+
#include <scribo/binarization/simple.hh>
+#include <scribo/preprocessing/unskew.hh>
+#include <scribo/filter/small_objects.hh>
+#include <scribo/filter/thin_objects.hh>
+
#include <scribo/debug/usage.hh>
const char *args_desc[][2] =
{
- { "input.pgm", "A gray level image." },
+ { "input.pgm", "A gray-level image." },
{0, 0}
};
-
int main(int argc, char *argv[])
{
using namespace mln;
- using value::int_u8;
if (argc != 3)
- return usage(argv, "Simple binarization of a gray-level image.",
"input.pbm output.pbm",
- args_desc, "A binary image.");
+ return scribo::debug::usage(argv,
+ "Generic image preprocessing",
+ "input.pgm output.pbm",
+ args_desc, "A binary image.");
trace::entering("main");
- image2d<int_u8> input;
+ typedef image2d<value::int_u8> I;
+ I input;
io::pgm::load(input, argv[1]);
+ image2d<bool> input_bw = scribo::binarization::simple(input);
+
+ logical::not_inplace(input_bw);
+ input_bw = scribo::preprocessing::unskew(input_bw);
- io::pbm::save(scribo::binarization::simple(input),
- argv[2]);
+ input_bw = scribo::filter::small_objects(input_bw, c8(), value::label_16(), 3);
+ input_bw = scribo::filter::thin_objects(input_bw, c8(), value::label_16(), 1);
+ logical::not_inplace(input_bw);
+ io::pbm::save(input_bw, argv[2]);
trace::exiting("main");
+
}
diff --git a/scribo/src/preprocessing/unskew.cc b/scribo/src/preprocessing/unskew.cc
index d46884f..bdd9035 100644
--- a/scribo/src/preprocessing/unskew.cc
+++ b/scribo/src/preprocessing/unskew.cc
@@ -44,8 +44,10 @@ int main(int argc, char *argv[])
using namespace mln;
if (argc != 3)
- return usage(argv, "Unskew a binary image", "input.pbm
output.pbm",
- args_desc, "A binary image.");
+ return scribo::debug::usage(argv,
+ "Unskew a binary image",
+ "input.pbm output.pbm",
+ args_desc, "A binary image.");
image2d<bool> input;
io::pbm::load(input, argv[1]);
diff --git a/scribo/src/recognition.cc b/scribo/src/recognition.cc
index e167d82..87bbade 100644
--- a/scribo/src/recognition.cc
+++ b/scribo/src/recognition.cc
@@ -62,8 +62,11 @@ int main(int argc, char* argv[])
using namespace mln;
if (argc != 2)
- return usage(argv, "Text extraction and recognition",
"input.pbm",
- args_desc, "The text is printed on the standard output.");
+ return scribo::debug::usage(argv,
+ "Text extraction and recognition",
+ "input.pbm",
+ args_desc,
+ "The text is printed on the standard output.");
trace::entering("main");
diff --git a/scribo/src/superpose.cc b/scribo/src/superpose.cc
index d219dfd..8449987 100644
--- a/scribo/src/superpose.cc
+++ b/scribo/src/superpose.cc
@@ -46,8 +46,12 @@ int main(int argc, char *argv[])
using namespace mln;
if (argc != 4)
- return usage(argv, "Superpose two binary images", "input.pbm data.pbm
output.ppm",
- args_desc, "A color image. Data from 'data.pbm' is colored in
red.");
+ return scribo::debug::usage(argv,
+ "Superpose two binary images",
+ "input.pbm data.pbm output.ppm",
+ args_desc,
+ "A color image. Data from 'data.pbm' is \
+colored in red.");
image2d<bool> input;
io::pbm::load(input, argv[1]);
diff --git a/scribo/src/table/erase.cc b/scribo/src/table/erase.cc
index b45d7e9..3cb441e 100644
--- a/scribo/src/table/erase.cc
+++ b/scribo/src/table/erase.cc
@@ -32,7 +32,7 @@
#include <mln/value/label_16.hh>
#include <mln/core/alias/neighb2d.hh>
-#include <scribo/table/extract.hh>
+#include <scribo/table/erase.hh>
#include <scribo/extract/primitive/lines_h_discontinued.hh>
#include <scribo/extract/primitive/lines_v_discontinued.hh>
@@ -55,9 +55,11 @@ int main(int argc, char* argv[])
using mln::value::label_16;
if (argc != 3)
- return usage(argv, "Remove tables from a binary image.",
- "input.pbm output.pbm",
- args_desc, "A binary image without tables.");
+ return scribo::debug::usage(argv,
+ "Remove tables from a binary image.",
+ "input.pbm output.pbm",
+ args_desc,
+ "A binary image without tables.");
trace::entering("main");
@@ -75,8 +77,8 @@ int main(int argc, char* argv[])
nhlines, 51, 6);
image2d<bool> input_notables
- = scribo::table::erase(input,
- mln::make::couple(lbl_v.bboxes(),lbl_h.bboxes()));
+ = scribo::table::erase(input, lbl_h, lbl_v);
+
io::pbm::save(input_notables, argv[2]);
trace::exiting("main");
diff --git a/scribo/src/table/extract.cc b/scribo/src/table/extract.cc
index 2d681f8..060f2f8 100644
--- a/scribo/src/table/extract.cc
+++ b/scribo/src/table/extract.cc
@@ -52,9 +52,11 @@ int main(int argc, char* argv[])
using namespace mln;
if (argc != 4)
- return usage(argv, "Extract tables from a binary image.",
- "input.pbm output.dump output.ppm",
- args_desc, "A color images. 'White' color means \
+ return scribo::debug::usage(argv,
+ "Extract tables from a binary image.",
+ "input.pbm output.dump output.ppm",
+ args_desc,
+ "A color images. 'White' color means \
the background, other colors indicates cells.");
trace::entering("main");
diff --git a/scribo/src/table_rebuild_opening.cc b/scribo/src/table_rebuild_opening.cc
index 2e504e5..8e12467 100644
--- a/scribo/src/table_rebuild_opening.cc
+++ b/scribo/src/table_rebuild_opening.cc
@@ -25,12 +25,18 @@
#include <iostream>
-#include <mln/essential/2d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/dmorph/image_if.hh>
+#include <mln/value/label_8.hh>
+#include <mln/value/label_16.hh>
#include <mln/pw/all.hh>
+#include <mln/io/pbm/all.hh>
+#include <mln/util/couple.hh>
#include <scribo/table/rebuild.hh>
#include <scribo/table/erase.hh>
-#include <scribo/table/extract_lines_with_opening.hh>
+#include <scribo/extract/primitive/lines_h_thick.hh>
+#include <scribo/extract/primitive/lines_v_thick.hh>
#include <scribo/make/debug_filename.hh>
int usage(const char *name)
@@ -54,18 +60,26 @@ int main(int argc, char* argv[])
io::pbm::load(input, argv[1]);
logical::not_inplace(input);
- typedef util::couple<util::array<box2d>,util::array<box2d> >
tblboxes_t;
+ typedef object_image(image2d<value::label_16>) lines_t;
- win::vline2d vline(51);
- win::hline2d hline(51);
value::label_16 nbboxes;
- tblboxes_t lineboxes
- = table::extract_lines_with_opening(input, c8(), nbboxes,
- vline, hline);
+ lines_t hlines
+ = scribo::extract::primitive::lines_h_thick(input,
+ c8(),
+ nbboxes,
+ 51);
+ lines_t vlines
+ = scribo::extract::primitive::lines_v_thick(input,
+ c8(),
+ nbboxes,
+ 51);
value::label_8 ncells;
image2d<value::label_8> tables
- = scribo::table::rebuild(input, lineboxes, 30, ncells).first();
+ = scribo::table::rebuild(input,
+ mln::make::couple(vlines.bboxes(), hlines.bboxes()),
+ 30,
+ ncells).first();
std::cout << "ncells (including background) = " << ncells
<< std::endl;
@@ -73,11 +87,11 @@ int main(int argc, char* argv[])
scribo::make::debug_filename("table_cells.ppm"));
io::pgm::save(tables, scribo::make::debug_filename("table_cells.pgm"));
- image2d<value::rgb8> input_rgb = level::convert(value::rgb8(), input);
+ image2d<value::rgb8> input_rgb = data::convert(value::rgb8(), input);
data::fill((input_rgb | pw::value(tables) == pw::cst(0u)).rw(), literal::red);
io::ppm::save(input_rgb,
scribo::make::debug_filename("table_superposed.ppm"));
- image2d<bool> in_wo_tables = table::erase(input, lineboxes);
+ image2d<bool> in_wo_tables = table::erase(input, hlines, vlines);
io::pbm::save(in_wo_tables,
scribo::make::debug_filename("input_wo_tables.pbm"));
}
diff --git a/scribo/src/table_rebuild_rank.cc b/scribo/src/table_rebuild_rank.cc
index 1c1764b..5e0d339 100644
--- a/scribo/src/table_rebuild_rank.cc
+++ b/scribo/src/table_rebuild_rank.cc
@@ -25,14 +25,20 @@
#include <iostream>
-#include <mln/essential/2d.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/dmorph/image_if.hh>
+#include <mln/value/label_8.hh>
+#include <mln/value/label_16.hh>
#include <mln/pw/all.hh>
+#include <mln/io/pbm/all.hh>
+#include <mln/util/couple.hh>
#include <mln/data/compute.hh>
#include <mln/accu/maj_h.hh>
#include <scribo/table/rebuild.hh>
#include <scribo/table/erase.hh>
-#include <scribo/table/extract_lines_with_rank.hh>
+#include <scribo/extract/primitive/lines_h_discontinued.hh>
+#include <scribo/extract/primitive/lines_v_discontinued.hh>
#include <scribo/make/debug_filename.hh>
int usage(const char *name)
@@ -56,18 +62,28 @@ int main(int argc, char* argv[])
io::pbm::load(input, argv[1]);
logical::not_inplace(input);
- typedef util::couple<util::array<box2d>,util::array<box2d> >
tblboxes_t;
+ typedef object_image(image2d<value::label_16>) lines_t;
- win::vline2d vline(51);
- win::hline2d hline(51);
value::label_16 nbboxes;
- tblboxes_t lineboxes
- = table::extract_lines_with_rank(input, c8(), nbboxes,
- vline, hline, 6, 6);
+ lines_t hlines
+ = scribo::extract::primitive::lines_h_discontinued(input,
+ c8(),
+ nbboxes,
+ 51,
+ 6);
+ lines_t vlines
+ = scribo::extract::primitive::lines_v_discontinued(input,
+ c8(),
+ nbboxes,
+ 51,
+ 6);
value::label_8 ncells;
image2d<value::label_8> tables
- = scribo::table::rebuild(input, lineboxes, 5, ncells).first();
+ = scribo::table::rebuild(input,
+ mln::make::couple(vlines.bboxes(), hlines.bboxes()),
+ 30,
+ ncells).first();
std::cout << "ncells (including background) = " << ncells
<< std::endl;
@@ -88,7 +104,7 @@ int main(int argc, char* argv[])
data::fill((input_rgb | pw::value(tables) == pw::cst(0u)).rw(), literal::red);
io::ppm::save(input_rgb,
scribo::make::debug_filename("table_superposed.ppm"));
- image2d<bool> in_wo_tables = table::erase(input, lineboxes);
+ image2d<bool> in_wo_tables = table::erase(input, hlines, vlines);
io::pbm::save(in_wo_tables,
scribo::make::debug_filename("input_wo_tables.pbm"));
diff --git a/scribo/src/text_in_photo.cc b/scribo/src/text_in_photo.cc
index 1e6b338..d13d741 100644
--- a/scribo/src/text_in_photo.cc
+++ b/scribo/src/text_in_photo.cc
@@ -33,6 +33,8 @@
#include <mln/io/pbm/all.hh>
#include <mln/io/ppm/save.hh>
+#include <mln/math/min.hh>
+
#include <scribo/extract/primitive/objects.hh>
#include <scribo/text/grouping/group_with_single_left_link.hh>
#include <scribo/text/grouping/group_with_single_right_link.hh>
@@ -42,8 +44,8 @@
#include <scribo/filter/thick_objects.hh>
#include <scribo/make/debug_filename.hh>
-#include <scribo/debug/save_textbboxes_image.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/debug/save_bboxes_image.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
#include <scribo/debug/usage.hh>
@@ -63,8 +65,12 @@ int main(int argc, char* argv[])
scribo::make::internal::debug_filename_prefix = "photo";
if (argc != 3)
- return usage(argv, "Find text in a binarized photo.", "input.pbm
output.ppm",
- args_desc, "A color image where the text is highlighted.");
+ return scribo::debug::usage(argv,
+ "Find text in a binarized photo.",
+ "input.pbm output.ppm",
+ args_desc,
+ "A color image where the text is \
+highlighted.");
trace::entering("main");
@@ -92,13 +98,13 @@ int main(int argc, char* argv[])
= text::grouping::group_with_single_right_link(objects, 30);
std::cout << "BEFORE - nobjects = " << nobjects <<
std::endl;
-// scribo::debug::save_linked_textbboxes_image(input,
+// scribo::debug::save_linked_bboxes_image(input,
// filtered_textbboxes, left_link, right_link,
// literal::red, literal::cyan, literal::yellow,
// literal::green,
// scribo::make::debug_filename("links.ppm"));
//
-// scribo::debug::save_textbboxes_image(input, filtered_textbboxes.bboxes(),
+// scribo::debug::save_bboxes_image(input, filtered_textbboxes.bboxes(),
// literal::red,
// scribo::make::debug_filename("test_graph_filtered_text.ppm"));
object_image(L) grouped_objects
@@ -107,7 +113,7 @@ int main(int argc, char* argv[])
std::cout << "AFTER - nobjects = " << grouped_objects.nlabels()
<< std::endl;
-// scribo::debug::save_textbboxes_image(input, grouped_textbboxes.bboxes(),
+// scribo::debug::save_bboxes_image(input, grouped_textbboxes.bboxes(),
// literal::red,
// scribo::make::debug_filename("test_graph_grouped_text.ppm"));
//
diff --git a/scribo/src/thin_bboxes.cc b/scribo/src/thin_bboxes.cc
index 3f826ff..49e28bd 100644
--- a/scribo/src/thin_bboxes.cc
+++ b/scribo/src/thin_bboxes.cc
@@ -40,18 +40,18 @@ int main(int argc, char *argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix = "thin_bboxes";
+ scribo::make::internal::debug_filename_prefix = "thin_objects";
image2d<bool> input;
io::pbm::load(input, argv[1]);
value::label_16 nlines;
- typedef scribo::util::text<image2d<value::label_16> > text_t;
+ typedef object_image(image2d<value::label_16>) text_t;
text_t lines = scribo::text::extract_lines(input, c8(), nlines);
text_t filtered_lines = scribo::filter::thin_objects(lines, 5);
- scribo::debug::save_textbboxes_image(input, filtered_lines.bboxes(),
- literal::red,
- scribo::make::debug_filename("thickness_filter"));
+ scribo::debug::save_bboxes_image(input, filtered_lines.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("thickness_filter"));
}
diff --git a/scribo/table/align_lines_horizontaly.hh
b/scribo/table/align_lines_horizontaly.hh
index 373bc88..b205b97 100644
--- a/scribo/table/align_lines_horizontaly.hh
+++ b/scribo/table/align_lines_horizontaly.hh
@@ -62,9 +62,9 @@ namespace scribo
/// \return A list of the resulting aligned rows. Each integer is actually
/// a row number.
template <typename I>
- util::array<int>
+ mln::util::array<int>
align_lines_horizontaly(const Image<I>& input,
- util::array<box<mln_site(I)> >& line_bboxes,
+ mln::util::array<box<mln_site(I)> >& line_bboxes,
unsigned max_alignment_diff);
@@ -72,19 +72,19 @@ namespace scribo
template <typename I>
- util::array<int>
+ mln::util::array<int>
align_lines_horizontaly(const Image<I>& input,
- util::array<box<mln_site(I)> >& line_bboxes,
+ mln::util::array<box<mln_site(I)> >& line_bboxes,
unsigned max_alignment_diff)
{
trace::entering("scribo::table::align_lines_horizontaly");
mln_precondition(exact(input).is_valid());
- util::array<int> res = internal::align_lines(geom::nrows(input),
- geom::min_row(input),
- geom::max_row(input),
- line_bboxes, 0,
- max_alignment_diff);
+ mln::util::array<int> res = internal::align_lines(geom::nrows(input),
+ geom::min_row(input),
+ geom::max_row(input),
+ line_bboxes, 0,
+ max_alignment_diff);
trace::exiting("scribo::table::align_lines_horizontaly");
return res;
diff --git a/scribo/table/align_lines_verticaly.hh
b/scribo/table/align_lines_verticaly.hh
index 147f2ef..f7138bc 100644
--- a/scribo/table/align_lines_verticaly.hh
+++ b/scribo/table/align_lines_verticaly.hh
@@ -63,9 +63,9 @@ namespace scribo
/// \return A list of the resulting aligned cols. Each integer is actually
/// a col number.
template <typename I>
- util::array<int>
+ mln::util::array<int>
align_lines_verticaly(const Image<I>& input,
- util::array<box<mln_site(I)> >& line_bboxes,
+ mln::util::array<box<mln_site(I)> >& line_bboxes,
unsigned max_alignment_diff);
@@ -73,15 +73,15 @@ namespace scribo
template <typename I>
- util::array<int>
+ mln::util::array<int>
align_lines_verticaly(const Image<I>& input,
- util::array<box<mln_site(I)> >& line_bboxes,
+ mln::util::array<box<mln_site(I)> >& line_bboxes,
unsigned max_alignment_diff)
{
trace::entering("scribo::table::align_lines_verticaly");
mln_precondition(exact(input).is_valid());
- util::array<int> res = internal::align_lines(geom::ncols(input),
+ mln::util::array<int> res = internal::align_lines(geom::ncols(input),
geom::min_col(input),
geom::max_col(input),
line_bboxes, 1,
diff --git a/scribo/table/all.hh b/scribo/table/all.hh
index ecd2926..186af77 100644
--- a/scribo/table/all.hh
+++ b/scribo/table/all.hh
@@ -42,16 +42,15 @@ namespace scribo
} // end of namespace scribo
# include <scribo/table/internal/all.hh>
-# include <scribo/table/repair_vertical_lines.hh>
-# include <scribo/table/rebuild.hh>
-# include <scribo/table/connect_horizontal_lines.hh>
-# include <scribo/table/erase.hh>
+
# include <scribo/table/align_lines_horizontaly.hh>
-# include <scribo/table/extract_lines_with_opening.hh>
# include <scribo/table/align_lines_verticaly.hh>
-# include <scribo/table/extract_lines_with_rank.hh>
-# include <scribo/table/extract.hh>
+# include <scribo/table/connect_horizontal_lines.hh>
# include <scribo/table/connect_vertical_lines.hh>
+# include <scribo/table/erase.hh>
+# include <scribo/table/extract.hh>
+# include <scribo/table/rebuild.hh>
# include <scribo/table/repair_horizontal_lines.hh>
+# include <scribo/table/repair_vertical_lines.hh>
#endif // ! SCRIBO_TABLE_ALL_HH
diff --git a/scribo/table/connect_horizontal_lines.hh
b/scribo/table/connect_horizontal_lines.hh
index a9ea3f4..45cc826 100644
--- a/scribo/table/connect_horizontal_lines.hh
+++ b/scribo/table/connect_horizontal_lines.hh
@@ -38,13 +38,16 @@
# include <scribo/table/internal/connect_lines.hh>
-
+#include <mln/value/int_u16.hh>
+#include <mln/draw/line.hh>
+#include <mln/io/pgm/all.hh>
namespace scribo
{
namespace table
{
+ using namespace mln;
/// Connect horizontal lines with the new aligned columns.
///
@@ -57,9 +60,9 @@ namespace scribo
/// and horizontal lines.
template <typename I>
void
- connect_horizontal_lines(const util::array<int>& aligned_cols,
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tablebboxes,
+ connect_horizontal_lines(const mln::util::array<int>& aligned_cols,
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >& tablebboxes,
const Image<I>& input,
unsigned max_distance);
@@ -69,9 +72,9 @@ namespace scribo
template <typename I>
void
- connect_horizontal_lines(const util::array<int>& aligned_cols,
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tablebboxes,
+ connect_horizontal_lines(const mln::util::array<int>& aligned_cols,
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >& tablebboxes,
const Image<I>& input,
unsigned max_distance)
{
diff --git a/scribo/table/connect_vertical_lines.hh
b/scribo/table/connect_vertical_lines.hh
index 5a68217..4b1423c 100644
--- a/scribo/table/connect_vertical_lines.hh
+++ b/scribo/table/connect_vertical_lines.hh
@@ -57,9 +57,9 @@ namespace scribo
/// and horizontal lines.
template <typename I>
void
- connect_vertical_lines(const util::array<int>& aligned_rows,
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tablebboxes,
+ connect_vertical_lines(const mln::util::array<int>& aligned_rows,
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >& tablebboxes,
const Image<I>& input,
unsigned max_distance);
@@ -70,9 +70,9 @@ namespace scribo
/// Connect vertical lines with the new aligned rows.
template <typename I>
void
- connect_vertical_lines(const util::array<int>& aligned_rows,
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tablebboxes,
+ connect_vertical_lines(const mln::util::array<int>& aligned_rows,
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >& tablebboxes,
const Image<I>& input,
unsigned max_distance)
{
diff --git a/scribo/table/erase.hh b/scribo/table/erase.hh
index a231e1c..91c4228 100644
--- a/scribo/table/erase.hh
+++ b/scribo/table/erase.hh
@@ -28,7 +28,8 @@
/// \file scribo/table/erase.hh
///
-/// Erase the table lines in an image.
+/// \brief Erase the table lines in an image.
+
# include <mln/core/concept/image.hh>
# include <mln/core/site_set/box.hh>
@@ -39,7 +40,7 @@
# include <mln/util/array.hh>
# include <mln/util/couple.hh>
-# include <scribo/core/erase_bboxes.hh>
+# include <scribo/core/erase_objects.hh>
namespace scribo
{
@@ -49,30 +50,31 @@ namespace scribo
using namespace mln;
- /// Erase table line bboxes from an image.
- ///
- /// \param[in] tablebboxes vertical and horizontal line bounding
- /// boxes.
- /// \param[in] input A binary image from which the table line
- /// bboxes are extracted.
+ /// Erase vertical and horizontal lines from an image.
///
+ /// \param[in] input A binary image from which the table lines
+ /// are extracted.
+ /// \param[in] hlines An object image with horizontal lines.
+ /// \param[in] vlines An object image with vertical lines.
///
/// \return A copy of \p in where the table lines are removed.
- template <typename I>
+ //
+ template <typename I, typename L>
mln_concrete(I)
erase(const Image<I>& input,
- const util::couple<util::array< box<mln_site(I)> >,
- util::array< box<mln_site(I)> > >& tablebboxes);
+ const object_image(L)& hlines,
+ const object_image(L)& vlines);
# ifndef MLN_INCLUDE_ONLY
- template <typename I>
+ template <typename I, typename L>
+ inline
mln_concrete(I)
erase(const Image<I>& input,
- const util::couple<util::array< box<mln_site(I)> >,
- util::array< box<mln_site(I)> > >& tablebboxes)
+ const object_image(L)& hlines,
+ const object_image(L)& vlines)
{
trace::entering("scribo::internal::erase");
mlc_equal(mln_value(I),bool)::check();
@@ -80,8 +82,8 @@ namespace scribo
I output = duplicate(input);
- erase_bboxes(output, tablebboxes.first());
- erase_bboxes(output, tablebboxes.second());
+ erase_objects(output, vlines);
+ erase_objects(output, hlines);
trace::exiting("scribo::internal::erase");
return output;
diff --git a/scribo/table/extract.hh b/scribo/table/extract.hh
index 6154c0d..f117603 100644
--- a/scribo/table/extract.hh
+++ b/scribo/table/extract.hh
@@ -40,8 +40,6 @@
# include <scribo/extract/primitive/lines_h_discontinued.hh>
# include <scribo/extract/primitive/lines_v_discontinued.hh>
-# include <scribo/make/debug_filename.hh>
-
namespace scribo
{
@@ -61,8 +59,8 @@ namespace scribo
*/
template <typename I, typename V>
mln::util::couple<mln_ch_value(I,V),
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > > >
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > > >
extract(const Image<I>& input_, V& ncells);
@@ -71,8 +69,8 @@ namespace scribo
template <typename I, typename V>
inline
mln::util::couple<mln_ch_value(I,V),
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > > >
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > > >
extract(const Image<I>& input_, V& ncells)
{
trace::entering("scribo::table::extract");
@@ -83,12 +81,14 @@ namespace scribo
V nhlines, nvlines;
object_image(mln_ch_value(I,V))
- hlines = extract::primitive::lines_h_discontinued(input, c8(), nhlines, 51, 6),
- vlines = extract::primitive::lines_v_discontinued(input, c8(), nvlines, 51, 6);
+ hlines = extract::primitive::lines_h_discontinued(input, c8(),
+ nhlines, 51, 6),
+ vlines = extract::primitive::lines_v_discontinued(input, c8(),
+ nvlines, 51, 6);
typedef mln::util::couple<mln_ch_value(I,V),
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > > >
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > > >
tables_t;
tables_t tables
= scribo::table::rebuild(input,
diff --git a/scribo/table/internal/align_lines.hh b/scribo/table/internal/align_lines.hh
index 10c7e2a..8ab2e8b 100644
--- a/scribo/table/internal/align_lines.hh
+++ b/scribo/table/internal/align_lines.hh
@@ -92,11 +92,11 @@ namespace scribo
**
*/
template <typename P>
- util::array<int>
+ mln::util::array<int>
align_lines(unsigned nsites,
int min_coord,
int max_coord,
- util::array<box<P> >& line_bboxes,
+ mln::util::array<box<P> >& line_bboxes,
unsigned dim,
unsigned max_alignment_diff);
@@ -106,11 +106,11 @@ namespace scribo
template <typename P>
- util::array<int>
+ mln::util::array<int>
align_lines(unsigned nsites,
int min_coord,
int max_coord,
- util::array<box<P> >& line_bboxes,
+ mln::util::array<box<P> >& line_bboxes,
unsigned dim,
unsigned max_alignment_diff)
{
@@ -118,7 +118,7 @@ namespace scribo
mln_precondition(nsites > 0);
- util::array< util::set<unsigned> > lines;
+ mln::util::array< mln::util::set<unsigned> > lines;
lines.resize(nsites);
// Map components with actual lines.
@@ -135,7 +135,7 @@ namespace scribo
}
// Init box2line
- util::array<int> box2line;
+ mln::util::array<int> box2line;
box2line.resize(line_bboxes.nelements());
for_all_elements(i, box2line)
box2line[i] = -1;
@@ -150,7 +150,7 @@ namespace scribo
// FIXME: not optimal... Make it faster!
// We may do too much iterations (while loop) and some of them may
// be done for nothing...
- util::array<int> newlines;
+ mln::util::array<int> newlines;
while (max_nelts > 0)
{
for_all_elements(i, lines)
diff --git a/scribo/table/internal/connect_lines.hh
b/scribo/table/internal/connect_lines.hh
index baf0e73..5c01c0f 100644
--- a/scribo/table/internal/connect_lines.hh
+++ b/scribo/table/internal/connect_lines.hh
@@ -35,12 +35,16 @@
# include <mln/data/fill.hh>
+# include <mln/transform/influence_zone_geodesic.hh>
+
# include <mln/morpho/elementary/dilation.hh>
# include <mln/util/array.hh>
# include <mln/util/couple.hh>
# include <mln/opt/at.hh>
+# include <mln/transform/influence_zone_geodesic.hh>
+
# include <scribo/core/macros.hh>
# include <scribo/core/central_sites.hh>
@@ -66,8 +70,8 @@ namespace scribo
/// FIXME: doc arguments.
template <typename P>
void
- connect_lines(const util::array<int>& aligned_lines,
- util::array< box<P> >& boxes,
+ connect_lines(const mln::util::array<int>& aligned_lines,
+ mln::util::array< box<P> >& boxes,
unsigned dim,
unsigned dim_size,
unsigned max_distance);
@@ -78,8 +82,8 @@ namespace scribo
template <typename P>
void
- connect_lines(const util::array<int>& aligned_lines,
- util::array< box<P> >& boxes,
+ connect_lines(const mln::util::array<int>& aligned_lines,
+ mln::util::array< box<P> >& boxes,
unsigned dim,
unsigned dim_size,
unsigned max_distance)
@@ -90,18 +94,19 @@ namespace scribo
data::fill(l, -1);
for_all_elements(i, aligned_lines)
- opt::at(l, aligned_lines[i]) = i;
+ opt::at(l, aligned_lines[i]) = aligned_lines[i];
- for (unsigned i = 0; i < max_distance; ++i)
- l = morpho::elementary::dilation(l, c2());
+ l = transform::influence_zone_geodesic(l, c2(), max_distance, -1);
for_all_components(i, boxes)
{
- util::couple<P,P> cp = central_sites(boxes[i], dim);
- if (opt::at(l, cp.first()[dim]) != -1)
- boxes[i].pmin()[dim] = aligned_lines[opt::at(l, cp.first()[dim])];
- if (opt::at(l, cp.second()[dim]) != -1)
- boxes[i].pmax()[dim] = aligned_lines[opt::at(l, cp.second()[dim])];
+ mln::util::couple<P,P> cp = central_sites(boxes[i], dim);
+ if (opt::at(l, cp.first()[dim]) != -1
+ && opt::at(l, cp.first()[dim]) < boxes[i].pmin()[dim])
+ boxes[i].pmin()[dim] = opt::at(l, cp.first()[dim]);
+ if (opt::at(l, cp.second()[dim]) != -1
+ && opt::at(l, cp.second()[dim]) > boxes[i].pmax()[dim])
+ boxes[i].pmax()[dim] = opt::at(l, cp.second()[dim]);
}
trace::exiting("scribo::table::internal::connect_lines");
diff --git a/scribo/table/internal/repair_lines.hh
b/scribo/table/internal/repair_lines.hh
index 26fdc17..fa7138a 100644
--- a/scribo/table/internal/repair_lines.hh
+++ b/scribo/table/internal/repair_lines.hh
@@ -79,7 +79,7 @@ namespace scribo
template <unsigned axis, typename I>
void
repair_lines(const Image<I>& input_,
- util::array<box<mln_site(I)> >& tableboxes,
+ mln::util::array<box<mln_site(I)> >& tableboxes,
unsigned max_discontinuity);
@@ -89,7 +89,7 @@ namespace scribo
template <unsigned axis, typename I>
void
repair_lines(const Image<I>& input_,
- util::array<box<mln_site(I)> >& tableboxes,
+ mln::util::array<box<mln_site(I)> >& tableboxes,
unsigned max_discontinuity)
{
trace::entering("scribo::table::internal::repair_lines");
@@ -105,7 +105,7 @@ namespace scribo
data::fill(l, literal::zero);
for_all_components(i, tableboxes)
{
- util::couple<P,P> cp = central_sites(tableboxes[i], axis);
+ mln::util::couple<P,P> cp = central_sites(tableboxes[i], axis);
l(cp.first()) = i;
l(cp.second()) = i;
}
@@ -113,7 +113,7 @@ namespace scribo
// Repair
extension_val<mln_ch_value(I,value::label_16)> l_ext(l, literal::zero);
- util::array<box<P> > result;
+ mln::util::array<box<P> > result;
std::vector<bool> to_keep(tableboxes.nelements(), true);
mln_VAR(tbb_ima, extend(l | (pw::value(l) != pw::cst(literal::zero)), l));
@@ -123,18 +123,18 @@ namespace scribo
mln_qiter(line_t) q(vl, p);
for_all(p)
{
- util::couple<P,P> cp_p = central_sites(tableboxes[l_ext(p)], axis);
+ mln::util::couple<P,P> cp_p = central_sites(tableboxes[l_ext(p)], axis);
for_all(q)
if (l_ext(q) != literal::zero && l_ext(q) != l_ext(p))
{
- if (util::ord_strict(tableboxes[l_ext(p)].pmax(),
+ if (mln::util::ord_strict(tableboxes[l_ext(p)].pmax(),
tableboxes[l_ext(q)].pmax()))
{
tableboxes[l_ext(p)].pmax() = tableboxes[l_ext(q)].pmax();
to_keep[l_ext(q)] = false;
}
- if (util::ord_strict(tableboxes[l_ext(q)].pmin(),
+ if (mln::util::ord_strict(tableboxes[l_ext(q)].pmin(),
tableboxes[l_ext(p)].pmin()))
{
tableboxes[l_ext(p)].pmin() = tableboxes[l_ext(q)].pmin();
@@ -143,7 +143,7 @@ namespace scribo
if (!to_keep[l_ext(q)])
{
- util::couple<P,P> cp_q = central_sites(tableboxes[l_ext(q)], axis);
+ mln::util::couple<P,P> cp_q = central_sites(tableboxes[l_ext(q)], axis);
l_ext(cp_q.first()) = literal::zero;
l_ext(cp_q.second()) = literal::zero;
@@ -151,7 +151,7 @@ namespace scribo
l_ext(cp_p.first()) = literal::zero;
l_ext(cp_p.second()) = literal::zero;
- util::couple<P,P> new_cp_p = central_sites(tableboxes[p_i], axis);
+ mln::util::couple<P,P> new_cp_p = central_sites(tableboxes[p_i], axis);
l_ext(new_cp_p.first()) = p_i;
l_ext(new_cp_p.second()) = p_i;
}
diff --git a/scribo/table/rebuild.hh b/scribo/table/rebuild.hh
index 6c6ba8b..6bfefbf 100644
--- a/scribo/table/rebuild.hh
+++ b/scribo/table/rebuild.hh
@@ -73,11 +73,11 @@ namespace scribo
*/
template <typename I, typename V>
mln::util::couple<mln_ch_value(I,V),
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > > >
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > > >
rebuild(const Image<I>& input_,
- const util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& linebboxes_,
+ const mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >& linebboxes_,
unsigned max_dist_lines,
V& ncells);
@@ -87,11 +87,11 @@ namespace scribo
template <typename I, typename V>
mln::util::couple<mln_ch_value(I,V),
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > > >
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > > >
rebuild(const Image<I>& input_,
- const util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& linebboxes_,
+ const mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >& linebboxes_,
unsigned max_dist_lines,
V& ncells)
{
@@ -101,14 +101,14 @@ namespace scribo
mlc_equal(mln_value(I), bool)::check();
mln_precondition(input.is_valid());
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > > linebboxes = linebboxes_;
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > > linebboxes = linebboxes_;
scribo::debug::save_table_image(input, linebboxes,
literal::red, "table-raw.ppm");
- util::array<int> rows = align_lines_horizontaly(input, linebboxes.second(),
5);
- util::array<int> cols = align_lines_verticaly(input, linebboxes.first(), 5);
+ mln::util::array<int> rows = align_lines_horizontaly(input,
linebboxes.second(), 5);
+ mln::util::array<int> cols = align_lines_verticaly(input, linebboxes.first(),
5);
# ifndef SCRIBO_NDEBUG
scribo::debug::save_table_image(input, linebboxes,
diff --git a/scribo/table/repair_horizontal_lines.hh
b/scribo/table/repair_horizontal_lines.hh
index caa8492..6fc3ba1 100644
--- a/scribo/table/repair_horizontal_lines.hh
+++ b/scribo/table/repair_horizontal_lines.hh
@@ -58,8 +58,8 @@ namespace scribo
template <typename I>
void
repair_horizontal_lines(const Image<I>& input,
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tablebboxes,
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >& tablebboxes,
unsigned max_discontinuity);
# ifndef MLN_INCLUDE_ONLY
@@ -68,8 +68,8 @@ namespace scribo
inline
void
repair_horizontal_lines(const Image<I>& input,
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tablebboxes,
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >& tablebboxes,
unsigned max_discontinuity)
{
trace::entering("scribo::table::repair_horizontal_lines");
diff --git a/scribo/table/repair_vertical_lines.hh
b/scribo/table/repair_vertical_lines.hh
index 6edde2e..38ba7f6 100644
--- a/scribo/table/repair_vertical_lines.hh
+++ b/scribo/table/repair_vertical_lines.hh
@@ -64,8 +64,8 @@ namespace scribo
template <typename I>
void
repair_vertical_lines(const Image<I>& input,
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tablebboxes,
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >& tablebboxes,
unsigned max_discontinuity);
# ifndef MLN_INCLUDE_ONLY
@@ -74,8 +74,8 @@ namespace scribo
inline
void
repair_vertical_lines(const Image<I>& input,
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >& tablebboxes,
+ mln::util::couple<mln::util::array<box<mln_site(I)> >,
+ mln::util::array<box<mln_site(I)> > >& tablebboxes,
unsigned max_discontinuity)
{
trace::entering("scribo::table::repair_vertical_lines");
diff --git a/scribo/tests/filter/small_and_large_bboxes.cc
b/scribo/tests/filter/small_and_large_bboxes.cc
index a4dd76a..38aa85e 100644
--- a/scribo/tests/filter/small_and_large_bboxes.cc
+++ b/scribo/tests/filter/small_and_large_bboxes.cc
@@ -32,15 +32,17 @@
#include <mln/io/pbm/load.hh>
#include <mln/literal/colors.hh>
-#include <scribo/text/extract_bboxes.hh>
+#include <scribo/core/object_image.hh>
+
+#include <scribo/extract/primitive/objects.hh>
#include <scribo/text/grouping/group_with_graph.hh>
#include <scribo/text/grouping/group_from_graph.hh>
-#include <scribo/filter/small_components.hh>
+#include <scribo/filter/small_objects.hh>
#include <scribo/util/text.hh>
#include <scribo/make/debug_filename.hh>
-#include <scribo/debug/save_textbboxes_image.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/debug/save_bboxes_image.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
#include <scribo/tests/data.hh>
@@ -69,37 +71,37 @@ int main(int argc, char* argv[])
image2d<bool> input;
io::pbm::load(input, img.c_str());
- typedef scribo::util::text<image2d<value::label_16> > text_t;
value::label_16 nbboxes;
- text_t textbboxes = text::extract_bboxes(input, c8(), nbboxes);
+ typedef object_image(image2d<value::label_16>) text_t;
+ text_t text = extract::primitive::objects(input, c8(), nbboxes);
- mln::util::graph g = text::grouping::group_with_graph(textbboxes, 30);
+ mln::util::graph g = text::grouping::group_with_graph(text, 30);
mln_assertion(nbboxes == 12u);
// std::cout << "BEFORE - nbboxes = " << nbboxes <<
std::endl;
-// scribo::debug::save_linked_textbboxes_image(input,
-// textbboxes, g,
+// scribo::debug::save_linked_bboxes_image(input,
+// text, g,
// literal::red, literal::cyan,
// "test_graph_left_linked.ppm");
- text_t grouped_textbboxes
- = text::grouping::group_from_graph(textbboxes, g);
+ text_t grouped_text
+ = text::grouping::group_from_graph(text, g);
-// std::cout << "AFTER - nbboxes = " <<
grouped_textbboxes.nbboxes().next() << std::endl;
+// std::cout << "AFTER - nbboxes = " <<
grouped_text.nbboxes().next() << std::endl;
//
-// scribo::debug::save_textbboxes_image(input, grouped_textbboxes.bboxes(),
+// scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
// literal::red,
// "test_graph_grouped_text.ppm");
- mln_assertion(grouped_textbboxes.nbboxes() == 6u);
+ mln_assertion(grouped_text.nbboxes() == 6u);
text_t
- filtered_textbboxes = scribo::filter::small_components(grouped_textbboxes, 20);
+ filtered_text = scribo::filter::small_objects(grouped_text, 20);
- mln_assertion(filtered_textbboxes.nbboxes() == 2u);
+ mln_assertion(filtered_text.nbboxes() == 2u);
-// scribo::debug::save_textbboxes_image(input, filtered_textbboxes.bboxes(),
+// scribo::debug::save_bboxes_image(input, filtered_text.bboxes(),
// literal::red,
// "test_graph_filtered_text.ppm");
diff --git a/scribo/tests/preprocessing/unskew.cc b/scribo/tests/preprocessing/unskew.cc
index ff6e715..832ae3d 100644
--- a/scribo/tests/preprocessing/unskew.cc
+++ b/scribo/tests/preprocessing/unskew.cc
@@ -1,5 +1,4 @@
-// Copyright (C) 2009
- EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -30,14 +29,16 @@
#include <scribo/preprocessing/unskew.hh>
+#include <scribo/tests/data.hh>
int main(int argc, char *argv[])
{
(void) argc;
+ (void) argv;
using namespace mln;
image2d<bool> ima;
- io::pbm::load(ima, argv[1]);
+ io::pbm::load(ima, SCRIBO_IMG_DIR "/text_to_group.pbm");
- io::pbm::save(scribo::preprocessing::unskew(ima), "tr.pbm");
+ io::pbm::save(scribo::preprocessing::unskew(ima), "unskew.pbm");
}
diff --git a/scribo/tests/table/extract_lines_with_rank.cc
b/scribo/tests/table/extract_lines_with_rank.cc
index 33bbac0..4ff6d89 100644
--- a/scribo/tests/table/extract_lines_with_rank.cc
+++ b/scribo/tests/table/extract_lines_with_rank.cc
@@ -74,15 +74,13 @@ int main(int argc, char *argv[])
lineboxes_t hboxes_, vboxes_;
- typedef image2d<value::label_8> lbl_t;
+ typedef object_image(image2d<value::label_8>) lbl_t;
lbl_t
hlbl = scribo::extract::primitive::lines_h_discontinued(input, c8(),
- nbboxes, 11, 2,
- hboxes_);
+ nbboxes, 11, 2);
lbl_t
vlbl = scribo::extract::primitive::lines_v_discontinued(input, c8(),
- nbboxes, 11, 2,
- vboxes_);
- mln_assertion(hboxes_ == hboxes);
- mln_assertion(vboxes_ == vboxes);
+ nbboxes, 11, 2);
+ mln_assertion(hlbl.bboxes() == hboxes);
+ mln_assertion(vlbl.bboxes() == vboxes);
}
diff --git a/scribo/tests/table/repair_lines.cc b/scribo/tests/table/repair_lines.cc
index d73d917..addbb10 100644
--- a/scribo/tests/table/repair_lines.cc
+++ b/scribo/tests/table/repair_lines.cc
@@ -35,7 +35,6 @@
#include <scribo/table/repair_vertical_lines.hh>
#include <scribo/table/repair_horizontal_lines.hh>
-#include <scribo/table/extract_lines_with_rank.hh>
#include <scribo/debug/save_table_image.hh>
#include <scribo/tests/data.hh>
@@ -64,12 +63,6 @@ int main(int argc, char *argv[])
lineboxes.second().append(make::box2d(27,0, 31, 26));
lineboxes.second().append(make::box2d(27,34, 31,59));
-
-// tblboxes_t lineboxes = scribo::table::extract_lines_with_rank(input, c8(),
value::label_16(), win::vline2d(11), win::hline2d(11), 2, 2);
-//
-// std::cout << lineboxes.first() << std::endl;
-// std::cout << lineboxes.second() << std::endl;
-
scribo::table::repair_vertical_lines(input, lineboxes, 31);
scribo::table::repair_horizontal_lines(input, lineboxes, 31);
diff --git a/scribo/tests/unit_test/build_unit_test.sh
b/scribo/tests/unit_test/build_unit_test.sh
index 87863e3..e722204 100755
--- a/scribo/tests/unit_test/build_unit_test.sh
+++ b/scribo/tests/unit_test/build_unit_test.sh
@@ -15,7 +15,13 @@ test $# -eq 1 || { echo "Usage: $0 <scribo path>"
&& exit 1; }
## FIXME: Ouch! Using `find' properly can probably save us some pipes,
## forks and characters here.
-HEADERS=`find $1 -name "*.hh" | grep -vE "*.spe.hh" | sort | sed -e
's/.*\/scribo\/\(.*\)/scribo\/\1/g' | sed 's/\.\.\/\.\.\///g'`
+HEADERS=`find $1 -name "*.hh" \
+ | grep -vE "*.spe.hh" \
+ | grep -v "recognition" \
+ | grep -v "demo" \
+ | sort \
+ | sed -e 's/.*\/scribo\/\(.*\)/scribo\/\1/g' \
+ | sed 's/\.\.\/\.\.\///g'`
output=unit-tests.mk
diff --git a/scribo/tests/unit_test/unit-tests.mk b/scribo/tests/unit_test/unit-tests.mk
index 1f58b67..8024afb 100644
--- a/scribo/tests/unit_test/unit-tests.mk
+++ b/scribo/tests/unit_test/unit-tests.mk
@@ -5,18 +5,19 @@ scribo_all \
scribo_binarization_simple \
scribo_core_all \
scribo_core_central_sites \
-scribo_core_erase_bboxes \
+scribo_core_erase_objects \
scribo_core_macros \
scribo_core_object_image \
scribo_debug_all \
+scribo_debug_save_bboxes_image \
scribo_debug_save_label_image \
-scribo_debug_save_linked_textbboxes_image \
+scribo_debug_save_linked_bboxes_image \
scribo_debug_save_table_image \
-scribo_debug_save_textbboxes_image \
scribo_debug_usage \
scribo_draw_all \
scribo_draw_bounding_box_links \
scribo_draw_bounding_boxes \
+scribo_extract_lines_discontinued \
scribo_extract_primitive_canvas \
scribo_extract_primitive_cells \
scribo_extract_primitive_lines_discontinued \
@@ -73,7 +74,6 @@ scribo_text_grouping_internal_init_link_array \
scribo_text_grouping_internal_is_link_valid \
scribo_text_grouping_internal_update_graph_link \
scribo_text_grouping_internal_update_link_array \
-scribo_text_recognition \
scribo_util_all \
scribo_util_text
@@ -81,18 +81,19 @@ scribo_all_SOURCES = scribo_all.cc
scribo_binarization_simple_SOURCES = scribo_binarization_simple.cc
scribo_core_all_SOURCES = scribo_core_all.cc
scribo_core_central_sites_SOURCES = scribo_core_central_sites.cc
-scribo_core_erase_bboxes_SOURCES = scribo_core_erase_bboxes.cc
+scribo_core_erase_objects_SOURCES = scribo_core_erase_objects.cc
scribo_core_macros_SOURCES = scribo_core_macros.cc
scribo_core_object_image_SOURCES = scribo_core_object_image.cc
scribo_debug_all_SOURCES = scribo_debug_all.cc
+scribo_debug_save_bboxes_image_SOURCES = scribo_debug_save_bboxes_image.cc
scribo_debug_save_label_image_SOURCES = scribo_debug_save_label_image.cc
-scribo_debug_save_linked_textbboxes_image_SOURCES =
scribo_debug_save_linked_textbboxes_image.cc
+scribo_debug_save_linked_bboxes_image_SOURCES = scribo_debug_save_linked_bboxes_image.cc
scribo_debug_save_table_image_SOURCES = scribo_debug_save_table_image.cc
-scribo_debug_save_textbboxes_image_SOURCES = scribo_debug_save_textbboxes_image.cc
scribo_debug_usage_SOURCES = scribo_debug_usage.cc
scribo_draw_all_SOURCES = scribo_draw_all.cc
scribo_draw_bounding_box_links_SOURCES = scribo_draw_bounding_box_links.cc
scribo_draw_bounding_boxes_SOURCES = scribo_draw_bounding_boxes.cc
+scribo_extract_lines_discontinued_SOURCES = scribo_extract_lines_discontinued.cc
scribo_extract_primitive_canvas_SOURCES = scribo_extract_primitive_canvas.cc
scribo_extract_primitive_cells_SOURCES = scribo_extract_primitive_cells.cc
scribo_extract_primitive_lines_discontinued_SOURCES =
scribo_extract_primitive_lines_discontinued.cc
@@ -149,6 +150,5 @@ scribo_text_grouping_internal_init_link_array_SOURCES =
scribo_text_grouping_int
scribo_text_grouping_internal_is_link_valid_SOURCES =
scribo_text_grouping_internal_is_link_valid.cc
scribo_text_grouping_internal_update_graph_link_SOURCES =
scribo_text_grouping_internal_update_graph_link.cc
scribo_text_grouping_internal_update_link_array_SOURCES =
scribo_text_grouping_internal_update_link_array.cc
-scribo_text_recognition_SOURCES = scribo_text_recognition.cc
scribo_util_all_SOURCES = scribo_util_all.cc
scribo_util_text_SOURCES = scribo_util_text.cc
diff --git a/scribo/text/all.hh b/scribo/text/all.hh
index 141e113..d269ebb 100644
--- a/scribo/text/all.hh
+++ b/scribo/text/all.hh
@@ -42,8 +42,8 @@ namespace scribo
} // end of namespace scribo
# include <scribo/text/extract_lines.hh>
-# include <scribo/text/recognition.hh>
-# include <scribo/text/extract_bboxes.hh>
+//# include <scribo/text/recognition.hh>
+# include <scribo/text/clean.hh>
# include <scribo/text/grouping/all.hh>
#endif // ! SCRIBO_TEXT_ALL_HH
diff --git a/scribo/text/clean.hh b/scribo/text/clean.hh
index 559ba2e..5a0b2e1 100644
--- a/scribo/text/clean.hh
+++ b/scribo/text/clean.hh
@@ -34,6 +34,7 @@
# include <mln/core/routine/extend.hh>
# include <mln/morpho/skeleton_constrained.hh>
+# include <mln/morpho/dilation.hh>
# include <mln/topo/skeleton/is_simple_point.hh>
# include <mln/topo/skeleton/crest.hh>
@@ -50,16 +51,30 @@
#include <mln/arith/revert.hh>
+#include <mln/transform/distance_front.hh>
+
#include <mln/linear/gaussian.hh>
#include <mln/value/int_u8.hh>
+
+
namespace scribo
{
namespace text
{
+ using namespace mln;
+
+
+ /// Improve quality of an image with text.
+ ///
+ /// \param[in] input_ A binary image.
+ /// \param[in] dmap_win_ A weighted window.
+ ///
+ /// \return An image. The text have better quality.
+ //
template <typename I, typename W>
mln_concrete(I)
clean(const Image<I>& input_, const Weighted_Window<W>&
dmap_win_);
@@ -68,7 +83,7 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
- static int plop = 0;
+// static int plop = 0;
template <typename I, typename W>
mln_concrete(I)
@@ -117,7 +132,7 @@ namespace scribo
// io::pbm::save(output, mln::debug::filename("dil_skel.pbm"));
}
- ++plop;
+// ++plop;
trace::exiting("scribo::text::clean");
return output;
}
diff --git a/scribo/text/extract_lines.hh b/scribo/text/extract_lines.hh
index f803990..a84d10f 100644
--- a/scribo/text/extract_lines.hh
+++ b/scribo/text/extract_lines.hh
@@ -47,15 +47,17 @@
# include <mln/util/graph.hh>
# include <mln/value/label_16.hh>
+# include <scribo/extract/primitive/objects.hh>
# include <scribo/text/grouping/group_with_several_left_links.hh>
# include <scribo/text/grouping/group_with_several_right_links.hh>
# include <scribo/text/grouping/group_from_double_link.hh>
-# include <scribo/filter/small_objects.hh>
-# include <scribo/util/text.hh>
-# include <scribo/make/debug_filename.hh>
-# include <scribo/debug/save_textbboxes_image.hh>
-# include <scribo/debug/save_linked_textbboxes_image.hh>
+# ifndef SCRIBO_NDEBUG
+# include <mln/literal/colors.hh>
+# include <scribo/make/debug_filename.hh>
+# include <scribo/debug/save_bboxes_image.hh>
+# include <scribo/debug/save_linked_bboxes_image.hh>
+# endif // SCRIBO_NDEBUG
namespace scribo
{
@@ -72,10 +74,10 @@ namespace scribo
** \param[in,out] nbboxes Will hold the number of bounding boxes
** at the end of the routine.
**
- ** \return The text lines.
+ ** \return An object image with grouped potential text objects.
*/
template <typename I, typename N, typename V>
- scribo::util::text<mln_ch_value(I,V)>
+ object_image(mln_ch_value(I,V))
extract_lines(const Image<I>& input_,
const Neighborhood<N>& nbh_,
V& nbboxes);
@@ -85,7 +87,7 @@ namespace scribo
template <typename I, typename N, typename V>
- scribo::util::text<mln_ch_value(I,V)>
+ object_image(mln_ch_value(I,V))
extract_lines(const Image<I>& input_,
const Neighborhood<N>& nbh_,
V& nbboxes)
@@ -98,12 +100,12 @@ namespace scribo
mln_precondition(input.is_valid());
mln_precondition(nbh.is_valid());
- scribo::util::text<mln_ch_value(I,V)> text
- = scribo::make::text(input, nbh, nbboxes);
+ typedef object_image(mln_ch_value(I,V)) text_t;
+ text_t text = scribo::extract::primitive::objects(input, nbh, nbboxes);
# ifndef SCRIBO_NDEBUG
- debug::save_textbboxes_image(input, text.bboxes(), literal::red,
- scribo::make::debug_filename("character-bboxes.ppm"));
+ debug::save_bboxes_image(input, text.bboxes(), literal::red,
+ scribo::make::debug_filename("character-bboxes.ppm"));
# endif // ! SCRIBO_NDEBUG
//Link character bboxes to their left neighboor if possible.
@@ -113,21 +115,21 @@ namespace scribo
= text::grouping::group_with_several_right_links(text, 30);
# ifndef SCRIBO_NDEBUG
- scribo::debug::save_linked_textbboxes_image(input,
- text, left_link, right_link,
- literal::red, literal::cyan,
- literal::yellow, literal::green,
- scribo::make::debug_filename("links.ppm"));
+ scribo::debug::save_linked_bboxes_image(input,
+ text, left_link, right_link,
+ literal::red, literal::cyan,
+ literal::yellow, literal::green,
+ scribo::make::debug_filename("links.ppm"));
# endif // ! SCRIBO_NDEBUG
//Merge character bboxes through a graph.
- scribo::util::text<mln_ch_value(I,V)> grouped_text
+ text_t grouped_text
= text::grouping::group_from_double_link(text, left_link, right_link);
# ifndef SCRIBO_NDEBUG
- debug::save_textbboxes_image(input, grouped_text.bboxes(),
- literal::red,
- scribo::make::debug_filename("multiple_links_grouped_text.ppm"));
+ debug::save_bboxes_image(input, grouped_text.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("multiple_links_grouped_text.ppm"));
# endif // ! SCRIBO_NDEBUG
diff --git a/scribo/text/grouping/group_from_double_link.hh
b/scribo/text/grouping/group_from_double_link.hh
index 4c9fa47..9c0cfa1 100644
--- a/scribo/text/grouping/group_from_double_link.hh
+++ b/scribo/text/grouping/group_from_double_link.hh
@@ -46,8 +46,10 @@
# include <scribo/make/text.hh>
+# include <scribo/core/object_image.hh>
# include <scribo/text/grouping/internal/find_root.hh>
# include <scribo/text/grouping/internal/is_link_valid.hh>
+# include <scribo/text/grouping/internal/init_link_array.hh>
namespace scribo
diff --git a/scribo/text/grouping/group_from_graph.hh
b/scribo/text/grouping/group_from_graph.hh
index aeb8683..d6debd2 100644
--- a/scribo/text/grouping/group_from_graph.hh
+++ b/scribo/text/grouping/group_from_graph.hh
@@ -46,9 +46,8 @@
# include <mln/util/array.hh>
# include <mln/util/graph_ids.hh>
+# include <scribo/core/object_image.hh>
# include <scribo/core/macros.hh>
-# include <scribo/util/text.hh>
-# include <scribo/make/text.hh>
namespace scribo
@@ -60,19 +59,22 @@ namespace scribo
namespace grouping
{
+ using namespace mln;
+
/// Group lines of text according to a graph of links between
/// the lines of text.
- /*!
- ** \param[in] text The lines of text.
- ** \param[in] g_ The graph of links between the lines of text.
- **
- ** \return The grouped and non-grouped lines of text.
- */
- template <typename I, typename G>
- scribo::util::text<I>
- group_from_graph(const scribo::util::text<I>& text,
+ ///
+ /// \param[in] text An object image.
+ /// \param[in] g_ The graph of links between the lines of text.
+ ///
+ /// \return An image with grouped objects.
+ //
+ template <typename L, typename G>
+ object_image(L)
+ group_from_graph(const object_image(L)& text,
const Graph<G>& g_);
+
# ifndef MLN_INCLUDE_ONLY
@@ -138,10 +140,10 @@ namespace scribo
- template <typename I, typename G>
+ template <typename L, typename G>
inline
- scribo::util::text<I>
- group_from_graph(const scribo::util::text<I>& text,
+ object_image(L)
+ group_from_graph(const object_image(L)& text,
const Graph<G>& g_)
{
trace::entering("scribo::text::grouping::group_from_graph");
@@ -150,10 +152,12 @@ namespace scribo
mln_assertion(g.is_valid());
- internal::map_vertex_to_representative_id_functor<mln_value(I)> f;
+ internal::map_vertex_to_representative_id_functor<mln_value(L)> f;
canvas::browsing::depth_first_search(g, f);
- scribo::util::text<I> output = scribo::make::text(text, f.vertextorep);
+ object_image(L) output;
+ output.init_from_(text);
+ output.relabel(f.vertextorep);
trace::exiting("scribo::text::grouping::group_from_graph");
return output;
diff --git a/scribo/text/grouping/group_from_single_link.hh
b/scribo/text/grouping/group_from_single_link.hh
index 4885cb5..242cce9 100644
--- a/scribo/text/grouping/group_from_single_link.hh
+++ b/scribo/text/grouping/group_from_single_link.hh
@@ -28,7 +28,7 @@
/// \file scribo/text/grouping/group_from_single_link.hh
///
-/// Link lines of text with their neighbor line if they have one.
+/// Link text objects with their neighbor line if they have one.
# include <mln/core/concept/image.hh>
# include <mln/core/site_set/box.hh>
@@ -40,9 +40,8 @@
# include <scribo/text/grouping/internal/find_root.hh>
+# include <scribo/core/object_image.hh>
# include <scribo/core/macros.hh>
-# include <scribo/util/text.hh>
-# include <scribo/make/text.hh>
namespace scribo
@@ -54,55 +53,44 @@ namespace scribo
namespace grouping
{
- /// Link lines of text with their neighbor line if they have one.
+ using namespace mln;
+
+ /// Link text objects with their neighbor line if they have one.
/*!
- ** \param[in] text The lines of text.
+ ** \param[in] objects An object image.
** \param[in] link_array The neighbor line of each line.
**
- ** \return The grouped and non-grouped lines of text.
+ ** \return An object image with grouped objects.
*/
- template <typename I>
- scribo::util::text<I>
- group_from_single_link(const scribo::util::text<I>& text,
+ template <typename L>
+ object_image(L)
+ group_from_single_link(const object_image(L)& objects,
const mln::util::array<unsigned>& link_array);
# ifndef MLN_INCLUDE_ONLY
- template <typename I>
+ template <typename L>
inline
- scribo::util::text<I>
- group_from_single_link(const scribo::util::text<I>& text,
+ object_image(L)
+ group_from_single_link(const object_image(L)& objects,
const mln::util::array<unsigned>& link_array)
{
trace::entering("scribo::text::grouping::group_from_single_link");
- mln_precondition(text.is_valid());
- mln_precondition(link_array.nelements() == text.nbboxes().next());
- mln_precondition(link_array.nelements() == text.bboxes().nelements());
+ mln_precondition(objects.is_valid());
+ mln_precondition(link_array.nelements() == objects.nlabels().next());
+ mln_precondition(link_array.nelements() == objects.bboxes().nelements());
mln::util::array<unsigned> parent_array = link_array;
for_all_components(i, parent_array)
internal::find_root(parent_array, i);
- mln::util::array< accu::bbox<mln_site(I)> > tboxes;
- tboxes.resize(text.nbboxes().next());
- for_all_components(i, text.bboxes())
- tboxes[parent_array[i]].take(text.bbox(i));
-
- mln::util::array< box<mln_site(I)> > result;
- // component 0, the background, has an invalid box.
- result.append(box<mln_site(I)>());
- for_all_components(i, tboxes)
- if (tboxes[i].is_valid())
- result.append(tboxes[i]);
-
- I lbl = labeling::relabel(text.label_image(), text.nbboxes(),
- convert::to<fun::i2v::array<mln_value(I)> >(parent_array));
- mln_value(I) new_nbboxes = result.nelements() - 1;
+ object_image(L) output;
+ output.init_from_(objects);
+ output.relabel(parent_array);
trace::exiting("scribo::text::grouping::group_from_single_link");
- /// FIXME: construct a new util::text from the old one.
- return scribo::make::text(result, lbl, new_nbboxes);
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/text/grouping/group_with_graph.hh
b/scribo/text/grouping/group_with_graph.hh
index e266cad..7865a7b 100644
--- a/scribo/text/grouping/group_with_graph.hh
+++ b/scribo/text/grouping/group_with_graph.hh
@@ -34,10 +34,15 @@
# include <mln/math/abs.hh>
+# include <mln/labeling/compute.hh>
+
+# include <mln/accu/center.hh>
+
# include <mln/util/array.hh>
# include <mln/util/graph.hh>
# include <scribo/core/macros.hh>
+# include <scribo/core/object_image.hh>
# include <scribo/text/grouping/internal/init_link_array.hh>
# include <scribo/text/grouping/internal/find_graph_link.hh>
# include <scribo/util/text.hh>
@@ -63,7 +68,7 @@ namespace scribo
*/
template <typename L>
mln::util::graph
- group_with_graph(const scribo::util::text<L>& text,
+ group_with_graph(const object_image(L)& text,
unsigned neighb_max_distance);
# ifndef MLN_INCLUDE_ONLY
@@ -71,25 +76,30 @@ namespace scribo
template <typename L>
inline
mln::util::graph
- group_with_graph(const scribo::util::text<L>& text,
+ group_with_graph(const object_image(L)& text,
unsigned neighb_max_distance)
{
trace::entering("scribo::text::grouping::group_with_graph");
- mln::util::graph g(text.nbboxes().next());
+ mln::util::graph g(text.nlabels().next());
- for_all_ncomponents(i, text.nbboxes())
+ for_all_ncomponents(i, text.nlabels())
{
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
+ mln::util::array<mln_result(accu::center<mln_psite(L)>)>
+ mass_center = labeling::compute(accu::meta::center(),
+ text,
+ text.nlabels());
+
// -------
// | |
// | X------->
// | |
// -------
- internal::find_graph_link(g, text, i, dmax, text.mass_center(i));
+ internal::find_graph_link(g, text, i, dmax, mass_center[i]);
}
trace::exiting("scribo::text::grouping::group_with_graph");
diff --git a/scribo/text/grouping/group_with_several_graphes.hh
b/scribo/text/grouping/group_with_several_graphes.hh
index 292c663..24cea3d 100644
--- a/scribo/text/grouping/group_with_several_graphes.hh
+++ b/scribo/text/grouping/group_with_several_graphes.hh
@@ -26,7 +26,7 @@
#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_GRAPHES_HH
# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_GRAPHES_HH
-/// \file scribo/text/grouping/group_with_several_graphes.hh
+/// \file
///
/// Group character bounding boxes with several graphes.
@@ -37,11 +37,12 @@
# include <mln/math/abs.hh>
# include <mln/util/array.hh>
+# include <mln/util/graph.hh>
+# include <scribo/core/object_image.hh>
# include <scribo/core/macros.hh>
# include <scribo/text/grouping/internal/init_link_array.hh>
# include <scribo/text/grouping/internal/find_graph_link.hh>
-# include <scribo/util/text.hh>
namespace scribo
{
@@ -56,27 +57,33 @@ namespace scribo
/// Look up for neighbors on the left of each box.
template <typename L>
mln::util::graph
- group_with_several_graphes(const scribo::util::text<L>& text,
- unsigned neighb_max_distance);
+ group_with_several_graphes(const object_image(L)& objects,
+ unsigned neighb_max_distance);
# ifndef MLN_INCLUDE_ONLY
template <typename L>
inline
mln::util::graph
- group_with_several_graphes(const scribo::util::text<L>& text,
- unsigned neighb_max_distance)
+ group_with_several_graphes(const object_image(L)& objects,
+ unsigned neighb_max_distance)
{
trace::entering("scribo::text::grouping::group_with_several_graphes");
- mln::util::graph g(text.nbboxes().next());
+ mln::util::graph g(objects.nlabels().next());
- for_all_ncomponents(i, text.nbboxes())
+ for_all_ncomponents(i, objects.nlabels())
{
- unsigned midcol = (text.bbox(i).pmax().col()
- - text.bbox(i).pmin().col()) / 2;
+ unsigned midcol = (objects.bbox(i).pmax().col()
+ - objects.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
- mln_site(L) c = text.mass_center(i);
+
+ mln::util::array<mln_result(accu::center<mln_psite(L)>)>
+ mass_center = labeling::compute(accu::meta::center(),
+ objects,
+ objects.nlabels());
+
+ mln_site(L) c = mass_center(i);
// -------
// | X------->
@@ -93,16 +100,16 @@ namespace scribo
/// Left link from the top anchor.
mln_site(L) a1 = c;
- a1.row() = text.bbox(i).pmin().row() + (c.row() - text.bbox(i).pmin().row()) / 4;
- internal::find_graph_link(g, text, i, dmax, a1);
+ a1.row() = objects.bbox(i).pmin().row() + (c.row() - objects.bbox(i).pmin().row()) /
4;
+ internal::find_graph_link(g, objects, i, dmax, a1);
/// First site on the right of the central site
- internal::find_graph_link(g, text, i, dmax, c);
+ internal::find_graph_link(g, objects, i, dmax, c);
/// Left link from the bottom anchor.
mln_site(L) a2 = c;
- a2.row() = text.bbox(i).pmax().row() - (c.row() - text.bbox(i).pmin().row()) / 4;
- internal::find_graph_link(g, text, i, dmax, a2);
+ a2.row() = objects.bbox(i).pmax().row() - (c.row() - objects.bbox(i).pmin().row()) /
4;
+ internal::find_graph_link(g, objects, i, dmax, a2);
}
diff --git a/scribo/text/grouping/group_with_several_right_links.hh
b/scribo/text/grouping/group_with_several_right_links.hh
index d8ac693..c785b0e 100644
--- a/scribo/text/grouping/group_with_several_right_links.hh
+++ b/scribo/text/grouping/group_with_several_right_links.hh
@@ -37,6 +37,7 @@
# include <mln/util/array.hh>
+# include <scribo/core/object_image.hh>
# include <scribo/core/macros.hh>
# include <scribo/text/grouping/internal/init_link_array.hh>
# include <scribo/text/grouping/internal/find_right_link.hh>
@@ -52,6 +53,8 @@ namespace scribo
namespace grouping
{
+ using namespace mln;
+
/// Map each character bounding box to its right bounding box neighbor
/// if possible.
/// Iterate to the right but link boxes to the right.
diff --git a/scribo/text/grouping/internal/find_graph_link.hh
b/scribo/text/grouping/internal/find_graph_link.hh
index 41ed0c7..b6fa1ee 100644
--- a/scribo/text/grouping/internal/find_graph_link.hh
+++ b/scribo/text/grouping/internal/find_graph_link.hh
@@ -37,7 +37,7 @@
# include <mln/util/array.hh>
-# include <scribo/util/text.hh>
+# include <scribo/core/object_image.hh>
# include <scribo/text/grouping/internal/update_graph_link.hh>
//FIXME: not generic.
@@ -63,10 +63,11 @@ namespace scribo
/// \param current_comp The current line being processed.
/// \param dmax The maximum lookup distance.
/// \param c Start point of the neighbor lookup.
+ //
template <typename G, typename L>
void
find_graph_link(Graph<G>& g_,
- const scribo::util::text<L>& text,
+ const object_image(L)& text,
unsigned current_comp,
int dmax,
const mln_site(L)& c);
@@ -76,7 +77,7 @@ namespace scribo
template <typename G, typename L>
void
find_graph_link(Graph<G>& g_,
- const scribo::util::text<L>& text,
+ const object_image(L)& text,
unsigned current_comp,
int dmax,
const mln_site(L)& c)
@@ -91,13 +92,12 @@ namespace scribo
/// First site on the right of the central site
mln_site(L) p = c + right;
- const L& lbl = text.label_image();
- while (lbl.domain().has(p) && (lbl(p) == literal::zero
- || lbl(p) == current_comp)
+ while (text.domain().has(p) && (text(p) == literal::zero
+ || text(p) == current_comp)
&& math::abs(p.col() - c.col()) < dmax)
++p.col();
- update_graph_link(lbl, g, p, c, current_comp, dmax);
+ update_graph_link(text, g, p, c, current_comp, dmax);
trace::exiting("scribo::text::grouping::internal::find_graph_link");
}
diff --git a/scribo/text/grouping/internal/find_right_link.hh
b/scribo/text/grouping/internal/find_right_link.hh
index b98811e..bd3c863 100644
--- a/scribo/text/grouping/internal/find_right_link.hh
+++ b/scribo/text/grouping/internal/find_right_link.hh
@@ -36,7 +36,7 @@
# include <mln/util/array.hh>
-# include <scribo/util/text.hh>
+# include <scribo/core/object_image.hh>
# include <scribo/text/grouping/internal/update_link_array.hh>
//FIXME: not generic.
@@ -54,6 +54,8 @@ namespace scribo
namespace internal
{
+ using namespace mln;
+
/// Find the right neighbor of a line of text if exists.
///
/// \param text The lines of text.
@@ -61,23 +63,24 @@ namespace scribo
/// \param current_comp A text line id.
/// \param dmax The maximum lookup distance.
/// \param c The lookup start point.
+ //
template <typename L>
void
find_right_link(const object_image(L)& text,
- mln::util::array<unsigned>& right_link,
- unsigned current_comp,
- int dmax,
- const mln_site(L)& c);
+ mln::util::array<unsigned>& right_link,
+ unsigned current_comp,
+ int dmax,
+ const mln_site(L)& c);
# ifndef MLN_INCLUDE_ONLY
template <typename L>
void
find_right_link(const object_image(L)& objects,
- mln::util::array<unsigned>& right_link,
- unsigned current_comp,
- int dmax,
- const mln_site(L)& c)
+ mln::util::array<unsigned>& right_link,
+ unsigned current_comp,
+ int dmax,
+ const mln_site(L)& c)
{
///FIXME: the following code is not generic...
/// First site on the right of the central site
diff --git a/scribo/text/grouping/internal/update_graph_link.hh
b/scribo/text/grouping/internal/update_graph_link.hh
index c576290..9fd3ede 100644
--- a/scribo/text/grouping/internal/update_graph_link.hh
+++ b/scribo/text/grouping/internal/update_graph_link.hh
@@ -32,6 +32,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/graph.hh>
+# include <mln/math/abs.hh>
namespace scribo
{
@@ -45,7 +46,19 @@ namespace scribo
namespace internal
{
+ using namespace mln;
+
+
/// Update graph edges if a valid neighbor is found.
+ ///
+ /// \param[in] lbl_ A label image.
+ /// \param[in] g_ A graph.
+ /// \param[in] p A site of \p lbl_.
+ /// \param[in] c A site of \p lbl_.
+ /// \param[in] i A vertex id.
+ /// \param[in] dmax The maximum distance allowed to look for a
+ /// neighbor.
+ //
template <typename I, typename G>
void
update_graph_link(const Image<I>& lbl_, Graph<G>& g_,
diff --git a/scribo/text/grouping/internal/update_link_array.hh
b/scribo/text/grouping/internal/update_link_array.hh
index 4deb25c..ef20dc9 100644
--- a/scribo/text/grouping/internal/update_link_array.hh
+++ b/scribo/text/grouping/internal/update_link_array.hh
@@ -34,6 +34,7 @@
# include <mln/core/concept/image.hh>
# include <mln/util/array.hh>
+# include <mln/math/abs.hh>
namespace scribo
@@ -48,11 +49,21 @@ namespace scribo
namespace internal
{
+ using namespace mln;
+
+
/// Update the lookup table \p link_array if a neighbor is found
/// on the right of the current bbox.
+ ///
+ /// \param[in] lbl A label image.
+ /// \param[in] link_array Links of bounding boxes.
+ /// \param[in] p A site of \p lbl.
+ /// \param[in] c A site of \p lbl.
+ //
template <typename I>
void
- update_link_array(const Image<I>& lbl, mln::util::array<unsigned>&
link_array,
+ update_link_array(const Image<I>& lbl,
+ mln::util::array<unsigned>& link_array,
const mln_site(I)& p, const mln_site(I)& c,
unsigned i, int dmax);
--
1.5.6.5