
* scribo/Makefile: add new targets. * scribo/debug/save_linked_textbboxes_image.hh, * scribo/debug/save_table_image.hh, * scribo/debug/save_textbboxes_image.hh: improve outputs. * scribo/draw/bounding_box_links.hh: draw mass centers. * scribo/filter/small_components.hh: add an assertion. * scribo/src/extract_text_double_link.cc, * scribo/src/extract_text_double_several_links.cc, * scribo/src/extract_text_multiple_links.cc, * scribo/src/extract_text_single_link.cc: cleanup small components. * scribo/src/extract_text_several_left_links.cc, * scribo/src/extract_text_several_multiple_links, * scribo/src/rectangularity.cc, * scribo/src/table_erase.cc, * scribo/src/table_rebuild_opening.cc, * scribo/src/table_rebuild_rank.cc: new sample code. * scribo/table/align_lines_horizontaly.hh, * scribo/table/align_lines_verticaly.hh: fix compilation issues. * scribo/table/erase.hh: fix traces. * scribo/table/extract.hh, * scribo/table/extract_lines_with_opening.hh, * scribo/table/extract_lines_with_rank.hh: update prototypes. * scribo/table/rebuild.hh: use for_all_elements instead of for_all_components. * scribo/text/grouping/group_from_double_link.hh: fix wrong link validation. * scribo/text/grouping/group_with_multiple_links.hh, * scribo/text/grouping/group_with_single_left_link.hh, * scribo/text/grouping/group_with_single_right_link.hh: refactor code... * scribo/text/grouping/internal/find_left_graph_link.hh, * scribo/text/grouping/internal/find_left_link.hh, * scribo/text/grouping/internal/find_right_link.hh: ... here. * scribo/text/grouping/internal/update_link_array.hh: fix wrong conditions. * scribo/text/grouping/group_with_several_left_links.hh, * scribo/text/grouping/group_with_several_multiple_links.hh, * scribo/text/grouping/group_with_several_right_links.hh: new variants using three anchors instead of one to find the left/right neighbors. --- milena/sandbox/ChangeLog | 57 +++++ milena/sandbox/scribo/Makefile | 22 ++- .../scribo/debug/save_linked_textbboxes_image.hh | 74 ++++++- milena/sandbox/scribo/debug/save_table_image.hh | 4 +- .../sandbox/scribo/debug/save_textbboxes_image.hh | 3 +- milena/sandbox/scribo/draw/bounding_box_links.hh | 215 +++++++++++++++++++- milena/sandbox/scribo/filter/small_components.hh | 6 +- .../sandbox/scribo/src/extract_text_double_link.cc | 9 +- ...ink.cc => extract_text_double_several_links.cc} | 32 +-- .../scribo/src/extract_text_multiple_links.cc | 1 + ..._link.cc => extract_text_several_left_links.cc} | 44 +---- ...s.cc => extract_text_several_multiple_links.cc} | 11 +- .../sandbox/scribo/src/extract_text_single_link.cc | 1 + milena/sandbox/scribo/src/rectangularity.cc | 38 ++++ ...tract_text_multiple_links.cc => table_erase.cc} | 47 ++--- ..._multiple_links.cc => table_rebuild_opening.cc} | 66 +++---- ...ext_multiple_links.cc => table_rebuild_rank.cc} | 66 +++---- .../scribo/table/align_lines_horizontaly.hh | 2 +- .../sandbox/scribo/table/align_lines_verticaly.hh | 7 +- milena/sandbox/scribo/table/erase.hh | 9 +- milena/sandbox/scribo/table/extract.hh | 27 ++- .../scribo/table/extract_lines_with_opening.hh | 15 +- .../scribo/table/extract_lines_with_rank.hh | 13 +- milena/sandbox/scribo/table/rebuild.hh | 23 +-- .../scribo/text/grouping/group_from_double_link.hh | 30 ++-- .../text/grouping/group_with_multiple_links.hh | 32 ++- ...ft_link.hh => group_with_several_left_links.hh} | 89 ++++++--- ...nks.hh => group_with_several_multiple_links.hh} | 58 ++++-- ...t_link.hh => group_with_several_right_links.hh} | 89 ++++++--- .../text/grouping/group_with_single_left_link.hh | 26 +-- .../text/grouping/group_with_single_right_link.hh | 24 +-- ...pdate_link_array.hh => find_left_graph_link.hh} | 62 ++++--- .../find_left_link.hh} | 91 +++++---- .../find_right_link.hh} | 87 ++++---- .../text/grouping/internal/update_link_array.hh | 10 +- 35 files changed, 907 insertions(+), 483 deletions(-) copy milena/sandbox/scribo/src/{extract_text_double_link.cc => extract_text_double_several_links.cc} (77%) copy milena/sandbox/scribo/src/{extract_text_single_link.cc => extract_text_several_left_links.cc} (64%) copy milena/sandbox/scribo/src/{extract_text_multiple_links.cc => extract_text_several_multiple_links.cc} (90%) create mode 100644 milena/sandbox/scribo/src/rectangularity.cc copy milena/sandbox/scribo/src/{extract_text_multiple_links.cc => table_erase.cc} (53%) copy milena/sandbox/scribo/src/{extract_text_multiple_links.cc => table_rebuild_opening.cc} (53%) copy milena/sandbox/scribo/src/{extract_text_multiple_links.cc => table_rebuild_rank.cc} (53%) copy milena/sandbox/scribo/text/grouping/{group_with_single_left_link.hh => group_with_several_left_links.hh} (53%) copy milena/sandbox/scribo/text/grouping/{group_with_multiple_links.hh => group_with_several_multiple_links.hh} (58%) copy milena/sandbox/scribo/text/grouping/{group_with_single_right_link.hh => group_with_several_right_links.hh} (53%) copy milena/sandbox/scribo/text/grouping/internal/{update_link_array.hh => find_left_graph_link.hh} (58%) copy milena/sandbox/scribo/text/grouping/{group_with_multiple_links.hh => internal/find_left_link.hh} (52%) copy milena/sandbox/scribo/text/grouping/{group_with_multiple_links.hh => internal/find_right_link.hh} (52%) diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog index 414a7fb..558ec99 100644 --- a/milena/sandbox/ChangeLog +++ b/milena/sandbox/ChangeLog @@ -1,3 +1,60 @@ +2009-03-24 Guillaume Lazzara <z@lrde.epita.fr> + + Update Scribo's code. + + * scribo/Makefile: add new targets. + + * scribo/debug/save_linked_textbboxes_image.hh, + * scribo/debug/save_table_image.hh, + * scribo/debug/save_textbboxes_image.hh: improve outputs. + + * scribo/draw/bounding_box_links.hh: draw mass centers. + + * scribo/filter/small_components.hh: add an assertion. + + * scribo/src/extract_text_double_link.cc, + * scribo/src/extract_text_double_several_links.cc, + * scribo/src/extract_text_multiple_links.cc, + * scribo/src/extract_text_single_link.cc: cleanup small components. + + * scribo/src/extract_text_several_left_links.cc, + * scribo/src/extract_text_several_multiple_links, + * scribo/src/rectangularity.cc, + * scribo/src/table_erase.cc, + * scribo/src/table_rebuild_opening.cc, + * scribo/src/table_rebuild_rank.cc: new sample code. + + * scribo/table/align_lines_horizontaly.hh, + * scribo/table/align_lines_verticaly.hh: fix compilation issues. + + * scribo/table/erase.hh: fix traces. + + * scribo/table/extract.hh, + * scribo/table/extract_lines_with_opening.hh, + * scribo/table/extract_lines_with_rank.hh: update prototypes. + + * scribo/table/rebuild.hh: use for_all_elements instead of + for_all_components. + + * scribo/text/grouping/group_from_double_link.hh: fix wrong + link validation. + + * scribo/text/grouping/group_with_multiple_links.hh, + * scribo/text/grouping/group_with_single_left_link.hh, + * scribo/text/grouping/group_with_single_right_link.hh: refactor code... + + * scribo/text/grouping/internal/find_left_graph_link.hh, + * scribo/text/grouping/internal/find_left_link.hh, + * scribo/text/grouping/internal/find_right_link.hh: ... here. + + * scribo/text/grouping/internal/update_link_array.hh: fix wrong + conditions. + + * scribo/text/grouping/group_with_several_left_links.hh, + * scribo/text/grouping/group_with_several_multiple_links.hh, + * scribo/text/grouping/group_with_several_right_links.hh: new variants + using three anchors instead of one to find the left/right neighbors. + 2009-03-24 Frederic Bour <bour@lrde.epita.fr> Add from_accu functional wrapper. diff --git a/milena/sandbox/scribo/Makefile b/milena/sandbox/scribo/Makefile index 09a3a2d..3c3e1a5 100644 --- a/milena/sandbox/scribo/Makefile +++ b/milena/sandbox/scribo/Makefile @@ -18,6 +18,9 @@ photo: demat.hh dmap: g++ $(CXX_FLAGS) src/dmap.cc -o bin/dmap.out +rectangularity: + g++ $(CXX_FLAGS) src/rectangularity.cc -o bin/rectangularity.out + extract_text_single_link: g++ $(CXX_FLAGS) src/extract_text_single_link.cc -o bin/extract_text_single_link.out @@ -25,15 +28,30 @@ extract_text_single_link: extract_text_double_link: g++ $(CXX_FLAGS) src/extract_text_double_link.cc -o bin/extract_text_double_link.out +extract_text_double_several_links: + g++ $(CXX_FLAGS) src/extract_text_double_several_links.cc -o bin/extract_text_double_several_links.out + extract_text_multiple_links: g++ $(CXX_FLAGS) src/extract_text_multiple_links.cc -o bin/extract_text_multiple_links.out -table_rebuild: - g++ $(CXX_FLAGS) src/table_rebuild.cc -o bin/table_rebuild.out +extract_text_several_multiple_links: + g++ $(CXX_FLAGS) src/extract_text_several_multiple_links.cc -o bin/extract_text_several_multiple_links.out + +extract_text_several_left_links: + g++ $(CXX_FLAGS) src/extract_text_several_left_links.cc -o bin/extract_text_several_left_links.out + +table_rebuild_rank: + g++ $(CXX_FLAGS) src/table_rebuild_rank.cc -o bin/table_rebuild_rank.out + +table_rebuild_opening: + g++ $(CXX_FLAGS) src/table_rebuild_opening.cc -o bin/table_rebuild_opening.out table_extract: g++ $(CXX_FLAGS) src/table_extract.cc -o bin/table_extract.out +table_erase: + g++ $(CXX_FLAGS) src/table_erase.cc -o bin/table_erase.out + thin_bboxes: g++ $(CXX_FLAGS) src/thin_bboxes.cc -o bin/thin_bboxes.out diff --git a/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh b/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh index 4012c05..e7d2a40 100644 --- a/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh +++ b/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh @@ -35,6 +35,8 @@ # include <mln/core/concept/image.hh> # include <mln/core/concept/graph.hh> +# include <mln/labeling/compute.hh> +# include <mln/accu/center.hh> # include <mln/level/convert.hh> # include <mln/value/rgb8.hh> # include <mln/util/array.hh> @@ -72,8 +74,20 @@ namespace scribo const mln::util::array<unsigned>& left_link, const mln::util::array<unsigned>& right_array, const value::rgb8& box_value, + const value::rgb8& link_value, + const std::string& filename); + + 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); @@ -104,8 +118,13 @@ namespace scribo mln_precondition(exact(input).is_valid()); mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input); + + mln::util::array<mln_site(I)::vec> mass_centers + = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes()); + draw::bounding_boxes(tmp, text.bboxes(), box_value); - draw::bounding_box_links(tmp, text.bboxes(), link_array, link_value); + draw::bounding_box_links(tmp, mass_centers, link_array, link_value); + io::ppm::save(tmp, filename); trace::exiting("scribo::debug::save_linked_textbboxes_image"); @@ -120,24 +139,62 @@ namespace scribo const mln::util::array<unsigned>& left_link, const mln::util::array<unsigned>& right_link, const value::rgb8& box_value, - const value::rgb8& left_value, - const value::rgb8& right_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 = level::convert(value::rgb8(), input); + + mln::util::array<mln_site(I)::vec> mass_centers + = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes()); + draw::bounding_boxes(tmp, text.bboxes(), box_value); - draw::bounding_box_links(tmp, text.bboxes(), + draw::bounding_box_links(tmp, mass_centers, left_link, right_link, - left_value, right_value); + 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 = level::convert(value::rgb8(), input); + + mln::util::array<mln_site(I)::vec> mass_centers + = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes()); + + draw::bounding_boxes(tmp, text.bboxes(), box_value); + draw::bounding_box_links(tmp, 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 @@ -153,8 +210,13 @@ namespace scribo mln_precondition(exact(input).is_valid()); mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input); - draw::bounding_boxes(tmp, text.bboxes(), box_value); + + mln::util::array<mln_site(I)::vec> mass_centers + = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes()); + + draw::bounding_boxes(tmp, mass_centers, 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"); diff --git a/milena/sandbox/scribo/debug/save_table_image.hh b/milena/sandbox/scribo/debug/save_table_image.hh index 4ed0a68..ebc65f6 100644 --- a/milena/sandbox/scribo/debug/save_table_image.hh +++ b/milena/sandbox/scribo/debug/save_table_image.hh @@ -98,7 +98,7 @@ namespace scribo draw::bounding_boxes(out2, tableboxes.second(), bbox_color); io::ppm::save(out2, filename); - trace::exiting("scribo::internal::save_table"); + trace::exiting("scribo::debug::save_table_image"); } @@ -121,7 +121,7 @@ namespace scribo draw::bounding_boxes(out2, tableboxes.second(), bbox_color); io::ppm::save(out2, filename); - trace::exiting("scribo::internal::save_table"); + trace::exiting("scribo::debug::save_table_image"); } # endif // ! MLN_INCLUDE_ONLY diff --git a/milena/sandbox/scribo/debug/save_textbboxes_image.hh b/milena/sandbox/scribo/debug/save_textbboxes_image.hh index 86a8b3f..dde3d38 100644 --- a/milena/sandbox/scribo/debug/save_textbboxes_image.hh +++ b/milena/sandbox/scribo/debug/save_textbboxes_image.hh @@ -40,7 +40,6 @@ # include <mln/io/ppm/save.hh> # include <scribo/draw/bounding_boxes.hh> -# include <scribo/make/debug_filename.hh> namespace scribo @@ -76,7 +75,7 @@ namespace scribo mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input); draw::bounding_boxes(tmp, textbboxes, value); - io::ppm::save(tmp, scribo::make::debug_filename(filename)); + io::ppm::save(tmp, filename); trace::exiting("scribo::debug::save_textbboxes_image"); } diff --git a/milena/sandbox/scribo/draw/bounding_box_links.hh b/milena/sandbox/scribo/draw/bounding_box_links.hh index e33da38..5d695f6 100644 --- a/milena/sandbox/scribo/draw/bounding_box_links.hh +++ b/milena/sandbox/scribo/draw/bounding_box_links.hh @@ -56,6 +56,13 @@ namespace scribo const mln::util::array<unsigned>& link_array, const mln_value(I)& value); + template <typename I> + inline + void + bounding_box_links(Image<I>& input_, + const mln::util::array<mln_site(I)::vec>& mass_centers, + const mln::util::array<unsigned>& link_array, + const mln_value(I)& value); template <typename I> void @@ -63,8 +70,46 @@ namespace scribo const mln::util::array< box<mln_site(I)> >& bboxes, const mln::util::array<unsigned>& left_link, const mln::util::array<unsigned>& right_link, + const mln_value(I)& value); + + template <typename I> + inline + void + bounding_box_links(Image<I>& input_, + const mln::util::array<mln_site(I)::vec>& mass_centers, + const mln::util::array<unsigned>& left_link, + const mln::util::array<unsigned>& right_link, + const mln_value(I)& value); + + template <typename I> + inline + void + bounding_box_links(Image<I>& input_, + const mln::util::array< box<mln_site(I)> >& bboxes, + const mln::util::array<unsigned>& left_link, + const mln::util::array<unsigned>& right_link, const mln_value(I)& left_link_value, - const mln_value(I)& right_link_value); + const mln_value(I)& right_link_value, + const mln_value(I)& validated_link_value); + + template <typename I> + inline + void + bounding_box_links(Image<I>& input_, + const mln::util::array<mln_site(I)::vec>& mass_centers, + const mln::util::array<unsigned>& left_link, + const mln::util::array<unsigned>& right_link, + const mln_value(I)& left_link_value, + const mln_value(I)& right_link_value, + const mln_value(I)& validated_link_value); + + template <typename I, typename G> + inline + void + bounding_box_links(Image<I>& input, + const mln::util::array< box<mln_site(I)> >& bboxes, + const Graph<G>& g, + const mln_value(I)& link_value); # ifndef MLN_INCLUDE_ONLY @@ -147,22 +192,182 @@ namespace scribo trace::exiting("scribo::draw::bounding_box_links"); } + template <typename I> + inline + void + bounding_box_links(Image<I>& input_, + const mln::util::array<mln_site(I)::vec>& mass_centers, + const mln::util::array<unsigned>& link_array, + const mln_value(I)& value) + { + trace::entering("scribo::draw::bounding_box_links"); + + I& input = exact(input_); + + mln_precondition(input.is_valid()); + + for_all_components(i, link_array) + { + if (link_array[i] != i) + mln::draw::line(input, + mass_centers[i], + mass_centers[link_array[i]], + value); + input(mass_centers[i]) = value; + } + + trace::exiting("scribo::draw::bounding_box_links"); + } + template <typename I> inline void - bounding_box_links(Image<I>& input, + bounding_box_links(Image<I>& input_, const mln::util::array< box<mln_site(I)> >& bboxes, const mln::util::array<unsigned>& left_link, const mln::util::array<unsigned>& right_link, + const mln_value(I)& value) + { + trace::entering("scribo::draw::bounding_box_links"); + mln_precondition(exact(input).is_valid()); + + I& input = exact(input_); + + mln_precondition(input.is_valid()); + + for_all_components(i, left_link) + { + unsigned nbh = right_link[left_link[i]]; + if (nbh == i && left_link[i] != i) + mln::draw::line(input, + bboxes[i].center(), + bboxes[left_link[i]].center(), + value); + } + + trace::exiting("scribo::draw::bounding_box_links"); + } + + template <typename I> + inline + void + bounding_box_links(Image<I>& input_, + const mln::util::array<mln_site(I)::vec>& mass_centers, + const mln::util::array<unsigned>& left_link, + const mln::util::array<unsigned>& right_link, + const mln_value(I)& value) + { + trace::entering("scribo::draw::bounding_box_links"); + mln_precondition(exact(input).is_valid()); + + I& input = exact(input_); + + mln_precondition(input.is_valid()); + + for_all_components(i, left_link) + { + unsigned nbh = right_link[left_link[i]]; + if (nbh == i && left_link[i] != i) + mln::draw::line(input, + mass_centers[i], + mass_centers[left_link[i]], + value); + input(mass_centers[i]) = value; + } + + trace::exiting("scribo::draw::bounding_box_links"); + } + + + template <typename I> + inline + void + bounding_box_links(Image<I>& input_, + const mln::util::array<mln_site(I)::vec>& mass_centers, + const mln::util::array<unsigned>& left_link, + const mln::util::array<unsigned>& right_link, const mln_value(I)& left_link_value, - const mln_value(I)& right_link_value) + const mln_value(I)& right_link_value, + const mln_value(I)& validated_link_value) { trace::entering("scribo::draw::bounding_box_links"); mln_precondition(exact(input).is_valid()); - bounding_box_links(input, bboxes, left_link, left_link_value); - bounding_box_links(input, bboxes, right_link, right_link_value); + I& input = exact(input_); + + mln_precondition(input.is_valid()); + + mln_site(I)::vec dleft = literal::origin; + dleft[0] = 2; + mln_site(I)::vec dright = literal::origin; + dright[0] = -2; + for_all_components(i, left_link) + { + mln::draw::line(input, + mass_centers[i] + dleft, + mass_centers[left_link[i]] + dleft, + left_link_value); + + mln::draw::line(input, + mass_centers[i] + dright, + mass_centers[right_link[i]] + dright, + right_link_value); + + unsigned nbh = right_link[left_link[i]]; + if (nbh == i && left_link[i] != i) + mln::draw::line(input, + mass_centers[i], + mass_centers[left_link[i]], + validated_link_value); + + input(mass_centers[i]) = validated_link_value; + } + + trace::exiting("scribo::draw::bounding_box_links"); + } + + template <typename I> + inline + void + bounding_box_links(Image<I>& input_, + const mln::util::array< box<mln_site(I)> >& bboxes, + const mln::util::array<unsigned>& left_link, + const mln::util::array<unsigned>& right_link, + const mln_value(I)& left_link_value, + const mln_value(I)& right_link_value, + const mln_value(I)& validated_link_value) + { + trace::entering("scribo::draw::bounding_box_links"); + mln_precondition(exact(input).is_valid()); + + I& input = exact(input_); + + mln_precondition(input.is_valid()); + + mln_site(I)::vec dleft = literal::origin; + dleft[0] = 2; + mln_site(I)::vec dright = literal::origin; + dright[0] = -2; + for_all_components(i, left_link) + { + mln::draw::line(input, + bboxes[i].center() + dleft, + bboxes[left_link[i]].center() + dleft, + left_link_value); + + mln::draw::line(input, + bboxes[i].center() + dright, + bboxes[right_link[i]].center() + dright, + right_link_value); + + unsigned nbh = right_link[left_link[i]]; + if (nbh == i && left_link[i] != i) + mln::draw::line(input, + bboxes[i].center(), + bboxes[left_link[i]].center(), + validated_link_value); + } trace::exiting("scribo::draw::bounding_box_links"); } diff --git a/milena/sandbox/scribo/filter/small_components.hh b/milena/sandbox/scribo/filter/small_components.hh index 8cb6858..fb8ff5a 100644 --- a/milena/sandbox/scribo/filter/small_components.hh +++ b/milena/sandbox/scribo/filter/small_components.hh @@ -40,6 +40,7 @@ # include <mln/labeling/blobs.hh> # include <mln/labeling/relabel.hh> +# include <mln/make/relabelfun.hh> # include <mln/util/array.hh> # include <mln/value/label_16.hh> @@ -191,7 +192,10 @@ namespace scribo mln_value(I) new_nbboxes; I new_lbl = labeling::relabel(text.label_image(), text.nbboxes(), - new_nbboxes, f); + mln::make::relabelfun(f, text.nbboxes(), + new_nbboxes)); + + mln_assertion(new_nbboxes.next() == bresult.nelements()); trace::exiting("scribo::filter::small_components"); return scribo::make::text(bresult, new_lbl, new_nbboxes); diff --git a/milena/sandbox/scribo/src/extract_text_double_link.cc b/milena/sandbox/scribo/src/extract_text_double_link.cc index ea4b2b8..d7de94b 100644 --- a/milena/sandbox/scribo/src/extract_text_double_link.cc +++ b/milena/sandbox/scribo/src/extract_text_double_link.cc @@ -29,14 +29,17 @@ #include <mln/essential/2d.hh> #include <mln/debug/colorize.hh> +#include <mln/debug/println.hh> #include <scribo/text/extract_bboxes.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/text/grouping/group_from_double_link.hh> +#include <scribo/filter/small_components.hh> #include <scribo/debug/save_textbboxes_image.hh> +#include <scribo/make/debug_filename.hh> int usage(const char *name) { @@ -62,6 +65,8 @@ int main(int argc, char* argv[]) scribo::util::text<image2d<value::label_16> > text = text::extract_bboxes(input, c8(), nbboxes); + text = filter::small_components(text,4); + mln::util::array<unsigned> left_link = text::grouping::group_with_single_left_link(text, 30); mln::util::array<unsigned> right_link @@ -80,8 +85,8 @@ int main(int argc, char* argv[]) scribo::debug::save_linked_textbboxes_image(input, text, left_link, right_link, - literal::red, literal::cyan, - literal::yellow, + literal::red, literal::cyan, literal::yellow, + literal::green, scribo::make::debug_filename("links.ppm")); // io::ppm::save(mln::debug::colorize(value::rgb8(), diff --git a/milena/sandbox/scribo/src/extract_text_double_link.cc b/milena/sandbox/scribo/src/extract_text_double_several_links.cc similarity index 77% copy from milena/sandbox/scribo/src/extract_text_double_link.cc copy to milena/sandbox/scribo/src/extract_text_double_several_links.cc index ea4b2b8..ee7d384 100644 --- a/milena/sandbox/scribo/src/extract_text_double_link.cc +++ b/milena/sandbox/scribo/src/extract_text_double_several_links.cc @@ -31,12 +31,14 @@ #include <mln/debug/colorize.hh> #include <scribo/text/extract_bboxes.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_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/text/grouping/group_from_double_link.hh> +#include <scribo/filter/small_components.hh> #include <scribo/debug/save_textbboxes_image.hh> +#include <scribo/make/debug_filename.hh> int usage(const char *name) { @@ -53,7 +55,7 @@ int main(int argc, char* argv[]) if (argc < 1) return usage(argv[0]); - scribo::make::internal::debug_filename_prefix = "extract_text_double_link"; + scribo::make::internal::debug_filename_prefix = "extract_text_double_several_links"; image2d<bool> input; io::pbm::load(input, argv[1]); @@ -62,33 +64,21 @@ int main(int argc, char* argv[]) scribo::util::text<image2d<value::label_16> > text = text::extract_bboxes(input, c8(), nbboxes); + text = filter::small_components(text,4); + mln::util::array<unsigned> left_link - = text::grouping::group_with_single_left_link(text, 30); + = text::grouping::group_with_several_left_links(text, 30); mln::util::array<unsigned> right_link - = text::grouping::group_with_single_right_link(text, 30); + = text::grouping::group_with_several_right_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_linked.ppm")); -// scribo::debug::save_linked_textbboxes_image(input, -// text, right_link, -// 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::red, literal::cyan, literal::yellow, + literal::green, scribo::make::debug_filename("links.ppm")); -// io::ppm::save(mln::debug::colorize(value::rgb8(), -// text.label_image(), -// text.nbboxes()), -// scribo::make::debug_filename("lbl_before.ppm")); - // With validation. scribo::util::text<image2d<value::label_16> > grouped_text = text::grouping::group_from_double_link(text, left_link, right_link); diff --git a/milena/sandbox/scribo/src/extract_text_multiple_links.cc b/milena/sandbox/scribo/src/extract_text_multiple_links.cc index 0c8c624..eacef81 100644 --- a/milena/sandbox/scribo/src/extract_text_multiple_links.cc +++ b/milena/sandbox/scribo/src/extract_text_multiple_links.cc @@ -35,6 +35,7 @@ #include <scribo/debug/save_textbboxes_image.hh> #include <scribo/debug/save_linked_textbboxes_image.hh> +#include <scribo/make/debug_filename.hh> int usage(const char *name) { diff --git a/milena/sandbox/scribo/src/extract_text_single_link.cc b/milena/sandbox/scribo/src/extract_text_several_left_links.cc similarity index 64% copy from milena/sandbox/scribo/src/extract_text_single_link.cc copy to milena/sandbox/scribo/src/extract_text_several_left_links.cc index 1dee956..a050ff3 100644 --- a/milena/sandbox/scribo/src/extract_text_single_link.cc +++ b/milena/sandbox/scribo/src/extract_text_several_left_links.cc @@ -30,12 +30,12 @@ #include <mln/essential/2d.hh> #include <scribo/text/extract_bboxes.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_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/make/debug_filename.hh> int usage(const char *name) { @@ -51,7 +51,7 @@ int main(int argc, char* argv[]) if (argc < 1) return usage(argv[0]); - scribo::make::internal::debug_filename_prefix = "extract_text_single_link"; + scribo::make::internal::debug_filename_prefix = "extract_text_several_left_links"; image2d<bool> input; io::pbm::load(input, argv[1]); @@ -63,19 +63,15 @@ int main(int argc, char* argv[]) { std::cout << "* Left grouping" << std::endl; mln::util::array<unsigned> left_link - = text::grouping::group_with_single_left_link(text, 30); + = 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")); -// io::ppm::save(mln::debug::colorize(value::rgb8(), -// text.label_image(), -// text.nbboxes()), -// scribo::make::debug_filename("lbl_before.ppm")); - scribo::util::text<image2d<value::label_16> > grouped_text + scribo::util::text<image2d<value::label_16> > grouped_text = text::grouping::group_from_single_link(text, left_link); std::cout << "AFTER - nbboxes = " << grouped_text.bboxes().nelements() << std::endl; @@ -88,35 +84,5 @@ int main(int argc, char* argv[]) scribo::make::debug_filename("left_bboxes.ppm")); } - { - std::cout << "* Left grouping" << std::endl; - mln::util::array<unsigned> right_link - = 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")); -// io::ppm::save(mln::debug::colorize(value::rgb8(), -// text.label_image(), -// text.nbboxes()), -// scribo::make::debug_filename("lbl_before.ppm")); - - scribo::util::text<image2d<value::label_16> > grouped_text - = text::grouping::group_from_single_link(text, right_link); - - io::ppm::save(mln::debug::colorize(value::rgb8(), - grouped_text.label_image(), - grouped_text.nbboxes()), - 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")); - } - - } diff --git a/milena/sandbox/scribo/src/extract_text_multiple_links.cc b/milena/sandbox/scribo/src/extract_text_several_multiple_links.cc similarity index 90% copy from milena/sandbox/scribo/src/extract_text_multiple_links.cc copy to milena/sandbox/scribo/src/extract_text_several_multiple_links.cc index 0c8c624..3c85c20 100644 --- a/milena/sandbox/scribo/src/extract_text_multiple_links.cc +++ b/milena/sandbox/scribo/src/extract_text_several_multiple_links.cc @@ -30,11 +30,12 @@ #include <mln/essential/2d.hh> #include <scribo/text/extract_bboxes.hh> -#include <scribo/text/grouping/group_with_multiple_links.hh> +#include <scribo/text/grouping/group_with_several_multiple_links.hh> #include <scribo/text/grouping/group_from_multiple_links.hh> #include <scribo/debug/save_textbboxes_image.hh> #include <scribo/debug/save_linked_textbboxes_image.hh> +#include <scribo/make/debug_filename.hh> int usage(const char *name) { @@ -50,7 +51,7 @@ int main(int argc, char* argv[]) if (argc < 1) return usage(argv[0]); - scribo::make::internal::debug_filename_prefix = "extract_text_multiple_links"; + scribo::make::internal::debug_filename_prefix = "extract_text_several_multiple_links"; image2d<bool> input; io::pbm::load(input, argv[1]); @@ -59,17 +60,13 @@ int main(int argc, char* argv[]) scribo::util::text<image2d<value::label_16> > text = text::extract_bboxes(input, c8(), nbboxes); - mln::util::graph g = text::grouping::group_with_multiple_links(text, 30); + mln::util::graph g = text::grouping::group_with_several_multiple_links(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")); -// io::ppm::save(mln::debug::colorize(value::rgb8(), -// text.label_image(), -// text.nbboxes()), -// scribo::make::debug_filename("lbl_before.ppm")); scribo::util::text<image2d<value::label_16> > grouped_text = text::grouping::group_from_multiple_links(text, g); diff --git a/milena/sandbox/scribo/src/extract_text_single_link.cc b/milena/sandbox/scribo/src/extract_text_single_link.cc index 1dee956..640f9f2 100644 --- a/milena/sandbox/scribo/src/extract_text_single_link.cc +++ b/milena/sandbox/scribo/src/extract_text_single_link.cc @@ -36,6 +36,7 @@ #include <scribo/debug/save_textbboxes_image.hh> #include <scribo/debug/save_linked_textbboxes_image.hh> +#include <scribo/make/debug_filename.hh> int usage(const char *name) { diff --git a/milena/sandbox/scribo/src/rectangularity.cc b/milena/sandbox/scribo/src/rectangularity.cc new file mode 100644 index 0000000..67f0bc8 --- /dev/null +++ b/milena/sandbox/scribo/src/rectangularity.cc @@ -0,0 +1,38 @@ +#include <mln/essential/2d.hh> +#include <mln/transform/distance_geodesic.hh> +#include <mln/core/var.hh> +#include <mln/fun/l2l/wrap.hh> +#include <mln/win/hline2d.hh> +#include <mln/morpho/watershed/flooding.hh> +#include <mln/morpho/watershed/superpose.hh> + +#include <scribo/make/debug_filename.hh> + +int main(int argc, char *argv[]) +{ + using namespace mln; + + using value::int_u16; + using value::label_16; + using value::label_8; + using value::rgb8; + + image2d<bool> input; + io::pbm::load(input, argv[1]); + + scribo::make::internal::debug_filename_prefix = "morpho"; + + label_16 nlabels; + image2d<label_16> lbl = labeling::blobs(input, c8(), nlabels); + + mln_VAR(dmap, transform::distance_geodesic(lbl, c8(), mln_max(unsigned))); + + io::pgm::save(level::transform(dmap, fun::l2l::wrap<label_8>()), "dmap.pgm"); + + { + image2d<unsigned> clo = morpho::closing::structural(dmap, win::disk2d(51)); + io::pgm::save(clo, scribo::make::debug_filename("clo_disk_51.pgm")); + image2d<float> r = morpho::tree:compute_attribute_image(accu::site_set::rectangularity<point2d>(),clo); + image2d<point2d> r = morpho::tree:max(r,c8()); + } +} diff --git a/milena/sandbox/scribo/src/extract_text_multiple_links.cc b/milena/sandbox/scribo/src/table_erase.cc similarity index 53% copy from milena/sandbox/scribo/src/extract_text_multiple_links.cc copy to milena/sandbox/scribo/src/table_erase.cc index 0c8c624..3cfcb46 100644 --- a/milena/sandbox/scribo/src/extract_text_multiple_links.cc +++ b/milena/sandbox/scribo/src/table_erase.cc @@ -28,13 +28,10 @@ #include <iostream> #include <mln/essential/2d.hh> +#include <mln/io/dump/save.hh> -#include <scribo/text/extract_bboxes.hh> -#include <scribo/text/grouping/group_with_multiple_links.hh> -#include <scribo/text/grouping/group_from_multiple_links.hh> +#include <scribo/table/extract.hh> -#include <scribo/debug/save_textbboxes_image.hh> -#include <scribo/debug/save_linked_textbboxes_image.hh> int usage(const char *name) { @@ -42,6 +39,7 @@ int usage(const char *name) return 1; } + int main(int argc, char* argv[]) { using namespace scribo; @@ -50,39 +48,20 @@ int main(int argc, char* argv[]) if (argc < 1) return usage(argv[0]); - scribo::make::internal::debug_filename_prefix = "extract_text_multiple_links"; + scribo::make::internal::debug_filename_prefix = "table_erase"; image2d<bool> input; io::pbm::load(input, argv[1]); + logical::not_inplace(input); - value::label_16 nbboxes; - scribo::util::text<image2d<value::label_16> > text - = text::extract_bboxes(input, c8(), nbboxes); - - mln::util::graph g = text::grouping::group_with_multiple_links(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")); -// io::ppm::save(mln::debug::colorize(value::rgb8(), -// text.label_image(), -// text.nbboxes()), -// scribo::make::debug_filename("lbl_before.ppm")); + typedef util::couple<util::array<box2d>, + util::array<box2d> > tables_t; - scribo::util::text<image2d<value::label_16> > grouped_text - = text::grouping::group_from_multiple_links(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")); - io::ppm::save(mln::debug::colorize(value::rgb8(), - grouped_text.label_image(), - grouped_text.nbboxes()), - scribo::make::debug_filename("label_color.ppm")); + value::label_16 ncells; + tables_t tables = scribo::table::extract_lines_with_rank(input, c8(), ncells, + win::vline2d(51), win::hline2d(51), + 8,6); + image2d<bool> input_notables = scribo::table::erase(input, tables); + io::pbm::save(input_notables, scribo::make::debug_filename("input_notables.pbm")); } - diff --git a/milena/sandbox/scribo/src/extract_text_multiple_links.cc b/milena/sandbox/scribo/src/table_rebuild_opening.cc similarity index 53% copy from milena/sandbox/scribo/src/extract_text_multiple_links.cc copy to milena/sandbox/scribo/src/table_rebuild_opening.cc index 0c8c624..375646d 100644 --- a/milena/sandbox/scribo/src/extract_text_multiple_links.cc +++ b/milena/sandbox/scribo/src/table_rebuild_opening.cc @@ -28,13 +28,12 @@ #include <iostream> #include <mln/essential/2d.hh> +#include <mln/pw/all.hh> -#include <scribo/text/extract_bboxes.hh> -#include <scribo/text/grouping/group_with_multiple_links.hh> -#include <scribo/text/grouping/group_from_multiple_links.hh> - -#include <scribo/debug/save_textbboxes_image.hh> -#include <scribo/debug/save_linked_textbboxes_image.hh> +#include <scribo/table/rebuild.hh> +#include <scribo/table/erase.hh> +#include <scribo/table/extract_lines_with_opening.hh> +#include <scribo/make/debug_filename.hh> int usage(const char *name) { @@ -42,6 +41,7 @@ int usage(const char *name) return 1; } + int main(int argc, char* argv[]) { using namespace scribo; @@ -50,39 +50,35 @@ int main(int argc, char* argv[]) if (argc < 1) return usage(argv[0]); - scribo::make::internal::debug_filename_prefix = "extract_text_multiple_links"; + scribo::make::internal::debug_filename_prefix = argv[0]; image2d<bool> input; io::pbm::load(input, argv[1]); + logical::not_inplace(input); + typedef util::couple<util::array<box2d>,util::array<box2d> > tblboxes_t; + + win::vline2d vline(51); + win::hline2d hline(51); value::label_16 nbboxes; - scribo::util::text<image2d<value::label_16> > text - = text::extract_bboxes(input, c8(), nbboxes); - - mln::util::graph g = text::grouping::group_with_multiple_links(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")); -// io::ppm::save(mln::debug::colorize(value::rgb8(), -// text.label_image(), -// text.nbboxes()), -// scribo::make::debug_filename("lbl_before.ppm")); - - scribo::util::text<image2d<value::label_16> > grouped_text - = text::grouping::group_from_multiple_links(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")); - io::ppm::save(mln::debug::colorize(value::rgb8(), - grouped_text.label_image(), - grouped_text.nbboxes()), - scribo::make::debug_filename("label_color.ppm")); + tblboxes_t lineboxes + = table::extract_lines_with_opening(input, c8(), nbboxes, + vline, hline); -} + value::label_8 ncells; + image2d<value::label_8> tables = scribo::table::rebuild(input, lineboxes, 30, ncells); + + std::cout << "ncells (including background) = " << ncells << std::endl; + io::ppm::save(mln::debug::colorize(value::rgb8(), tables, ncells), + 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); + 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); + io::pbm::save(in_wo_tables, + scribo::make::debug_filename("input_wo_tables.pbm")); +} diff --git a/milena/sandbox/scribo/src/extract_text_multiple_links.cc b/milena/sandbox/scribo/src/table_rebuild_rank.cc similarity index 53% copy from milena/sandbox/scribo/src/extract_text_multiple_links.cc copy to milena/sandbox/scribo/src/table_rebuild_rank.cc index 0c8c624..77b2b79 100644 --- a/milena/sandbox/scribo/src/extract_text_multiple_links.cc +++ b/milena/sandbox/scribo/src/table_rebuild_rank.cc @@ -28,13 +28,12 @@ #include <iostream> #include <mln/essential/2d.hh> +#include <mln/pw/all.hh> -#include <scribo/text/extract_bboxes.hh> -#include <scribo/text/grouping/group_with_multiple_links.hh> -#include <scribo/text/grouping/group_from_multiple_links.hh> - -#include <scribo/debug/save_textbboxes_image.hh> -#include <scribo/debug/save_linked_textbboxes_image.hh> +#include <scribo/table/rebuild.hh> +#include <scribo/table/erase.hh> +#include <scribo/table/extract_lines_with_rank.hh> +#include <scribo/make/debug_filename.hh> int usage(const char *name) { @@ -42,6 +41,7 @@ int usage(const char *name) return 1; } + int main(int argc, char* argv[]) { using namespace scribo; @@ -50,39 +50,35 @@ int main(int argc, char* argv[]) if (argc < 1) return usage(argv[0]); - scribo::make::internal::debug_filename_prefix = "extract_text_multiple_links"; + scribo::make::internal::debug_filename_prefix = argv[0]; image2d<bool> input; io::pbm::load(input, argv[1]); + logical::not_inplace(input); + typedef util::couple<util::array<box2d>,util::array<box2d> > tblboxes_t; + + win::vline2d vline(51); + win::hline2d hline(51); value::label_16 nbboxes; - scribo::util::text<image2d<value::label_16> > text - = text::extract_bboxes(input, c8(), nbboxes); - - mln::util::graph g = text::grouping::group_with_multiple_links(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")); -// io::ppm::save(mln::debug::colorize(value::rgb8(), -// text.label_image(), -// text.nbboxes()), -// scribo::make::debug_filename("lbl_before.ppm")); - - scribo::util::text<image2d<value::label_16> > grouped_text - = text::grouping::group_from_multiple_links(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")); - io::ppm::save(mln::debug::colorize(value::rgb8(), - grouped_text.label_image(), - grouped_text.nbboxes()), - scribo::make::debug_filename("label_color.ppm")); + tblboxes_t lineboxes + = table::extract_lines_with_rank(input, c8(), nbboxes, + vline, hline, 6, 6); -} + value::label_8 ncells; + image2d<value::label_8> tables = scribo::table::rebuild(input, lineboxes, 5, ncells); + + std::cout << "ncells (including background) = " << ncells << std::endl; + io::ppm::save(mln::debug::colorize(value::rgb8(), tables, ncells), + 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); + 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); + io::pbm::save(in_wo_tables, + scribo::make::debug_filename("input_wo_tables.pbm")); +} diff --git a/milena/sandbox/scribo/table/align_lines_horizontaly.hh b/milena/sandbox/scribo/table/align_lines_horizontaly.hh index 4828cfe..88e283e 100644 --- a/milena/sandbox/scribo/table/align_lines_horizontaly.hh +++ b/milena/sandbox/scribo/table/align_lines_horizontaly.hh @@ -79,7 +79,7 @@ namespace scribo util::array<int> align_lines_horizontaly(const Image<I>& input, util::array<box<mln_site(I)> >& lines_bboxes, - max_alignment_diff) + unsigned max_alignment_diff) { trace::entering("scribo::table::align_lines_horizontaly"); diff --git a/milena/sandbox/scribo/table/align_lines_verticaly.hh b/milena/sandbox/scribo/table/align_lines_verticaly.hh index e4d04ba..c1062bf 100644 --- a/milena/sandbox/scribo/table/align_lines_verticaly.hh +++ b/milena/sandbox/scribo/table/align_lines_verticaly.hh @@ -79,9 +79,10 @@ namespace scribo template <typename I> util::array<int> align_lines_verticaly(const Image<I>& input, - util::array<box<mln_site(I)> >& lines_bboxes) + util::array<box<mln_site(I)> >& lines_bboxes, + unsigned max_alignment_diff) { - trace::entering("scribo::table::align_lines_horizontaly"); + trace::entering("scribo::table::align_lines_verticaly"); mln_precondition(exact(input).is_valid()); util::array<int> res = internal::align_lines(geom::ncols(input), @@ -90,7 +91,7 @@ namespace scribo lines_bboxes, 1, max_alignment_diff); - trace::exiting("scribo::table::align_lines_horizontaly"); + trace::exiting("scribo::table::align_lines_verticaly"); return res; } diff --git a/milena/sandbox/scribo/table/erase.hh b/milena/sandbox/scribo/table/erase.hh index 9d94edb..2f5957a 100644 --- a/milena/sandbox/scribo/table/erase.hh +++ b/milena/sandbox/scribo/table/erase.hh @@ -37,6 +37,8 @@ # include <mln/core/site_set/box.hh> # include <mln/core/routine/duplicate.hh> +# include <mln/pw/all.hh> + # include <mln/util/array.hh> # include <mln/util/couple.hh> @@ -48,6 +50,8 @@ namespace scribo namespace table { + using namespace mln; + /// Erase table line bboxes from an image. /// /// \param[in] line_bboxes vertical and horizontal line bounding @@ -64,7 +68,6 @@ namespace scribo util::array< box<mln_site(I)> > >& line_bboxes); - # ifndef MLN_INCLUDE_ONLY @@ -74,7 +77,7 @@ namespace scribo const util::couple<util::array< box<mln_site(I)> >, util::array< box<mln_site(I)> > >& line_bboxes) { - trace::entering("scribo::internal::erase_table"); + trace::entering("scribo::internal::erase"); mlc_equal(mln_value(I),bool)::check(); mln_precondition(exact(in).is_valid()); @@ -83,7 +86,7 @@ namespace scribo erase_bboxes(output, line_bboxes.first()); erase_bboxes(output, line_bboxes.second()); - trace::exiting("scribo::internal::erase_table"); + trace::exiting("scribo::internal::erase"); return output; } diff --git a/milena/sandbox/scribo/table/extract.hh b/milena/sandbox/scribo/table/extract.hh index 06520c9..ebe4955 100644 --- a/milena/sandbox/scribo/table/extract.hh +++ b/milena/sandbox/scribo/table/extract.hh @@ -51,8 +51,20 @@ namespace scribo namespace table { + /// Extract tables from a binary image. + /// Use arbitrary criterions. + /* + ** \param[in] input_ A binary image. + ** \param[in,out] ncells The number of cells. + ** + ** \return a couple. The first element is an image containing the + ** cells components. The second element is a couple of vertical and + ** horizontal table lines. + */ template <typename I, typename V> - mln_ch_value(I,V) + mln::util::couple<mln_ch_value(I,V), + util::couple<util::array<box<mln_site(I)> >, + util::array<box<mln_site(I)> > > > extract(const Image<I>& input_, V& ncells); @@ -60,7 +72,9 @@ namespace scribo template <typename I, typename V> inline - mln_ch_value(I,V) + mln::util::couple<mln_ch_value(I,V), + util::couple<util::array<box<mln_site(I)> >, + util::array<box<mln_site(I)> > > > extract(const Image<I>& input_, V& ncells) { trace::entering("scribo::table::extract"); @@ -75,11 +89,14 @@ namespace scribo 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); tblboxes_t lineboxes - = table::extract_lines_with_rank(input, c8(), V(), + = table::extract_lines_with_rank(input, c8(), ncells, vline, hline, 6, 6); - image2d<V> tables - = scribo::table::rebuild(input, lineboxes, 30, ncells); + typedef mln::util::couple<mln_ch_value(I,V), + util::couple<util::array<box<mln_site(I)> >, + util::array<box<mln_site(I)> > > > + tables_t; + tables_t tables = scribo::table::rebuild(input, lineboxes, 30, ncells); trace::exiting("scribo::table::extract"); return tables; diff --git a/milena/sandbox/scribo/table/extract_lines_with_opening.hh b/milena/sandbox/scribo/table/extract_lines_with_opening.hh index 55fd77f..a4ddfd1 100644 --- a/milena/sandbox/scribo/table/extract_lines_with_opening.hh +++ b/milena/sandbox/scribo/table/extract_lines_with_opening.hh @@ -63,7 +63,7 @@ namespace scribo * * \param[in] input_ A binary image. * \param[in] nbh_ The neighborhood used for labeling image components. - * \param[in] label_type The type used to store the labels. + * \param[out] nlines The number of lines found. * \param[in] vwin Window used to extract the vertical lines in a morphological * opening * \param[in] hwin Window used to extract the horizontal lines in a morphological @@ -77,7 +77,7 @@ namespace scribo util::couple<util::array<box<mln_site(I)> >, util::array<box<mln_site(I)> > > extract_lines_with_opening(const Image<I>& input_, - const Neighborhood<N>& nbh_, const V& label_type, + const Neighborhood<N>& nbh_, V& nlines, const Window<HW>& vwin, const Window<VW>& hwin); @@ -88,8 +88,8 @@ namespace scribo util::couple<util::array<box<mln_site(I)> >, util::array<box<mln_site(I)> > > extract_lines_with_opening(const Image<I>& input_, - const Neighborhood<N>& nbh_, const V& label_type, - const Window<VW>& vwin_, const Window<HW>& hwin_); + const Neighborhood<N>& nbh_, V& nlines, + const Window<VW>& vwin_, const Window<HW>& hwin_) { trace::entering("scribo::table::extract_lines_with_opening"); @@ -106,12 +106,11 @@ namespace scribo mln_precondition(vwin.is_valid()); mln_precondition(hwin.is_valid()); - typedef accu::bbox<mln_psite(I)> A; - typedef util::array<mln_result(A)> boxes_t; + typedef util::array<box<mln_site(I)> > boxes_t; // Vertical lines mln_ch_value(I,bool) vfilter = morpho::erosion(input, vwin); - boxes_t vboxes = component_bboxes(vfilter, nbh, label_type); + boxes_t vboxes = component_bboxes(vfilter, nbh, nlines).first(); for_all_components(i, vboxes) { vboxes[i].enlarge(0, vwin.length() / 2); @@ -120,7 +119,7 @@ namespace scribo // Horizontal lines. mln_ch_value(I,bool) hfilter = morpho::erosion(input, hwin); - boxes_t hboxes = component_bboxes(hfilter, nbh, label_type); + boxes_t hboxes = component_bboxes(hfilter, nbh, nlines).first(); for_all_components(i, hboxes) { hboxes[i].enlarge(1, hwin.length() / 2); diff --git a/milena/sandbox/scribo/table/extract_lines_with_rank.hh b/milena/sandbox/scribo/table/extract_lines_with_rank.hh index 63c90b1..dbb3d50 100644 --- a/milena/sandbox/scribo/table/extract_lines_with_rank.hh +++ b/milena/sandbox/scribo/table/extract_lines_with_rank.hh @@ -63,7 +63,7 @@ namespace scribo * * \param[in] input_ A binary image. * \param[in] nbh_ The neighborhood used for labeling image components. - * \param[in] label_type The type used to store the labels. + * \param[out] nlines The number of lines. * \param[in] vwin Window used to extract the vertical lines in the rank * filter. * \param[in] hwin Window used to extract the horizontal lines in the rank @@ -79,7 +79,7 @@ namespace scribo util::couple<util::array<box<mln_site(I)> >, util::array<box<mln_site(I)> > > extract_lines_with_rank(const Image<I>& input_, - const Neighborhood<N>& nbh_, const V& label_type, + const Neighborhood<N>& nbh_, V& nlines, const Window<HW>& vwin, const Window<VW>& hwin, unsigned vrank_k, unsigned hrank_k); @@ -91,7 +91,7 @@ namespace scribo util::couple<util::array<box<mln_site(I)> >, util::array<box<mln_site(I)> > > extract_lines_with_rank(const Image<I>& input_, - const Neighborhood<N>& nbh_, const V& label_type, + const Neighborhood<N>& nbh_, V& nlines, const Window<VW>& vwin_, const Window<HW>& hwin_, unsigned vrank_k, unsigned hrank_k) { @@ -110,12 +110,11 @@ namespace scribo mln_precondition(vwin.is_valid()); mln_precondition(hwin.is_valid()); - typedef accu::bbox<mln_psite(I)> A; - typedef util::array<mln_result(A)> boxes_t; + typedef util::array<box<mln_site(I)> > boxes_t; // Vertical lines mln_ch_value(I,bool) vfilter = morpho::rank_filter(input, vwin, vrank_k); - boxes_t vboxes = component_bboxes(vfilter, nbh, label_type); + boxes_t vboxes = component_bboxes(vfilter, nbh, nlines).first(); for_all_components(i, vboxes) { vboxes[i].enlarge(0, vwin.length() / 2); @@ -124,7 +123,7 @@ namespace scribo // Horizontal lines. mln_ch_value(I,bool) hfilter = morpho::rank_filter(input, hwin, hrank_k); - boxes_t hboxes = component_bboxes(hfilter, nbh, label_type); + boxes_t hboxes = component_bboxes(hfilter, nbh, nlines).first(); for_all_components(i, hboxes) { hboxes[i].enlarge(1, hwin.length() / 2); diff --git a/milena/sandbox/scribo/table/rebuild.hh b/milena/sandbox/scribo/table/rebuild.hh index b78112d..4c632ba 100644 --- a/milena/sandbox/scribo/table/rebuild.hh +++ b/milena/sandbox/scribo/table/rebuild.hh @@ -57,7 +57,9 @@ namespace scribo { template <typename I, typename V> - mln_ch_value(I,V) + mln::util::couple<mln_ch_value(I,V), + util::couple<util::array<box<mln_site(I)> >, + util::array<box<mln_site(I)> > > > rebuild(const Image<I>& in_, const util::couple<util::array<box<mln_site(I)> >, util::array<box<mln_site(I)> > >& lineboxes, @@ -69,7 +71,9 @@ namespace scribo template <typename I, typename V> - mln_ch_value(I,V) + mln::util::couple<mln_ch_value(I,V), + util::couple<util::array<box<mln_site(I)> >, + util::array<box<mln_site(I)> > > > rebuild(const Image<I>& in_, const util::couple<util::array<box<mln_site(I)> >, util::array<box<mln_site(I)> > >& lineboxes, @@ -85,10 +89,6 @@ namespace scribo util::couple<util::array<box<mln_site(I)> >, util::array<box<mln_site(I)> > > tblboxes = lineboxes; -//# ifndef SCRIBO_NDEBUG -// scribo::debug::save_table_image(in, tblboxes, -// literal::red, "table.ppm"); -//# endif scribo::debug::save_table_image(in, tblboxes, literal::red, "table-raw.ppm"); @@ -121,20 +121,15 @@ namespace scribo mln_ch_value(I,bool) res; initialize(res, in); data::fill(res, false); - for_all_components(i, tblboxes.first()) + for_all_elements(i, tblboxes.first()) mln::draw::box(res, tblboxes.first()[i], true); - for_all_components(i, tblboxes.second()) + for_all_elements(i, tblboxes.second()) mln::draw::box(res, tblboxes.second()[i], true); mln_ch_value(I,V) lbl = labeling::background(res, c8(), ncells); -//# ifndef SCRIBO_NDEBUG -// scribo::debug::save_table_image(in, tblboxes, -// literal::red, "table-connected.ppm"); -//# endif - trace::exiting("scribo::table::rebuild"); - return lbl; + return mln::make::couple(lbl, tblboxes); } diff --git a/milena/sandbox/scribo/text/grouping/group_from_double_link.hh b/milena/sandbox/scribo/text/grouping/group_from_double_link.hh index 582abcd..d4e5d71 100644 --- a/milena/sandbox/scribo/text/grouping/group_from_double_link.hh +++ b/milena/sandbox/scribo/text/grouping/group_from_double_link.hh @@ -82,27 +82,31 @@ namespace scribo mln::util::array< accu::bbox<mln_site(I)> > tboxes; tboxes.resize(text.bboxes().nelements()); - mln::util::array<unsigned> left_parent = left_link; - for_all_components(i, left_parent) - left_parent[i] = internal::find_root(left_parent, i); - - fun::i2v::array<mln_value(I)> f(text.bboxes().nelements(), - literal::zero); + mln::util::array<unsigned> parent(left_link.nelements()); + internal::init_link_array(parent); for_all_components(i, text.bboxes()) { unsigned nbh = right_link[left_link[i]]; if (nbh == i) { - tboxes[left_parent[i]].take(text.bbox(i)); - f(i) = left_parent[left_link[i]]; - } - else - { - f(i) = i; - tboxes[i].take(text.bbox(i)); + unsigned par = internal::find_root(parent, left_link[i]); + if (par < i) + parent[par] = i; + else + parent[i] = par; } } + for_all_elements(i, parent) + for (unsigned i = parent.nelements() - 1; i < parent.nelements(); --i) + { + parent[i] = parent[parent[i]]; + tboxes[parent[i]].take(text.bbox(i)); + } + + fun::i2v::array<unsigned> f; + convert::from_to(parent, f); + // Update bounding boxes information. mln::util::array< box<mln_site(I)> > bresult; // component 0, the background, has an invalid box. diff --git a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh b/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh index 236cf16..bfe1bc3 100644 --- a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh +++ b/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh @@ -35,6 +35,8 @@ /// Group character bounding boxes with multiple links. # include <mln/core/concept/image.hh> +# include <mln/labeling/compute.hh> +# include <mln/accu/center.hh> # include <mln/math/abs.hh> @@ -55,35 +57,47 @@ namespace scribo { /// Group character bounding boxes with multiple links. - /// Look up for neighbors on the left of each box. - template <typename I> + /// Look up for neighbors on the right of each box. + template <typename L> mln::util::graph - group_with_multiple_links(const scribo::util::text<I>& text, + group_with_multiple_links(const scribo::util::text<L>& text, unsigned neighb_max_distance); # ifndef MLN_INCLUDE_ONLY - template <typename I> + template <typename L> inline mln::util::graph - group_with_multiple_links(const scribo::util::text<I>& text, + group_with_multiple_links(const scribo::util::text<L>& text, unsigned neighb_max_distance) { trace::entering("scribo::text::grouping::group_with_multiple_links"); mln::util::graph g(text.nbboxes().next()); + mln::util::array<mln_site(L)::vec> centers + = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes()); + for_all_ncomponents(i, text.nbboxes()) { unsigned midcol = (text.bbox(i).pmax().col() - text.bbox(i).pmin().col()) / 2; int dmax = midcol + neighb_max_distance; - mln_site(I) c = text.bbox(i).center(); - + mln_site(L) c = centers[i]; + + // ------- + // | | + // | | + // | | + // | X-------> + // | | + // | | + // | | + // ------- /// First site on the right of the central site - mln_site(I) p = c + right; + mln_site(L) p = c + right; - const I& lbl = text.label_image(); + const L& lbl = text.label_image(); while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i) && math::abs(p.col() - c.col()) < dmax) ++p.col(); diff --git a/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh b/milena/sandbox/scribo/text/grouping/group_with_several_left_links.hh similarity index 53% copy from milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh copy to milena/sandbox/scribo/text/grouping/group_with_several_left_links.hh index ca1a8da..84a743d 100644 --- a/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh +++ b/milena/sandbox/scribo/text/grouping/group_with_several_left_links.hh @@ -27,10 +27,10 @@ // Public License. -#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_LEFT_LINK_HH -# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_LEFT_LINK_HH +#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_LEFT_LINKS_HH +# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_LEFT_LINKS_HH -/// \file scribo/text/grouping/group_with_single_left_link.hh +/// \file scribo/text/grouping/group_with_several_left_links.hh /// /// Link text bounding boxes with their left neighbor. /// @@ -38,19 +38,16 @@ # include <mln/core/concept/image.hh> # include <mln/core/concept/neighborhood.hh> - -# include <mln/math/abs.hh> +# include <mln/labeling/compute.hh> +# include <mln/accu/center.hh> # include <mln/util/array.hh> # include <scribo/core/macros.hh> # include <scribo/text/grouping/internal/init_link_array.hh> -# include <scribo/text/grouping/internal/update_link_array.hh> -# include <scribo/text/grouping/internal/find_root.hh> +# include <scribo/text/grouping/internal/find_left_link.hh> # include <scribo/util/text.hh> -//FIXME: not generic. -# include <mln/core/alias/dpoint2d.hh> namespace scribo { @@ -69,50 +66,80 @@ namespace scribo template <typename L> inline mln::util::array<unsigned> - group_with_single_left_link(const scribo::util::text<L>& text, - unsigned neighb_max_distance); + group_with_several_left_links(const scribo::util::text<L>& text, + unsigned neighb_max_distance); # ifndef MLN_INCLUDE_ONLY template <typename L> inline mln::util::array<unsigned> - group_with_single_left_link(const scribo::util::text<L>& text, - unsigned neighb_max_distance) + group_with_several_left_links(const scribo::util::text<L>& text, + unsigned neighb_max_distance) { - trace::entering("scribo::text::grouping::group_with_single_left_link"); + trace::entering("scribo::text::grouping::group_with_several_left_links"); mln_precondition(text.is_valid()); - mln::util::array<unsigned> left_link(text.nbboxes().next()); - internal::init_link_array(left_link); + mln::util::array<unsigned> + link_1(text.nbboxes().next()), link_2(text.nbboxes().next()), + link_3(text.nbboxes().next()), final_link(text.nbboxes().next()); + internal::init_link_array(link_1); + internal::init_link_array(link_2); + internal::init_link_array(link_3); + + //FIXME: should be removed if this information is stored in util::text. + mln::util::array<mln_site(L)::vec> centers + = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes()); + std::cout << "dmax = " << neighb_max_distance << std::endl; for_all_ncomponents(i, text.nbboxes()) { + // ------- + // | X-------> + // | | + // | | + // | X-------> + // | | + // | | + // | X-------> + // ------- unsigned midcol = (text.bbox(i).pmax().col() - text.bbox(i).pmin().col()) / 2; int dmax = midcol + neighb_max_distance; + mln_site(L) c = text.bbox(i).center(); - /// - /// Find a neighbor on the right - /// + /// 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_left_link(text, link_1, i, dmax, a1); - ///FIXME: the following code is not generic... - /// First site on the right of the central site - mln_site(L) p = c + right; + /// Left link from the central site + internal::find_left_link(text, link_2, i, dmax, centers[i]); - const L& lbl = text.label_image(); - while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i || - left_link[i] == lbl(p)) - && math::abs(p.col() - c.col()) < dmax) - ++p.col(); + /// 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_left_link(text, link_3, i, dmax, a2); + } - internal::update_link_array(lbl, left_link, p, c, i, dmax); + for_all_ncomponents(i, text.nbboxes()) + { + if (link_2[i] != i) + final_link[i] = link_2[i]; + else if (link_1[i] == link_3[i]) + final_link[i] = link_1[i]; + else if (link_1[i] != i && link_3[i] == i) + final_link[i] = link_1[i]; + else if (link_3[i] != i && link_1[i] == i) + final_link[i] = link_3[i]; + else + final_link[i] = i; } - trace::exiting("scribo::text::grouping::group_with_single_left_link"); - return left_link; + trace::exiting("scribo::text::grouping::group_with_several_left_links"); + return final_link; } # endif // ! MLN_INCLUDE_ONLY @@ -123,4 +150,4 @@ namespace scribo } // end of namespace scribo -#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_LEFT_LINK_HH +#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_LEFT_LINKS_HH diff --git a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh b/milena/sandbox/scribo/text/grouping/group_with_several_multiple_links.hh similarity index 58% copy from milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh copy to milena/sandbox/scribo/text/grouping/group_with_several_multiple_links.hh index 236cf16..4dec5c7 100644 --- a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh +++ b/milena/sandbox/scribo/text/grouping/group_with_several_multiple_links.hh @@ -27,14 +27,16 @@ // Public License. -#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH -# define SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH +#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_MULTIPLE_LINKS_HH +# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_MULTIPLE_LINKS_HH -/// \file scribo/text/grouping/group_with_multiple_links.hh +/// \file scribo/text/grouping/group_with_several_multiple_links.hh /// -/// Group character bounding boxes with multiple links. +/// Group character bounding boxes with several multiple links. # include <mln/core/concept/image.hh> +# include <mln/labeling/compute.hh> +# include <mln/accu/center.hh> # include <mln/math/abs.hh> @@ -43,6 +45,7 @@ # include <scribo/core/macros.hh> # include <scribo/text/grouping/internal/init_link_array.hh> # include <scribo/text/grouping/internal/update_link_graph.hh> +# include <scribo/text/grouping/internal/find_left_graph_link.hh> # include <scribo/util/text.hh> namespace scribo @@ -54,44 +57,61 @@ namespace scribo namespace grouping { - /// Group character bounding boxes with multiple links. + /// Group character bounding boxes with several_multiple links. /// Look up for neighbors on the left of each box. - template <typename I> + template <typename L> mln::util::graph - group_with_multiple_links(const scribo::util::text<I>& text, + group_with_several_multiple_links(const scribo::util::text<L>& text, unsigned neighb_max_distance); # ifndef MLN_INCLUDE_ONLY - template <typename I> + template <typename L> inline mln::util::graph - group_with_multiple_links(const scribo::util::text<I>& text, + group_with_several_multiple_links(const scribo::util::text<L>& text, unsigned neighb_max_distance) { - trace::entering("scribo::text::grouping::group_with_multiple_links"); + trace::entering("scribo::text::grouping::group_with_several_multiple_links"); mln::util::graph g(text.nbboxes().next()); + mln::util::array<mln_site(L)::vec> centers + = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes()); + for_all_ncomponents(i, text.nbboxes()) { unsigned midcol = (text.bbox(i).pmax().col() - text.bbox(i).pmin().col()) / 2; int dmax = midcol + neighb_max_distance; - mln_site(I) c = text.bbox(i).center(); + mln_site(L) c = centers[i]; + + // ------- + // | X-------> + // | | + // | | + // | X-------> + // | | + // | | + // | X-------> + // ------- + + /// 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_left_graph_link(g, text, i, dmax, a1); /// First site on the right of the central site - mln_site(I) p = c + right; + internal::find_left_graph_link(g, text, i, dmax, c); - const I& lbl = text.label_image(); - while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i) - && math::abs(p.col() - c.col()) < dmax) - ++p.col(); + /// 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_left_graph_link(g, text, i, dmax, a2); - internal::update_link_graph(lbl, g, p, c, i, dmax); } - trace::exiting("scribo::text::grouping::group_with_multiple_links"); + trace::exiting("scribo::text::grouping::group_with_several_multiple_links"); return g; } @@ -103,4 +123,4 @@ namespace scribo } // end of namespace scribo -#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH +#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_MULTIPLE_LINKS_HH diff --git a/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh b/milena/sandbox/scribo/text/grouping/group_with_several_right_links.hh similarity index 53% copy from milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh copy to milena/sandbox/scribo/text/grouping/group_with_several_right_links.hh index 5740b09..cc2ee2c 100644 --- a/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh +++ b/milena/sandbox/scribo/text/grouping/group_with_several_right_links.hh @@ -27,10 +27,10 @@ // Public License. -#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_RIGHT_LINK_HH -# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_RIGHT_LINK_HH +#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_RIGHT_LINKS_HH +# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_RIGHT_LINKS_HH -/// \file scribo/text/grouping/group_with_single_right_link.hh +/// \file scribo/text/grouping/group_with_several_right_links.hh /// /// Link text bounding boxes with their right neighbor. /// @@ -38,19 +38,16 @@ # include <mln/core/concept/image.hh> # include <mln/core/concept/neighborhood.hh> - -# include <mln/math/abs.hh> +# include <mln/labeling/compute.hh> +# include <mln/accu/center.hh> # include <mln/util/array.hh> # include <scribo/core/macros.hh> # include <scribo/text/grouping/internal/init_link_array.hh> -# include <scribo/text/grouping/internal/update_link_array.hh> -# include <scribo/text/grouping/internal/find_root.hh> +# include <scribo/text/grouping/internal/find_right_link.hh> # include <scribo/util/text.hh> -//FIXME: not generic. -# include <mln/core/alias/dpoint2d.hh> namespace scribo { @@ -69,50 +66,80 @@ namespace scribo template <typename L> inline mln::util::array<unsigned> - group_with_single_right_link(const scribo::util::text<L>& text, - unsigned neighb_max_distance); + group_with_several_right_links(const scribo::util::text<L>& text, + unsigned neighb_max_distance); # ifndef MLN_INCLUDE_ONLY template <typename L> inline mln::util::array<unsigned> - group_with_single_right_link(const scribo::util::text<L>& text, - unsigned neighb_max_distance) + group_with_several_right_links(const scribo::util::text<L>& text, + unsigned neighb_max_distance) { - trace::entering("scribo::text::grouping::group_with_single_right_link"); + trace::entering("scribo::text::grouping::group_with_several_right_links"); mln_precondition(text.is_valid()); - mln::util::array<unsigned> right_link(text.nbboxes().next()); - internal::init_link_array(right_link); + mln::util::array<unsigned> + link_1(text.nbboxes().next()), link_2(text.nbboxes().next()), + link_3(text.nbboxes().next()), final_link(text.nbboxes().next()); + internal::init_link_array(link_1); + internal::init_link_array(link_2); + internal::init_link_array(link_3); + + //FIXME: should be removed if this information is stored in util::text. + mln::util::array<mln_site(L)::vec> centers + = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes()); + std::cout << "dmax = " << neighb_max_distance << std::endl; for_all_ncomponents(i, text.nbboxes()) { + // ------- + // <------X | + // | | + // | | + // <------X | + // | | + // | | + // <------X | + // ------- unsigned midcol = (text.bbox(i).pmax().col() - text.bbox(i).pmin().col()) / 2; int dmax = midcol + neighb_max_distance; + mln_site(L) c = text.bbox(i).center(); - /// - /// Find a neighbor on the left - /// + /// Right 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_right_link(text, link_1, i, dmax, a1); - ///FIXME: the following code is not generic... - /// First site on the left of the central site - mln_site(L) p = c + left; + /// Right link from the central site + internal::find_right_link(text, link_2, i, dmax, centers[i]); - const L& lbl = text.label_image(); - while (lbl.domain().has(p) && (lbl(p) == literal::zero - || lbl(p) == i || right_link[i] == lbl(p)) - && math::abs(p.col() - c.col()) < dmax) - --p.col(); + /// Right 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_right_link(text, link_3, i, dmax, a2); + } - internal::update_link_array(lbl, right_link, p, c, i, dmax); + for_all_ncomponents(i, text.nbboxes()) + { + if (link_2[i] != i) + final_link[i] = link_2[i]; + else if (link_1[i] == link_3[i]) + final_link[i] = link_1[i]; + else if (link_1[i] != i && link_3[i] == i) + final_link[i] = link_1[i]; + else if (link_3[i] != i && link_1[i] == i) + final_link[i] = link_3[i]; + else + final_link[i] = i; } - trace::exiting("scribo::text::grouping::group_with_single_right_link"); - return right_link; + trace::exiting("scribo::text::grouping::group_with_several_right_links"); + return final_link; } # endif // ! MLN_INCLUDE_ONLY @@ -123,4 +150,4 @@ namespace scribo } // end of namespace scribo -#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SINGLE_RIGHT_LINK_HH +#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_RIGHT_LINKS_HH diff --git a/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh b/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh index ca1a8da..1b39485 100644 --- a/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh +++ b/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh @@ -38,6 +38,7 @@ # include <mln/core/concept/image.hh> # include <mln/core/concept/neighborhood.hh> +# include <mln/labeling/compute.hh> # include <mln/math/abs.hh> @@ -45,8 +46,7 @@ # include <scribo/core/macros.hh> # include <scribo/text/grouping/internal/init_link_array.hh> -# include <scribo/text/grouping/internal/update_link_array.hh> -# include <scribo/text/grouping/internal/find_root.hh> +# include <scribo/text/grouping/internal/find_left_link.hh> # include <scribo/util/text.hh> //FIXME: not generic. @@ -87,28 +87,18 @@ namespace scribo mln::util::array<unsigned> left_link(text.nbboxes().next()); internal::init_link_array(left_link); + mln::util::array<mln_site(L)::vec> centers + = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes()); + for_all_ncomponents(i, text.nbboxes()) { unsigned midcol = (text.bbox(i).pmax().col() - text.bbox(i).pmin().col()) / 2; int dmax = midcol + neighb_max_distance; - mln_site(L) c = text.bbox(i).center(); - - /// - /// Find a neighbor on the right - /// - - ///FIXME: the following code is not generic... - /// 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) == i || - left_link[i] == lbl(p)) - && math::abs(p.col() - c.col()) < dmax) - ++p.col(); + mln_site(L) c = centers[i]; - internal::update_link_array(lbl, left_link, p, c, i, dmax); + /// Find a neighbor on the left + internal::find_left_link(text, left_link, i, dmax, c); } trace::exiting("scribo::text::grouping::group_with_single_left_link"); diff --git a/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh b/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh index 5740b09..6327d9f 100644 --- a/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh +++ b/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh @@ -34,10 +34,11 @@ /// /// Link text bounding boxes with their right neighbor. /// -/// Merge code with text::grouping::group_with_single_right_link.hh +/// \todo Merge code with text::grouping::group_with_single_right_link.hh # include <mln/core/concept/image.hh> # include <mln/core/concept/neighborhood.hh> +# include <mln/labeling/compute.hh> # include <mln/math/abs.hh> @@ -47,6 +48,7 @@ # include <scribo/text/grouping/internal/init_link_array.hh> # include <scribo/text/grouping/internal/update_link_array.hh> # include <scribo/text/grouping/internal/find_root.hh> +# include <scribo/text/grouping/internal/find_right_link.hh> # include <scribo/util/text.hh> //FIXME: not generic. @@ -87,28 +89,20 @@ namespace scribo mln::util::array<unsigned> right_link(text.nbboxes().next()); internal::init_link_array(right_link); + mln::util::array<mln_site(L)::vec> centers + = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes()); + for_all_ncomponents(i, text.nbboxes()) { unsigned midcol = (text.bbox(i).pmax().col() - text.bbox(i).pmin().col()) / 2; int dmax = midcol + neighb_max_distance; - mln_site(L) c = text.bbox(i).center(); + mln_site(L) c = centers[i]; /// - /// Find a neighbor on the left + /// Find a neighbor on the right /// - - ///FIXME: the following code is not generic... - /// First site on the left of the central site - mln_site(L) p = c + left; - - const L& lbl = text.label_image(); - while (lbl.domain().has(p) && (lbl(p) == literal::zero - || lbl(p) == i || right_link[i] == lbl(p)) - && math::abs(p.col() - c.col()) < dmax) - --p.col(); - - internal::update_link_array(lbl, right_link, p, c, i, dmax); + internal::find_right_link(text, right_link, i, dmax, c); } trace::exiting("scribo::text::grouping::group_with_single_right_link"); diff --git a/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh b/milena/sandbox/scribo/text/grouping/internal/find_left_graph_link.hh similarity index 58% copy from milena/sandbox/scribo/text/grouping/internal/update_link_array.hh copy to milena/sandbox/scribo/text/grouping/internal/find_left_graph_link.hh index 501d6f2..4055ea1 100644 --- a/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh +++ b/milena/sandbox/scribo/text/grouping/internal/find_left_graph_link.hh @@ -26,19 +26,24 @@ // reasons why the executable file might be covered by the GNU General // Public License. +#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_GRAPH_LINK_HH +# define SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_GRAPH_LINK_HH -#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_LINK_ARRAY_HH -# define SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_LINK_ARRAY_HH - -/// \file scribo/text/grouping/internal/update_link_array.hh +/// \file scribo/text/grouping/internal/find_left_graph_link.hh +/// /// -/// Update a lookup table if a neighbor is found on the right of -/// the current bbox. - # include <mln/core/concept/image.hh> + +# include <mln/math/abs.hh> + # include <mln/util/array.hh> +# include <scribo/util/text.hh> +# include <scribo/text/grouping/internal/update_link_graph.hh> + +//FIXME: not generic. +# include <mln/core/alias/dpoint2d.hh> namespace scribo { @@ -52,35 +57,38 @@ namespace scribo namespace internal { - /// Update the lookup table \p link_array if a neighbor is found - /// on the right of the current bbox. - template <typename I> + template <typename L> void - 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); + find_left_graph_link(const scribo::util::text<L>& text, + mln::util::array<unsigned>& left_link, + unsigned current_comp, + int dmax, + const mln_site(L)& c); # ifndef MLN_INCLUDE_ONLY - template <typename I> - inline + template <typename L> void - 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) + find_left_graph_link(mln::util::graph& g, + const scribo::util::text<L>& text, + unsigned current_comp, + int dmax, + const mln_site(L)& c) { - const I& lbl = exact(lbl_); + ///FIXME: the following code is not generic... + /// First site on the right of the central site + mln_site(L) p = c + left; - mlc_is_a(mln_value(I), mln::value::Symbolic)::check(); - mln_assertion(lbl.is_valid()); + const L& lbl = text.label_image(); + while (lbl.domain().has(p) && (lbl(p) == literal::zero + || lbl(p) == current_comp) + && math::abs(p.col() - c.col()) < dmax) + --p.col(); - if (lbl.domain().has(p) && lbl(p) != literal::zero && lbl(p) != i - && (math::abs(p.col() - c.col())) < dmax && link_array[lbl(p)] == lbl(p) - && link_array[i] != lbl(p)) - link_array[lbl(p)] = i; + update_link_graph(lbl, g, p, c, current_comp, dmax); } -# endif // ! MLN_INCLUDE_ONLY +# endif // MLN_INCLUDE_ONLY } // end of namespace scribo::text::grouping::internal @@ -91,4 +99,4 @@ namespace scribo } // end of namespace scribo -#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_LINK_ARRAY_HH +#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_GRAPH_LINK_HH diff --git a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh b/milena/sandbox/scribo/text/grouping/internal/find_left_link.hh similarity index 52% copy from milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh copy to milena/sandbox/scribo/text/grouping/internal/find_left_link.hh index 236cf16..4695012 100644 --- a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh +++ b/milena/sandbox/scribo/text/grouping/internal/find_left_link.hh @@ -26,13 +26,12 @@ // reasons why the executable file might be covered by the GNU General // Public License. +#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_LINK_HH +# define SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_LINK_HH -#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH -# define SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH - -/// \file scribo/text/grouping/group_with_multiple_links.hh +/// \file scribo/text/grouping/internal/find_left_link.hh +/// /// -/// Group character bounding boxes with multiple links. # include <mln/core/concept/image.hh> @@ -40,10 +39,11 @@ # include <mln/util/array.hh> -# include <scribo/core/macros.hh> -# include <scribo/text/grouping/internal/init_link_array.hh> -# include <scribo/text/grouping/internal/update_link_graph.hh> # include <scribo/util/text.hh> +# include <scribo/text/grouping/internal/update_link_array.hh> + +//FIXME: not generic. +# include <mln/core/alias/dpoint2d.hh> namespace scribo { @@ -54,48 +54,52 @@ namespace scribo namespace grouping { - /// Group character bounding boxes with multiple links. - /// Look up for neighbors on the left of each box. - template <typename I> - mln::util::graph - group_with_multiple_links(const scribo::util::text<I>& text, - unsigned neighb_max_distance); - -# ifndef MLN_INCLUDE_ONLY - - template <typename I> - inline - mln::util::graph - group_with_multiple_links(const scribo::util::text<I>& text, - unsigned neighb_max_distance) + namespace internal { - trace::entering("scribo::text::grouping::group_with_multiple_links"); - mln::util::graph g(text.nbboxes().next()); + template <typename L> + void + find_left_link(const scribo::util::text<L>& text, + mln::util::array<unsigned>& left_link, + unsigned current_comp, + int dmax, + const mln_site(L)& c); - for_all_ncomponents(i, text.nbboxes()) - { - unsigned midcol = (text.bbox(i).pmax().col() - - text.bbox(i).pmin().col()) / 2; - int dmax = midcol + neighb_max_distance; - mln_site(I) c = text.bbox(i).center(); +# ifndef MLN_INCLUDE_ONLY + template <typename L> + void + find_left_link(const scribo::util::text<L>& text, + mln::util::array<unsigned>& left_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 - mln_site(I) p = c + right; - - const I& lbl = text.label_image(); - while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i) - && math::abs(p.col() - c.col()) < dmax) - ++p.col(); - - internal::update_link_graph(lbl, g, p, c, i, dmax); + mln_site(L) p = c + left; + + /// Construct a new label image with the components bounding + /// boxes only. + /// TOO SLOW, so disabled!!! +// L lbl(text.label_image().domain()); +// for_all_components(i, text.bboxes()) +// mln::draw::box(lbl, text.bbox(i), i); + const L& lbl = text.label_image(); + + while (lbl.domain().has(p) // Not outside image domain + && (lbl(p) == literal::zero // Is the background + || lbl(p) == current_comp // Is the current component + || left_link[lbl(p)] == current_comp) // Creates a loop + && math::abs(p.col() - c.col()) < dmax) // Not to far + --p.col(); + + update_link_array(lbl, left_link, p, c, current_comp, dmax); } - trace::exiting("scribo::text::grouping::group_with_multiple_links"); - return g; - } +# endif // MLN_INCLUDE_ONLY -# endif // ! MLN_INCLUDE_ONLY + } // end of namespace scribo::text::grouping::internal } // end of namespace scribo::text::grouping @@ -103,4 +107,5 @@ namespace scribo } // end of namespace scribo -#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH + +#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_LINK_HH diff --git a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh b/milena/sandbox/scribo/text/grouping/internal/find_right_link.hh similarity index 52% copy from milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh copy to milena/sandbox/scribo/text/grouping/internal/find_right_link.hh index 236cf16..e83aa46 100644 --- a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh +++ b/milena/sandbox/scribo/text/grouping/internal/find_right_link.hh @@ -26,13 +26,12 @@ // reasons why the executable file might be covered by the GNU General // Public License. +#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_FIND_RIGHT_LINK_HH +# define SCRIBO_TEXT_GROUPING_INTERNAL_FIND_RIGHT_LINK_HH -#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH -# define SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH - -/// \file scribo/text/grouping/group_with_multiple_links.hh +/// \file scribo/text/grouping/internal/find_right_link.hh +/// /// -/// Group character bounding boxes with multiple links. # include <mln/core/concept/image.hh> @@ -40,10 +39,11 @@ # include <mln/util/array.hh> -# include <scribo/core/macros.hh> -# include <scribo/text/grouping/internal/init_link_array.hh> -# include <scribo/text/grouping/internal/update_link_graph.hh> # include <scribo/util/text.hh> +# include <scribo/text/grouping/internal/update_link_array.hh> + +//FIXME: not generic. +# include <mln/core/alias/dpoint2d.hh> namespace scribo { @@ -54,48 +54,52 @@ namespace scribo namespace grouping { - /// Group character bounding boxes with multiple links. - /// Look up for neighbors on the left of each box. - template <typename I> - mln::util::graph - group_with_multiple_links(const scribo::util::text<I>& text, - unsigned neighb_max_distance); - -# ifndef MLN_INCLUDE_ONLY - - template <typename I> - inline - mln::util::graph - group_with_multiple_links(const scribo::util::text<I>& text, - unsigned neighb_max_distance) + namespace internal { - trace::entering("scribo::text::grouping::group_with_multiple_links"); - mln::util::graph g(text.nbboxes().next()); + template <typename L> + void + find_right_link(const scribo::util::text<L>& text, + mln::util::array<unsigned>& right_link, + unsigned current_comp, + int dmax, + const mln_site(L)& c); - for_all_ncomponents(i, text.nbboxes()) - { - unsigned midcol = (text.bbox(i).pmax().col() - - text.bbox(i).pmin().col()) / 2; - int dmax = midcol + neighb_max_distance; - mln_site(I) c = text.bbox(i).center(); +# ifndef MLN_INCLUDE_ONLY + template <typename L> + void + find_right_link(const scribo::util::text<L>& text, + 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 - mln_site(I) p = c + right; - - const I& lbl = text.label_image(); - while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i) - && math::abs(p.col() - c.col()) < dmax) + mln_site(L) p = c + right; + + /// Construct a new label image with the components bounding + /// boxes only. + /// TOO SLOW, so disabled!!! +// L lbl(text.label_image().domain()); +// for_all_components(i, text.bboxes()) +// mln::draw::box(lbl, text.bbox(i), i); + const L& lbl = text.label_image(); + + while (lbl.domain().has(p) // Not outside image domain + && (lbl(p) == literal::zero // Is the background + || lbl(p) == current_comp // Is the current component + || right_link[lbl(p)] == current_comp) // Creates a loop + && math::abs(p.col() - c.col()) < dmax) // Not too far ++p.col(); - internal::update_link_graph(lbl, g, p, c, i, dmax); + update_link_array(lbl, right_link, p, c, current_comp, dmax); } - trace::exiting("scribo::text::grouping::group_with_multiple_links"); - return g; - } +# endif // MLN_INCLUDE_ONLY -# endif // ! MLN_INCLUDE_ONLY + } // end of namespace scribo::text::grouping::internal } // end of namespace scribo::text::grouping @@ -103,4 +107,5 @@ namespace scribo } // end of namespace scribo -#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH + +#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_FIND_RIGHT_LINK_HH diff --git a/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh b/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh index 501d6f2..1642d1a 100644 --- a/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh +++ b/milena/sandbox/scribo/text/grouping/internal/update_link_array.hh @@ -74,10 +74,12 @@ namespace scribo mlc_is_a(mln_value(I), mln::value::Symbolic)::check(); mln_assertion(lbl.is_valid()); - if (lbl.domain().has(p) && lbl(p) != literal::zero && lbl(p) != i - && (math::abs(p.col() - c.col())) < dmax && link_array[lbl(p)] == lbl(p) - && link_array[i] != lbl(p)) - link_array[lbl(p)] = i; + if (lbl.domain().has(p) // Not outside image domain + && lbl(p) != literal::zero // Not the background + && lbl(p) != i // Not the current component + && (math::abs(p.col() - c.col())) < dmax // Not too far + && link_array[lbl(p)] != i) // Not creating a loop + link_array[i] = lbl(p); } # endif // ! MLN_INCLUDE_ONLY -- 1.5.6.5