Olena-patches
Threads by month
- ----- 2025 -----
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
May 2011
- 9 participants
- 171 discussions

03 May '11
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Olena, a generic and efficient image processing platform".
The branch safe-groups has been created
at 397d9adad2d9d3854bb9f6b43fd3b0530af973e3 (commit)
- Log -----------------------------------------------------------------
397d9ad tests/unit_test/unit-tests.mk: Regen.
25b4393 Add a test for object_groups.
ff536c8 scribo/primitive/extract/separators_nonvisible.hh: Update use of object_groups and object_links.
6404315 Several improvements related to low-level data structures in XML output.
2fbfae8 scribo/toolchain/internal/content_in_doc_functor.hh: Make use of component::extract::alignments.
41e2055 Small fixes.
3f50eb7 scribo/primitive/extract/alignments.hh: Fix several bugs.
7e736d6 Improve object_groups and object_links API.
3ac6dd8 Add test data in EXTRA_DIST.
1bcc175 Add new tests for Sauvola algorithms.
78b8020 scribo/filter/object_groups_size_ratio.hh: Fix compilation.
d82fdf6 Rename few routines.
52a1107 Add more tests.
5b660b4 Small fixes in Scribo.
52f8110 Change test image format to pnm.
-----------------------------------------------------------------------
hooks/post-receive
--
Olena, a generic and efficient image processing platform
1
0

03 May '11
* tests/core/Makefile.am: New target.
* tests/core/object_groups.cc: New.
---
scribo/ChangeLog | 8 ++
scribo/tests/core/Makefile.am | 8 ++-
.../object_groups.cc} | 70 +++++++++++++-------
3 files changed, 60 insertions(+), 26 deletions(-)
copy scribo/tests/{filter/object_groups_small.cc => core/object_groups.cc} (50%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 9395d2b..f139bb6 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,13 @@
2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add a test for object_groups.
+
+ * tests/core/Makefile.am: New target.
+
+ * tests/core/object_groups.cc: New.
+
+2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
* scribo/primitive/extract/separators_nonvisible.hh: Update use of
object_groups and object_links.
diff --git a/scribo/tests/core/Makefile.am b/scribo/tests/core/Makefile.am
index 356cc31..c9af42d 100644
--- a/scribo/tests/core/Makefile.am
+++ b/scribo/tests/core/Makefile.am
@@ -1,5 +1,5 @@
-# Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-# (LRDE).
+# Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+# Laboratory (LRDE).
#
# This file is part of Olena.
#
@@ -20,8 +20,10 @@
include $(top_srcdir)/scribo/tests/tests.mk
-check_PROGRAMS = line_info
+check_PROGRAMS = line_info \
+ object_groups
line_info_SOURCES = line_info.cc
+object_groups_SOURCES = object_groups.cc
TESTS = $(check_PROGRAMS)
diff --git a/scribo/tests/filter/object_groups_small.cc b/scribo/tests/core/object_groups.cc
similarity index 50%
copy from scribo/tests/filter/object_groups_small.cc
copy to scribo/tests/core/object_groups.cc
index 9812b70..33e408f 100644
--- a/scribo/tests/filter/object_groups_small.cc
+++ b/scribo/tests/core/object_groups.cc
@@ -25,55 +25,79 @@
/// \file
-#include <iostream>
-
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/io/pbm/load.hh>
+
+#include <scribo/core/component_set.hh>
#include <scribo/core/def/lbl_type.hh>
+#include <scribo/core/object_links.hh>
+#include <scribo/core/object_groups.hh>
#include <scribo/primitive/extract/components.hh>
#include <scribo/primitive/link/with_single_left_link.hh>
-#include <scribo/primitive/group/from_single_link.hh>
-#include <scribo/filter/object_groups_small.hh>
#include "tests/data.hh"
-int main()
+int main(int argc, char *argv[])
{
- using namespace scribo;
using namespace mln;
+ using namespace scribo;
std::string img = SCRIBO_IMG_DIR "/the_valleys.pbm";
- const bool ref[] = { false, true, true, true, true };
- const bool filtered_ref[] = { false, false, true, false, false };
- const unsigned size_ref[] = { 0, 1, 7, 1, 3 };
-
+ static const int comp_to_group_ref[] = { 0, 1, 4, 2, 3, 2, 2, 4, 4, 2, 2, 2, 2 };
+ static const int pixel_area_ref[] = { 0, 3, 973, 39, 426 };
+ static const box2d bbox_ref[] = {
+ box2d(),
+ make::box2d(0,91, 1,92),
+ make::box2d(9,95, 45,224),
+ make::box2d(9,204, 20,209),
+ make::box2d(9,12, 36,64)
+ };
+
+ static const int comp_ids_count_ref[] = { 0, 1, 7, 1, 3 };
+ static const int comp_ids_ref[][7] = {
+ { 0, 0, 0, 0, 0, 0, 0 },
+ { 1, 0, 0, 0, 0, 0, 0 },
+ { 3, 9, 5, 6, 10, 11, 12 },
+ { 4, 0, 0, 0, 0, 0, 0 },
+ { 7, 2, 8, 0, 0, 0, 0 } };
image2d<bool> input;
io::pbm::load(input, img.c_str());
typedef scribo::def::lbl_type V;
+ V nlabels;
typedef image2d<V> L;
-
- V nbboxes;
component_set<L>
- text = primitive::extract::components(input, c8(), nbboxes);
- object_links<L> links = primitive::link::with_single_left_link(text, 30);
+ comps = scribo::primitive::extract::components(input, c8(), nlabels);
- object_groups<L> groups = primitive::group::from_single_link(links);
+ object_links<L> link
+ = primitive::link::with_single_left_link(comps, 30);
- mln_assertion(groups.nelements() == 5);
- for_all_groups(g, groups)
- mln_assertion(groups(g).is_valid() == ref[g]);
+ object_groups<L> group(link);
- object_groups<L> groups2 = filter::object_groups_small(groups, 4);
+ mln_assertion(group.nelements() == 5);
+ mln_assertion(group.comp_to_group().nelements() == 13);
- for_all_groups(g, groups2)
+ // Checking comp_to_group()
+ for (int i = 0; i < group.comp_to_group().nelements(); ++i)
+ mln_assertion(group.comp_to_group()[i] == comp_to_group_ref[i]);
+
+ // Checking group info data.
+ for_all_groups(g, group)
{
- mln_assertion(groups2(g).is_valid() == filtered_ref[g]);
- mln_assertion(groups2(g).card() == size_ref[g]);
+ mln_assertion(group(g).id() == g);
+ mln_assertion(group(g).is_valid());
+ mln_assertion(group(g).pixel_area() == pixel_area_ref[g]);
+ mln_assertion(group(g).bbox() == bbox_ref[g]);
+ mln_assertion(group(g).component_ids().nelements() == comp_ids_count_ref[g]);
+
+ for_all_elements(e, group(g).component_ids())
+ mln_assertion(group(g).component_ids()[e] == comp_ids_ref[g][e]);
}
-
+ // Checking group_of()
+ for_all_comps(c, comps)
+ mln_assertion(group.group_of(c).id() == comp_to_group_ref[c]);
}
--
1.5.6.5
1
0

03 May '11
---
scribo/ChangeLog | 4 ++++
scribo/tests/unit_test/unit-tests.mk | 16 ++++++++++++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index f139bb6..a6ef3f8 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,9 @@
2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ * tests/unit_test/unit-tests.mk: Regen.
+
+2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add a test for object_groups.
* tests/core/Makefile.am: New target.
diff --git a/scribo/tests/unit_test/unit-tests.mk b/scribo/tests/unit_test/unit-tests.mk
index c654084..309b482 100644
--- a/scribo/tests/unit_test/unit-tests.mk
+++ b/scribo/tests/unit_test/unit-tests.mk
@@ -38,6 +38,7 @@ check_PROGRAMS += \
scribo_convert_from_base64 \
scribo_convert_from_qimage \
scribo_io_xml_internal_full_xml_visitor \
+scribo_io_xml_internal_save_image_to_xml \
scribo_io_xml_load
scribo_convert_from_base64_CPPFLAGS= ${QT_CPPFLAGS} -DHAVE_QT ${AM_CPPFLAGS}
@@ -49,6 +50,9 @@ scribo_convert_from_qimage_SOURCES = scribo_convert_from_qimage.cc
scribo_io_xml_internal_full_xml_visitor_CPPFLAGS= ${QT_CPPFLAGS} -DHAVE_QT ${AM_CPPFLAGS}
scribo_io_xml_internal_full_xml_visitor_LDFLAGS= ${QT_LDFLAGS} ${AM_LDFLAGS}
scribo_io_xml_internal_full_xml_visitor_SOURCES = scribo_io_xml_internal_full_xml_visitor.cc
+scribo_io_xml_internal_save_image_to_xml_CPPFLAGS= ${QT_CPPFLAGS} -DHAVE_QT ${AM_CPPFLAGS}
+scribo_io_xml_internal_save_image_to_xml_LDFLAGS= ${QT_LDFLAGS} ${AM_LDFLAGS}
+scribo_io_xml_internal_save_image_to_xml_SOURCES = scribo_io_xml_internal_save_image_to_xml.cc
scribo_io_xml_load_CPPFLAGS= ${QT_CPPFLAGS} -DHAVE_QT ${AM_CPPFLAGS}
scribo_io_xml_load_LDFLAGS= ${QT_LDFLAGS} ${AM_LDFLAGS}
scribo_io_xml_load_SOURCES = scribo_io_xml_load.cc
@@ -117,8 +121,10 @@ scribo_core_def_color_type \
scribo_core_def_lbl_type \
scribo_core_document \
scribo_core_erase_objects \
+scribo_core_group_info \
scribo_core_init_integral_image \
scribo_core_internal_doc_serializer \
+scribo_core_internal_sort_comp_ids \
scribo_core_line_info \
scribo_core_line_links \
scribo_core_line_set \
@@ -158,16 +164,16 @@ scribo_estim_components_features \
scribo_estim_font_boldness \
scribo_estim_font_color \
scribo_estim_internal_compute_skeleton \
-scribo_estim_object_groups_v_thickness \
+scribo_estim_object_groups_mean_width \
scribo_filter_all \
scribo_filter_common_objects_photo \
scribo_filter_internal_alignment_angle \
scribo_filter_internal_component_aligned \
scribo_filter_internal_compute \
scribo_filter_line_links_x_height \
+scribo_filter_object_groups_mean_width \
scribo_filter_object_groups_size_ratio \
scribo_filter_object_groups_small \
-scribo_filter_object_groups_v_thickness \
scribo_filter_object_groups_with_holes \
scribo_filter_object_links_aligned \
scribo_filter_object_links_bbox_h_ratio \
@@ -361,8 +367,10 @@ scribo_core_def_color_type_SOURCES = scribo_core_def_color_type.cc
scribo_core_def_lbl_type_SOURCES = scribo_core_def_lbl_type.cc
scribo_core_document_SOURCES = scribo_core_document.cc
scribo_core_erase_objects_SOURCES = scribo_core_erase_objects.cc
+scribo_core_group_info_SOURCES = scribo_core_group_info.cc
scribo_core_init_integral_image_SOURCES = scribo_core_init_integral_image.cc
scribo_core_internal_doc_serializer_SOURCES = scribo_core_internal_doc_serializer.cc
+scribo_core_internal_sort_comp_ids_SOURCES = scribo_core_internal_sort_comp_ids.cc
scribo_core_line_info_SOURCES = scribo_core_line_info.cc
scribo_core_line_links_SOURCES = scribo_core_line_links.cc
scribo_core_line_set_SOURCES = scribo_core_line_set.cc
@@ -402,16 +410,16 @@ scribo_estim_components_features_SOURCES = scribo_estim_components_features.cc
scribo_estim_font_boldness_SOURCES = scribo_estim_font_boldness.cc
scribo_estim_font_color_SOURCES = scribo_estim_font_color.cc
scribo_estim_internal_compute_skeleton_SOURCES = scribo_estim_internal_compute_skeleton.cc
-scribo_estim_object_groups_v_thickness_SOURCES = scribo_estim_object_groups_v_thickness.cc
+scribo_estim_object_groups_mean_width_SOURCES = scribo_estim_object_groups_mean_width.cc
scribo_filter_all_SOURCES = scribo_filter_all.cc
scribo_filter_common_objects_photo_SOURCES = scribo_filter_common_objects_photo.cc
scribo_filter_internal_alignment_angle_SOURCES = scribo_filter_internal_alignment_angle.cc
scribo_filter_internal_component_aligned_SOURCES = scribo_filter_internal_component_aligned.cc
scribo_filter_internal_compute_SOURCES = scribo_filter_internal_compute.cc
scribo_filter_line_links_x_height_SOURCES = scribo_filter_line_links_x_height.cc
+scribo_filter_object_groups_mean_width_SOURCES = scribo_filter_object_groups_mean_width.cc
scribo_filter_object_groups_size_ratio_SOURCES = scribo_filter_object_groups_size_ratio.cc
scribo_filter_object_groups_small_SOURCES = scribo_filter_object_groups_small.cc
-scribo_filter_object_groups_v_thickness_SOURCES = scribo_filter_object_groups_v_thickness.cc
scribo_filter_object_groups_with_holes_SOURCES = scribo_filter_object_groups_with_holes.cc
scribo_filter_object_links_aligned_SOURCES = scribo_filter_object_links_aligned.cc
scribo_filter_object_links_bbox_h_ratio_SOURCES = scribo_filter_object_links_bbox_h_ratio.cc
--
1.5.6.5
1
0

last-svn-commit-850-gff536c8 scribo/primitive/extract/separators_nonvisible.hh: Update use of object_groups and object_links.
by Guillaume Lazzara 03 May '11
by Guillaume Lazzara 03 May '11
03 May '11
---
scribo/ChangeLog | 5 +
.../primitive/extract/separators_nonvisible.hh | 229 +++++---------------
2 files changed, 60 insertions(+), 174 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 350b536..9395d2b 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,10 @@
2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ * scribo/primitive/extract/separators_nonvisible.hh: Update use of
+ object_groups and object_links.
+
+2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Several improvements related to low-level data structures in XML
output.
diff --git a/scribo/scribo/primitive/extract/separators_nonvisible.hh b/scribo/scribo/primitive/extract/separators_nonvisible.hh
index c3e227c..5c26285 100644
--- a/scribo/scribo/primitive/extract/separators_nonvisible.hh
+++ b/scribo/scribo/primitive/extract/separators_nonvisible.hh
@@ -27,84 +27,56 @@
/// \file
///
/// \brief Find non visible separators (whitespaces)
-///
-/// \fixme To be cleaned up
+
#ifndef SCRIBO_PRIMITIVE_EXTRACT_SEPARATORS_NONVISIBLE_HH
# define SCRIBO_PRIMITIVE_EXTRACT_SEPARATORS_NONVISIBLE_HH
-#include <mln/core/concept/image.hh>
-#include <mln/core/image/dmorph/image_if.hh>
-#include <mln/pw/all.hh>
-
-#include <mln/draw/line.hh>
-
-#include <mln/data/wrap.hh>
-#include <mln/data/fill.hh>
-#include <mln/data/convert.hh>
-
+# include <mln/core/concept/image.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+# include <mln/pw/all.hh>
-#include <mln/labeling/colorize.hh>
-#include <mln/labeling/relabel.hh>
-#include <mln/labeling/blobs.hh>
+# include <mln/accu/count_value.hh>
-#include <mln/morpho/closing/structural.hh>
-#include <mln/morpho/closing/area.hh>
-#include <mln/morpho/opening/structural.hh>
-#include <mln/win/rectangle2d.hh>
-#include <mln/win/vline2d.hh>
+# include <mln/draw/line.hh>
-#include <mln/logical/not.hh>
-#include <mln/io/pbm/all.hh>
-#include <mln/io/pgm/all.hh>
-#include <mln/io/ppm/save.hh>
+# include <mln/data/fill.hh>
+# include <mln/data/convert.hh>
-#include <mln/literal/colors.hh>
+# include <mln/labeling/relabel.hh>
+# include <mln/labeling/value.hh>
-#include <mln/value/label_16.hh>
-#include <mln/value/int_u8.hh>
-#include <mln/value/int_u12.hh>
-#include <mln/value/int_u16.hh>
-#include <mln/value/rgb8.hh>
+# include <mln/morpho/closing/structural.hh>
-#include <mln/draw/box_plain.hh>
+# include <mln/literal/colors.hh>
-#include <mln/transform/influence_zone_geodesic.hh>
+# include <mln/value/label_16.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/value/rgb8.hh>
-#include <mln/data/stretch.hh>
+# include <mln/util/timer.hh>
-#include <mln/util/timer.hh>
+# include <scribo/core/object_groups.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/def/lbl_type.hh>
-#include <mln/norm/l1.hh>
+# include <scribo/debug/logger.hh>
-#include <scribo/debug/logger.hh>
-#include <scribo/core/object_groups.hh>
-#include <scribo/core/component_set.hh>
-#include <scribo/primitive/extract/components.hh>
+# include <scribo/filter/object_groups_small.hh>
+# include <scribo/filter/object_links_bottom_aligned.hh>
+# include <scribo/filter/object_links_top_aligned.hh>
-#include <scribo/primitive/extract/lines_h_pattern.hh>
-#include <scribo/primitive/remove/separators.hh>
+# include <scribo/preprocessing/rotate_90.hh>
-#include <scribo/preprocessing/denoise_fg.hh>
-#include <scribo/preprocessing/rotate_90.hh>
+# include <scribo/primitive/extract/components.hh>
-#include <scribo/primitive/link/internal/compute_anchor.hh>
+# include <scribo/primitive/link/internal/dmax_default.hh>
+# include <scribo/primitive/link/with_single_right_link_dmax_ratio_aligned.hh>
+# include <scribo/primitive/link/with_single_left_link_dmax_ratio_aligned.hh>
-#include <scribo/primitive/link/internal/dmax_default.hh>
+# include <scribo/primitive/group/from_double_link_any.hh>
-#include <scribo/primitive/link/with_single_right_link_dmax_ratio_aligned.hh>
-#include <scribo/primitive/link/with_single_left_link_dmax_ratio_aligned.hh>
-#include <scribo/primitive/group/from_double_link_any.hh>
-
-#include <scribo/filter/object_links_top_aligned.hh>
-#include <scribo/filter/object_groups_small.hh>
-#include <scribo/filter/object_links_bottom_aligned.hh>
-
-#include <scribo/core/def/lbl_type.hh>
-#include <scribo/core/line_set.hh>
-#include <scribo/text/extract_lines.hh>
-#include <mln/draw/box.hh>
namespace scribo
@@ -120,7 +92,8 @@ namespace scribo
using namespace scribo::debug;
- /// \brief Find non visible separators (whitespaces)
+ /// \brief Find non visible separators. Based on components
+ /// alignments.
//
template <typename I>
mln_concrete(I)
@@ -161,20 +134,9 @@ namespace scribo
// Closing structural - Connect characters.
t.start();
- // line_set<L> lines = text::extract_lines(in, c8());
-
- // mln_concrete(I) input_clo;
- // initialize(input_clo, in);
- // data::fill(input_clo, false);
-
- // for_all_lines(l, lines)
- // draw::box(input_clo, lines(l).bbox(), true);
-
win::hline2d vl(17);
mln_concrete(I) input_clo = morpho::closing::structural(in, vl);
-
-
float t_ = t;
std::cout << "closing_structural - " << t_ << std::endl;
@@ -320,23 +282,7 @@ namespace scribo
t_ = t;
std::cout << "small groups - " << t_ << std::endl;
-
// Compute group bboxes
- t.restart();
- util::array<accu::shape::bbox<point2d> >
- top_accu(top_groups.nelements()),
- bot_accu(bot_groups.nelements());
-
-
- for_all_groups(c, top_groups)
- {
- top_accu(top_groups(c)).take(components(c).bbox());
- bot_accu(bot_groups(c)).take(components(c).bbox());
- }
- t_ = t;
- std::cout << "groups to group bboxes - " << t_ << std::endl;
-
-
t.restart();
mln_concrete(I) separators;
@@ -350,26 +296,28 @@ namespace scribo
std::cout << "Initialize separators image - " << t_ << std::endl;
t.restart();
- for_all_comp_data(d, top_accu)
- {
- if (top_accu(d).is_valid())
+ for_all_groups(d, top_groups)
+ if (top_groups(d).is_valid())
{
mln::draw::line(separators,
- top_accu(d).to_result().pmin(),
- point2d(top_accu(d).to_result().pmin().row(),
- top_accu(d).to_result().pmax().col()),
+ top_groups(d).bbox().pmin(),
+ point2d(top_groups(d).bbox().pmin().row(),
+ top_groups(d).bbox().pmax().col()),
true);
}
- if (bot_accu(d).is_valid())
+
+
+ for_all_groups(d, bot_groups)
+ if (bot_groups(d).is_valid())
{
mln::draw::line(separators,
- point2d(bot_accu(d).to_result().pmax().row(),
- bot_accu(d).to_result().pmin().col()),
- bot_accu(d).to_result().pmax(),
+ point2d(bot_groups(d).bbox().pmax().row(),
+ bot_groups(d).bbox().pmin().col()),
+ bot_groups(d).bbox().pmax(),
true);
}
- }
+
t_ = t;
std::cout << "Drawing output image - " << t_ << std::endl;
@@ -379,94 +327,30 @@ namespace scribo
// Restore input orientation.
mln_concrete(I) input = scribo::preprocessing::rotate_90(in, false);
-
- // Debug group bboxes (includes all bboxes before filtering)
- util::array<accu::shape::bbox<point2d> >
- btop_accu(top_groups.nelements()),
- bbot_accu(bot_groups.nelements());
-
-
- for_all_groups(c, top_groups)
- {
- btop_accu(top_groups(c)).take(components(c).bbox());
- bbot_accu(bot_groups(c)).take(components(c).bbox());
- }
-
mln_ch_value(I, value::rgb8)
wo_filtering = data::convert(value::rgb8(), input);
- for_all_comp_data(d, btop_accu)
- {
- if (btop_accu(d).is_valid())
+ for_all_groups(d, top_groups)
+ if (top_groups(d).is_valid())
{
mln::draw::line(wo_filtering,
- btop_accu(d).to_result().pmin(),
- point2d(btop_accu(d).to_result().pmin().row(),
- btop_accu(d).to_result().pmax().col()),
+ top_groups(d).bbox().pmin(),
+ point2d(top_groups(d).bbox().pmin().row(),
+ top_groups(d).bbox().pmax().col()),
literal::green);
-
}
- }
- for_all_comp_data(d, bbot_accu)
- {
- if (bbot_accu(d).is_valid())
+ for_all_groups(d, bot_groups)
+ if (bot_groups(d).is_valid())
{
mln::draw::line(wo_filtering,
- point2d(bbot_accu(d).to_result().pmax().row(),
- bbot_accu(d).to_result().pmin().col()),
- bbot_accu(d).to_result().pmax(),
+ point2d(bot_groups(d).bbox().pmax().row(),
+ bot_groups(d).bbox().pmin().col()),
+ bot_groups(d).bbox().pmax(),
literal::green);
}
- }
- logger().log_image(AuxiliaryResults, wo_filtering, "wo_filtering");
- // mln_ch_value(I, value::rgb8) both = data::convert(value::rgb8(), input);
-
- // for_all_comp_data(d, top_accu)
- // {
- // if (top_accu(d).is_valid() || btop_accu(d).is_valid())
- // {
- // if (top_accu(d).is_valid())
- // {
- // mln::draw::line(both,
- // top_accu(d).to_result().pmin(),
- // point2d(top_accu(d).to_result().pmin().row(),
- // top_accu(d).to_result().pmax().col()),
- // literal::green);
- // }
- // else
- // if (btop_accu(d).is_valid())
- // mln::draw::line(both,
- // btop_accu(d).to_result().pmin(),
- // point2d(btop_accu(d).to_result().pmin().row(),
- // btop_accu(d).to_result().pmax().col()),
- // literal::yellow);
-
- // }
- // if (bot_accu(d).is_valid() || bbot_accu(d).is_valid())
- // {
- // if (bot_accu(d).is_valid())
- // {
- // mln::draw::line(both,
- // point2d(bot_accu(d).to_result().pmax().row(),
- // bot_accu(d).to_result().pmin().col()),
- // bot_accu(d).to_result().pmax(),
- // literal::green);
- // }
- // else
- // if (bbot_accu(d).is_valid())
- // mln::draw::line(both,
- // point2d(bbot_accu(d).to_result().pmax().row(),
- // bbot_accu(d).to_result().pmin().col()),
- // bbot_accu(d).to_result().pmax(),
- // literal::yellow);
- // }
-
- // }
-
- // logger().log_image(AuxiliaryResults,
- // both, "both");
+ logger().log_image(AuxiliaryResults, wo_filtering, "wo_filtering");
logger().log_image(AuxiliaryResults, separators, "separators");
}
@@ -500,9 +384,6 @@ namespace scribo
t_ = t;
std::cout << "* accu::transform_line - " << t_ << std::endl;
- // if (_debug_)
- // io::pgm::save(data::convert(value::int_u8(), tmp), "tmp.pgm");
-
t.restart();
value::int_u8 nlabels;
--
1.5.6.5
1
0

last-svn-commit-849-g6404315 Several improvements related to low-level data structures in XML output.
by Guillaume Lazzara 03 May '11
by Guillaume Lazzara 03 May '11
03 May '11
* scribo/core/component_features_data.hh,
* scribo/core/component_info.hh,
* scribo/core/component_set.hh,
* scribo/core/document.hh,
* scribo/core/line_links.hh,
* scribo/core/paragraph_info.hh,
* scribo/core/paragraph_set.hh: Add operator==().
* scribo/io/xml/internal/full_xml_visitor.hh: Save more data for
groups, separators and paragraphs.
* scribo/io/xml/internal/save_image_to_xml.hh: New.
* scribo/io/xml/load.hh: Load new saved data.
* tests/unit_test/cond_tests_qt: Add save_image_to_xml.hh.
---
scribo/ChangeLog | 22 +++
scribo/scribo/core/component_features_data.hh | 16 ++
scribo/scribo/core/component_info.hh | 17 ++
scribo/scribo/core/component_set.hh | 36 +++--
scribo/scribo/core/document.hh | 68 +++++++-
scribo/scribo/core/line_links.hh | 12 ++
scribo/scribo/core/paragraph_info.hh | 19 +++
scribo/scribo/core/paragraph_set.hh | 21 +++
scribo/scribo/io/xml/internal/full_xml_visitor.hh | 118 +++++++++------
...{print_image_coords.hh => save_image_to_xml.hh} | 70 +++++----
scribo/scribo/io/xml/load.hh | 164 ++++++++++++++++++--
scribo/tests/unit_test/cond_tests_qt | 1 +
12 files changed, 456 insertions(+), 108 deletions(-)
copy scribo/scribo/io/xml/internal/{print_image_coords.hh => save_image_to_xml.hh} (54%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 637fca8..350b536 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,27 @@
2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Several improvements related to low-level data structures in XML
+ output.
+
+ * scribo/core/component_features_data.hh,
+ * scribo/core/component_info.hh,
+ * scribo/core/component_set.hh,
+ * scribo/core/document.hh,
+ * scribo/core/line_links.hh,
+ * scribo/core/paragraph_info.hh,
+ * scribo/core/paragraph_set.hh: Add operator==().
+
+ * scribo/io/xml/internal/full_xml_visitor.hh: Save more data for
+ groups, separators and paragraphs.
+
+ * scribo/io/xml/internal/save_image_to_xml.hh: New.
+
+ * scribo/io/xml/load.hh: Load new saved data.
+
+ * tests/unit_test/cond_tests_qt: Add save_image_to_xml.hh.
+
+2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
* scribo/toolchain/internal/content_in_doc_functor.hh: Make use of
component::extract::alignments.
diff --git a/scribo/scribo/core/component_features_data.hh b/scribo/scribo/core/component_features_data.hh
index 07b3e4a..b0a4e47 100644
--- a/scribo/scribo/core/component_features_data.hh
+++ b/scribo/scribo/core/component_features_data.hh
@@ -49,9 +49,14 @@ namespace scribo
std::ostream&
operator<<(std::ostream& ostr, const component_features_data& data);
+ bool
+ operator==(const component_features_data& lhs,
+ const component_features_data& rhs);
+
# ifndef MLN_INCLUDE_ONLY
+ inline
component_features_data::component_features_data()
: valid(false)
{
@@ -69,6 +74,17 @@ namespace scribo
<< "]" << std::endl;
}
+
+ bool
+ operator==(const component_features_data& lhs,
+ const component_features_data& rhs)
+ {
+ return
+ lhs.valid == rhs.valid
+ && lhs.color == rhs.color
+ && lhs.boldness == rhs.boldness;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo
diff --git a/scribo/scribo/core/component_info.hh b/scribo/scribo/core/component_info.hh
index 164a242..1f94076 100644
--- a/scribo/scribo/core/component_info.hh
+++ b/scribo/scribo/core/component_info.hh
@@ -97,6 +97,9 @@ namespace scribo
std::ostream&
operator<<(std::ostream& ostr, const component_info& info);
+ bool
+ operator==(const component_info& lhs, const component_info& rhs);
+
# ifndef MLN_INCLUDE_ONLY
@@ -230,6 +233,20 @@ namespace scribo
<< ")" << std::endl;
}
+ inline
+ bool
+ operator==(const component_info& lhs, const component_info& rhs)
+ {
+
+ return
+ lhs.id() == rhs.id()
+ && lhs.bbox() == rhs.bbox()
+ && lhs.mass_center() == rhs.mass_center()
+ && lhs.card() == rhs.card()
+ && lhs.features() == rhs.features()
+ && lhs.tag() == rhs.tag()
+ && lhs.type() == rhs.type();
+ }
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/scribo/core/component_set.hh b/scribo/scribo/core/component_set.hh
index d729802..3587302 100644
--- a/scribo/scribo/core/component_set.hh
+++ b/scribo/scribo/core/component_set.hh
@@ -459,22 +459,6 @@ namespace scribo
return data_->infos_[id];
}
-// template <typename L>
-// inline
-// const component_info&
-// component_set<L>::operator()(const mln_value(L)& id) const
-// {
-// return data_->infos_[id];
-// }
-
-// template <typename L>
-// inline
-// component_info&
-// component_set<L>::operator()(const mln_value(L)& id)
-// {
-// return data_->infos_[id];
-// }
-
template <typename L>
inline
const component_info&
@@ -650,7 +634,25 @@ namespace scribo
bool
operator==(const component_set<L>& lhs, const component_set<L>& rhs)
{
- return lhs.id_() == rhs.id_();
+ if (! (lhs.labeled_image() == rhs.labeled_image()))
+ std::cout << "comp.lbl" << std::endl;
+
+ if (! (lhs.separators() == rhs.separators()))
+ std::cout << "comp.seps" << std::endl;
+
+ if (! (lhs.nelements() == rhs.nelements()
+ && lhs.labeled_image() == rhs.labeled_image()
+ && lhs.separators() == rhs.separators()))
+ return false;
+
+ for_all_comps(c, lhs)
+ if (! (lhs(c) == rhs(c)))
+ {
+ std::cout << "comp.info" << std::endl;
+ return false;
+ }
+
+ return true;
}
template <typename L>
diff --git a/scribo/scribo/core/document.hh b/scribo/scribo/core/document.hh
index f38b20b..e287c1d 100644
--- a/scribo/scribo/core/document.hh
+++ b/scribo/scribo/core/document.hh
@@ -88,19 +88,27 @@ namespace scribo
bool has_whitespace_seps() const;
const mln::image2d<bool>& whitespace_seps() const;
const component_set<L>& whitespace_seps_comps() const;
- void set_whitespace_separators(const image2d<bool>& whitespace_seps);
+ void set_whitespace_separators(const image2d<bool>& whitespace_seps,
+ const component_set<L>& whitespace_seps_comps);
// Horizontal separators
bool has_hline_seps() const;
const mln::image2d<bool>& hline_seps() const;
const component_set<L>& hline_seps_comps() const;
+ // Set vline separators image. The component is automatically computed.
void set_hline_separators(const image2d<bool>& line_seps);
+ void set_hline_separators(const image2d<bool>& line_seps,
+ const component_set<L>& hline_seps_comps);
// Vertical separators
bool has_vline_seps() const;
const mln::image2d<bool>& vline_seps() const;
const component_set<L>& vline_seps_comps() const;
- void set_vline_separators(const image2d<bool>& line_seps);
+
+ // Set vline separators image. The component is automatically computed.
+ void set_vline_separators(const image2d<bool>& vline_seps);
+ void set_vline_separators(const image2d<bool>& vline_seps,
+ const component_set<L>& vline_seps_comps);
const mln::image2d<value::rgb8>& image() const;
void set_image(const mln::image2d<value::rgb8>& image);
@@ -128,6 +136,9 @@ namespace scribo
};
+ template <typename L>
+ bool operator==(const document<L>& lhs, const document<L>& rhs);
+
# ifndef MLN_INCLUDE_ONLY
@@ -291,14 +302,11 @@ namespace scribo
template <typename L>
void
- document<L>::set_whitespace_separators(const image2d<bool>& whitespace_seps)
+ document<L>::set_whitespace_separators(const image2d<bool>& whitespace_seps,
+ const component_set<L>& whitespace_seps_comps)
{
whitespace_seps_ = whitespace_seps;
-
- mln_value(L) ncomps;
- whitespace_seps_comps_ = primitive::extract::components(whitespace_seps,
- mln::c8(), ncomps,
- component::WhitespaceSeparator);
+ whitespace_seps_comps_ = whitespace_seps_comps;
}
@@ -340,6 +348,16 @@ namespace scribo
template <typename L>
+ void
+ document<L>::set_hline_separators(const image2d<bool>& hline_seps,
+ const component_set<L>& hline_seps_comps)
+ {
+ hline_seps_ = hline_seps;
+ hline_seps_comps_ = hline_seps_comps;
+ }
+
+
+ template <typename L>
bool
document<L>::has_vline_seps() const
{
@@ -377,6 +395,16 @@ namespace scribo
template <typename L>
+ void
+ document<L>::set_vline_separators(const image2d<bool>& vline_seps,
+ const component_set<L>& vline_seps_comps)
+ {
+ vline_seps_ = vline_seps;
+ vline_seps_comps_ = vline_seps_comps;
+ }
+
+
+ template <typename L>
const mln::image2d<value::rgb8>&
document<L>::image() const
{
@@ -408,6 +436,30 @@ namespace scribo
}
+ template <typename L>
+ bool operator==(const document<L>& lhs, const document<L>& rhs)
+ {
+
+
+ return
+ lhs.filename() == rhs.filename()
+ && lhs.image() == rhs.image()
+ && lhs.binary_image() == rhs.binary_image()
+ && lhs.has_text() == rhs.has_text()
+ && lhs.paragraphs() == rhs.paragraphs()
+ && lhs.has_elements() == rhs.has_elements()
+ && lhs.elements() == rhs.elements()
+ && lhs.has_whitespace_seps() == rhs.has_whitespace_seps()
+ && lhs.whitespace_seps() == rhs.whitespace_seps()
+ && lhs.whitespace_seps_comps() == rhs.whitespace_seps_comps()
+ && lhs.has_hline_seps() == rhs.has_hline_seps()
+ && lhs.hline_seps() == rhs.hline_seps()
+ && lhs.hline_seps_comps() == rhs.hline_seps_comps()
+ && lhs.has_vline_seps() == rhs.has_vline_seps()
+ && lhs.vline_seps() == rhs.vline_seps()
+ && lhs.vline_seps_comps() == rhs.vline_seps_comps();
+ }
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/scribo/core/line_links.hh b/scribo/scribo/core/line_links.hh
index ab36a73..b7b438c 100644
--- a/scribo/scribo/core/line_links.hh
+++ b/scribo/scribo/core/line_links.hh
@@ -103,6 +103,10 @@ namespace scribo
std::ostream&
operator<<(std::ostream& ostr, const line_links<L>& links);
+ template <typename L>
+ bool
+ operator==(const line_links<L>& lhs, const line_links<L>& rhs);
+
# ifndef MLN_INCLUDE_ONLY
@@ -254,6 +258,14 @@ namespace scribo
}
+ template <typename L>
+ bool
+ operator==(const line_links<L>& lhs, const line_links<L>& rhs)
+ {
+ return lhs.lines() == rhs.lines()
+ && lhs.line_to_link() == rhs.line_to_link();
+ }
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/scribo/core/paragraph_info.hh b/scribo/scribo/core/paragraph_info.hh
index 557ded7..52068a7 100644
--- a/scribo/scribo/core/paragraph_info.hh
+++ b/scribo/scribo/core/paragraph_info.hh
@@ -89,6 +89,8 @@ namespace scribo
template <typename L>
std::ostream& operator<<(std::ostream& ostr, const paragraph_info<L>& info);
+ template <typename L>
+ bool operator==(const paragraph_info<L>& lhs, const paragraph_info<L>& rhs);
# ifndef MLN_INCLUDE_ONLY
@@ -248,6 +250,22 @@ namespace scribo
}
template <typename L>
+ bool
+ operator==(const paragraph_info<L>& lhs, const paragraph_info<L>& rhs)
+ {
+
+
+
+ return
+ lhs.line_ids() == rhs.line_ids()
+ && lhs.bbox() == rhs.bbox()
+ && lhs.llinks() == rhs.llinks()
+ && lhs.color() == rhs.color()
+ && lhs.color_reliability() == rhs.color_reliability()
+ && lhs.needs_stats_update() == rhs.needs_stats_update();
+ }
+
+ template <typename L>
std::ostream&
operator<<(std::ostream& ostr, const paragraph_info<L>& info)
{
@@ -259,6 +277,7 @@ namespace scribo
<< ")" << std::endl;
}
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo
diff --git a/scribo/scribo/core/paragraph_set.hh b/scribo/scribo/core/paragraph_set.hh
index ec9f51b..242501d 100644
--- a/scribo/scribo/core/paragraph_set.hh
+++ b/scribo/scribo/core/paragraph_set.hh
@@ -86,6 +86,8 @@ namespace scribo
};
+ template <typename L>
+ bool operator==(const paragraph_set<L>& lhs, const paragraph_set<L>& rhs);
namespace make
{
@@ -200,6 +202,25 @@ namespace scribo
}
+ template <typename L>
+ bool operator==(const paragraph_set<L>& lhs, const paragraph_set<L>& rhs)
+ {
+ if (! (lhs.lines() == rhs.lines() && lhs.nelements() == rhs.nelements()))
+ {
+ return false;
+ }
+
+ for_all_paragraphs(p, lhs)
+ if (!(lhs(p) == rhs(p)))
+ {
+ std::cout << "paragraph.info" << std::endl;
+ return false;
+ }
+
+ return true;
+ }
+
+
namespace make
{
diff --git a/scribo/scribo/io/xml/internal/full_xml_visitor.hh b/scribo/scribo/io/xml/internal/full_xml_visitor.hh
index bba7691..c294bbc 100644
--- a/scribo/scribo/io/xml/internal/full_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/full_xml_visitor.hh
@@ -43,13 +43,10 @@
# include <scribo/core/line_links.hh>
# include <scribo/core/line_info.hh>
+# include <scribo/io/xml/internal/save_image_to_xml.hh>
# include <scribo/io/xml/internal/print_box_coords.hh>
# include <scribo/io/xml/internal/print_page_preambule.hh>
-// Compression level 0-9. 9 is the best but is slow.
-// 5 seems to be a good compromise.
-# define COMPRESSION_LEVEL 5
-
namespace scribo
{
@@ -157,20 +154,46 @@ namespace scribo
if (doc.has_elements())
{
const component_set<L>& elts = doc.elements();
+
+ output << " <elements>" << std::endl;
+ elts.accept(*this);
+
for_all_comps(e, elts)
if (elts(e).is_valid())
elts(e).accept(*this);
+
+ output << " </elements>" << std::endl;
}
// line seraparators
if (doc.has_hline_seps())
+ {
+ output << " <hlines_separators>" << std::endl;
+ doc.hline_seps_comps().accept(*this);
+
for_all_comps(c, doc.hline_seps_comps())
doc.hline_seps_comps()(c).accept(*this);
+
+ save_image_to_xml(output, doc.hline_seps(),
+ "hlines_separators_image");
+
+ output << " </hlines_separators>" << std::endl;
+ }
if (doc.has_vline_seps())
+ {
+ output << " <vlines_separators>" << std::endl;
+ doc.vline_seps_comps().accept(*this);
+
for_all_comps(c, doc.vline_seps_comps())
doc.vline_seps_comps()(c).accept(*this);
+ save_image_to_xml(output, doc.vline_seps(),
+ "vlines_separators_image");
+
+ output << " </vlines_separators>" << std::endl;
+ }
+
// Whitespace seraparators
if (doc.has_whitespace_seps())
@@ -178,8 +201,16 @@ namespace scribo
const component_set<L>&
whitespace_seps_comps = doc.whitespace_seps_comps();
+ output << " <whitespaces_delimitors>" << std::endl;
+ whitespace_seps_comps.accept(*this);
+
for_all_comps(c, whitespace_seps_comps)
whitespace_seps_comps(c).accept(*this);
+
+ save_image_to_xml(output, doc.whitespace_seps(),
+ "whitespaces_delimitors_image");
+
+ output << " </whitespaces_delimitors>" << std::endl;
}
output << " </page>" << std::endl;
@@ -212,13 +243,26 @@ namespace scribo
void
full_xml_visitor::visit(const object_groups<L>& groups) const
{
- output << " <object_groups>" << std::endl;
+ output << " <object_groups ngroups=\"" << groups.nelements()
+ << "\">" << std::endl;
+
for_all_groups(g, groups)
{
- output << " <group "
- << " object_id=\"" << g
- << "\" group_id=\"" << groups(g)
- << "\"/>" << std::endl;
+ output << " <group id=\"" << groups(g).id()
+ << "\" valid=\"" << groups(g).is_valid()
+ << "\" pixel_area=\"" << groups(g).pixel_area()
+ << "\" pmin_x=\"" << groups(g).bbox().pmin().row()
+ << "\" pmin_y=\"" << groups(g).bbox().pmin().col()
+ << "\" pmax_x=\"" << groups(g).bbox().pmax().row()
+ << "\" pmax_y=\"" << groups(g).bbox().pmax().col()
+ << "\">" << std::endl;
+
+ for_all_elements(e, groups(g).component_ids())
+ output << " <group_member comp_id=\""
+ << groups(g).component_ids()(e)
+ << "\"/>" << std::endl;
+
+ output << " </group>" << std::endl;
}
output << " </object_groups>" << std::endl;
}
@@ -263,51 +307,36 @@ namespace scribo
<< "\" pmin_x=\"" << comp_set(c).bbox().pmin().col()
<< "\" pmin_y=\"" << comp_set(c).bbox().pmin().row()
<< "\" pmax_x=\"" << comp_set(c).bbox().pmax().col()
- << "\" pmax_y=\"" << comp_set(c).bbox().pmax().row()
- << "\"/>" << std::endl;
+ << "\" pmax_y=\"" << comp_set(c).bbox().pmax().row();
+
+ if (comp_set(c).has_features())
+ {
+ output << "\">" << std::endl;
+
+ output << " <component_features"
+ << " valid=\"" << comp_set(c).features().valid
+ << "\" color=\"" << comp_set(c).features().color
+ << "\" boldness=\"" << comp_set(c).features().boldness
+ << "\"/>" << std::endl;
+
+ output << " </component_info>" << std::endl;
+ }
+ else
+ output << "\"/>" << std::endl;
}
// Save labeled image
{
const L& lbl = comp_set.labeled_image();
- output << "<labeled_image "
- << " height=\"" << lbl.domain().height()
- << "\" width=\"" << lbl.domain().width() << "\">"
- << "<![CDATA[";
-
- // FIXME: Try to avoid that!
- border::resize(lbl, 0);
- QByteArray
- lbl64 = QByteArray::fromRawData((const char *)lbl.buffer(),
- lbl.nelements() * sizeof(mln_value(L)));
- lbl64 = qCompress(lbl64, COMPRESSION_LEVEL);
- lbl64 = lbl64.toBase64();
-
- output.write(lbl64.data(), lbl64.size());
-
- output << "]]></labeled_image>" << std::endl;
+ save_image_to_xml(output, lbl, "labeled_image");
}
// Save separators image
if (comp_set.has_separators())
{
const mln_ch_value(L,bool)& seps = comp_set.separators();
- output << "<separators_image "
- << " height=\"" << seps.domain().height()
- << "\" width=\"" << seps.domain().width() << "\">"
- << "<![CDATA[";
-
- border::resize(seps, 0);
- QByteArray
- seps64 = QByteArray::fromRawData((const char *)seps.buffer(),
- seps.nelements() * sizeof(bool));
- seps64 = qCompress(seps64, COMPRESSION_LEVEL);
- seps64 = seps64.toBase64();
-
- output.write(seps64.data(), seps64.size());
-
- output << "]]></separators_image>" << std::endl;
+ save_image_to_xml(output, seps, "separators_image");
}
output << "</component_set>" << std::endl;
@@ -394,7 +423,9 @@ namespace scribo
<< "\" x_height=\"" << lines(fid).x_height()
<< "\" d_height=\"" << lines(fid).d_height()
<< "\" a_height=\"" << lines(fid).a_height()
- << "\" char_width=\"" << lines(fid).char_width();
+ << "\" char_width=\"" << lines(fid).char_width()
+ << "\" color=\"" << parset(p).color()
+ << "\" color_reliability=\"" << parset(p).color_reliability();
// End of EXTENSIONS
output << "\">"
<< std::endl;
@@ -469,6 +500,5 @@ namespace scribo
} // end of namespace scribo
-# undef COMPRESSION_LEVEL
#endif // SCRIBO_IO_XML_INTERNAL_FULL_XML_VISITOR_HH
diff --git a/scribo/scribo/io/xml/internal/print_image_coords.hh b/scribo/scribo/io/xml/internal/save_image_to_xml.hh
similarity index 54%
copy from scribo/scribo/io/xml/internal/print_image_coords.hh
copy to scribo/scribo/io/xml/internal/save_image_to_xml.hh
index ebfe402..3f38337 100644
--- a/scribo/scribo/io/xml/internal/print_image_coords.hh
+++ b/scribo/scribo/io/xml/internal/save_image_to_xml.hh
@@ -23,15 +23,24 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
-# define SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
+#ifndef SCRIBO_IO_XML_INTERNAL_SAVE_IMAGE_TO_XML_HH
+# define SCRIBO_IO_XML_INTERNAL_SAVE_IMAGE_TO_XML_HH
/// \file
///
-/// \brief Prints box2d coordinates to XML data.
+/// Save an image as XML data.
-# include <fstream>
-# include <mln/core/concept/site_set.hh>
+# include <iostream>
+
+# include <QtXml>
+
+# include <mln/core/concept/image.hh>
+# include <mln/border/resize.hh>
+
+
+// Compression level 0-9. 9 is the best but is slow.
+// 5 seems to be a good compromise.
+# define COMPRESSION_LEVEL 5
namespace scribo
{
@@ -44,42 +53,43 @@ namespace scribo
namespace internal
{
-
using namespace mln;
- /*! \brief Prints box2d coordinates to XML data.
- */
- template <typename S>
+ template <typename I>
void
- print_image_coords(std::ofstream& ostr, const mln::Site_Set<S>& b,
- const char *space);
-
+ save_image_to_xml(std::ostream& output, const Image<I>& ima,
+ const char *qname);
# ifndef MLN_INCLUDE_ONLY
-
- template <typename S>
+ template <typename I>
void
- print_image_coords(std::ofstream& ostr, const mln::Site_Set<S>& b_,
- const char *space)
+ save_image_to_xml(std::ostream& output, const Image<I>& ima_,
+ const char *qname)
{
- std::string sc = space;
- std::string sp = sc + " ";
+ trace::entering("scribo::io::xml::internal::save_image");
- const S& b = exact(b_);
- mln_precondition(b.is_valid());
+ mln_precondition(exact(ima_).is_valid());
+ const I& ima = exact(ima_);
- ostr << sc << "<coords>" << std::endl;
+ output << "<" << qname
+ << " height=\"" << ima.domain().height()
+ << "\" width=\"" << ima.domain().width() << "\">"
+ << "<![CDATA[";
- mln_piter(S) p(b);
- for_all(p)
- ostr << sp << "<point x=\"" << p.col()
- << "\" y=\"" << p.row() << "\"/>"
- << std::endl;
+ mln::border::resize(ima, 0);
+ QByteArray
+ seps64 = QByteArray::fromRawData((const char *)ima.buffer(),
+ ima.nelements() * sizeof(mln_value(I)));
+ seps64 = qCompress(seps64, COMPRESSION_LEVEL);
+ seps64 = seps64.toBase64();
- ostr << sc << "</coords>" << std::endl;
- }
+ output.write(seps64.data(), seps64.size());
+ output << "]]></" << qname << ">" << std::endl;
+
+ trace::exiting("scribo::io::xml::internal::save_image");
+ }
# endif // ! MLN_INCLUDE_ONLY
@@ -91,4 +101,6 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_IMAGE_COORDS_HH
+# undef COMPRESSION_LEVEL
+
+#endif // ! SCRIBO_IO_XML_INTERNAL_SAVE_IMAGE_TO_XML_HH
diff --git a/scribo/scribo/io/xml/load.hh b/scribo/scribo/io/xml/load.hh
index 8042c75..8d89085 100644
--- a/scribo/scribo/io/xml/load.hh
+++ b/scribo/scribo/io/xml/load.hh
@@ -88,6 +88,8 @@ namespace scribo
None,
ComponentSet,
ComponentInfo,
+ ComponentFeatures,
+ Elements,
LabeledImage,
SeparatorsImage,
ObjectLinks,
@@ -95,6 +97,7 @@ namespace scribo
Point,
Link,
Group,
+ GroupMember,
Line,
LineLinks,
LineLink,
@@ -102,7 +105,13 @@ namespace scribo
TextRegion,
CompIdList,
CompId,
- Page
+ Page,
+ WhitespacesDelimitors,
+ HLineSeparators,
+ VLineSeparators,
+ WhitespacesDelimitorsImage,
+ HLineSeparatorsImage,
+ VLineSeparatorsImage,
};
@@ -116,6 +125,8 @@ namespace scribo
static const ModeData mode_data[] = {
{ "component_set", ComponentSet },
{ "component_info", ComponentInfo },
+ { "component_features", ComponentFeatures },
+ { "elements", Elements },
{ "labeled_image", LabeledImage },
{ "separators_image", SeparatorsImage },
{ "object_links", ObjectLinks },
@@ -123,6 +134,7 @@ namespace scribo
{ "point", Point },
{ "link", Link },
{ "group", Group },
+ { "group_member", GroupMember },
{ "line", Line },
{ "line_links", LineLinks },
{ "line_link", LineLink },
@@ -131,10 +143,34 @@ namespace scribo
{ "compid_list", CompIdList },
{ "compid", CompId },
{ "page", Page },
+ { "whitespaces_delimitors", WhitespacesDelimitors },
+ { "hlines_separators", HLineSeparators },
+ { "vlines_separators", VLineSeparators },
+ { "whitespaces_delimitors_image", WhitespacesDelimitorsImage },
+ { "hlines_separators_image", HLineSeparatorsImage },
+ { "vlines_separators_image", VLineSeparatorsImage },
{ 0, None }
};
+ namespace internal
+ {
+
+ value::rgb8 parse_color(const QString& color_str)
+ {
+ QString color = color_str;
+ color.chop(1);
+ color = color.remove(0, 1);
+ QStringList rgb = color.split(',');
+
+ return
+ value::rgb8(rgb.at(0).toInt(),
+ rgb.at(1).toInt(),
+ rgb.at(2).toInt());
+ }
+
+ }
+
template <typename L>
class xml_handler : public QXmlDefaultHandler
{
@@ -142,7 +178,8 @@ namespace scribo
typedef mln_ch_value(L,bool) B;
public:
- xml_handler() : current_paragraph_id(1) { lines_data.append(line_info<L>()); } // line info id starts from 1.
+ xml_handler(document<L>& doc_) : current_paragraph_id(1), doc(doc_)
+ { lines_data.append(line_info<L>()); } // line info id starts from 1.
virtual
bool
@@ -185,6 +222,20 @@ namespace scribo
break;
+ case ComponentFeatures:
+ {
+ if (atts.value("valid").toInt())
+ {
+ component_features_data comp_features;
+ comp_features.valid = true;
+ comp_features.color = internal::parse_color(atts.value("color"));
+ comp_features.boldness = atts.value("boldness").toFloat();
+
+ comp_set_data->infos_.last().update_features(comp_features);
+ }
+ }
+ break;
+
// Object links
case ObjectLinks:
{
@@ -197,8 +248,9 @@ namespace scribo
// Object groups
case ObjectGroups:
{
- // qDebug() << "object_groups created";
- groups = object_groups<L>(links);
+ //qDebug() << "Processing object_groups";
+ group_info_.reserve(atts.value("ngroups").toInt());
+ group_info_.resize(1);
}
break;
@@ -225,6 +277,8 @@ namespace scribo
// qDebug() << "TextRegion";
current_paragraph = paragraph_info<L>(llinks);
+ current_paragraph.set_color_(internal::parse_color(atts.value("color")));
+ current_paragraph.set_color_reliability_(atts.value("color_reliability").toFloat());
}
break;
@@ -257,6 +311,7 @@ namespace scribo
line_data->a_height_ = atts.value("a_height").toInt();
line_data->char_space_ = atts.value("kerning").toInt();
line_data->char_width_ = atts.value("char_width").toInt();
+ line_data->char_width_ = atts.value("char_width").toInt();
line_data->word_space_ = 0;
line_data->reading_direction_ = line::LeftToRight;
@@ -266,6 +321,13 @@ namespace scribo
line_data->reading_orientation_ = atts.value("txt_reading_orientation").toInt();
line_data->indented_ = (atts.value("txt_indented") == "false" ? false : true);
+
+ line_data->boldness_ = atts.value("boldness").toFloat();
+ line_data->boldness_reliability_ = atts.value("boldness_reliability").toFloat();
+ line_data->color_ = internal::parse_color(atts.value("color"));
+
+ line_data->color_reliability_ = atts.value("color_reliability").toFloat();
+
bbox.init();
}
break;
@@ -282,7 +344,7 @@ namespace scribo
// CompId
case CompId:
{
- line_data->components_.append(atts.value("value").toInt());
+ line_data->component_ids_.append(atts.value("value").toInt());
}
break;
@@ -316,10 +378,21 @@ namespace scribo
break;
+ // Separators/delimitor images
+ case WhitespacesDelimitorsImage:
+ case HLineSeparatorsImage:
+ case VLineSeparatorsImage:
+ {
+ width = atts.value("width").toInt();
+ height = atts.value("height").toInt();
+ seps = B(mln::make::box2d(height, width), 0); // No border
+ }
+ break;
+
// Link
case Link:
{
- links(atts.value("from").toInt()) = atts.value("to").toInt();
+ links.update(atts.value("from").toInt(), atts.value("to").toInt());
}
break;
@@ -327,7 +400,20 @@ namespace scribo
// Group
case Group:
{
- groups(atts.value("object_id").toInt()) = atts.value("group_id").toInt();
+ group_info_.append(group_info(atts.value("id").toInt(),
+ atts.value("pixel_area").toInt(),
+ mln::make::box2d(atts.value("pmin_x").toInt(),
+ atts.value("pmin_y").toInt(),
+ atts.value("pmax_x").toInt(),
+ atts.value("pmax_y").toInt()),
+ atts.value("valid").toInt()));
+ }
+ break;
+
+ // GroupMember
+ case GroupMember:
+ {
+ component_ids.append(atts.value("comp_id").toInt());
}
break;
@@ -352,6 +438,7 @@ namespace scribo
{
// qDebug() << "Component set done";
components = component_set<L>(comp_set_data);
+
}
break;
@@ -382,6 +469,46 @@ namespace scribo
// qDebug() << "Page done";
lines.update_line_data_(lines_data);
parset = paragraph_set<L>(par_data);
+ doc.set_paragraphs(parset);
+ }
+ break;
+
+ // ObjectGroups
+ case ObjectGroups:
+ {
+ groups = object_groups<L>(links, group_info_);
+ }
+ break;
+
+ // Group
+ case Group:
+ {
+ group_info_.last().component_ids_() = component_ids;
+ component_ids.clear();
+ }
+ break;
+
+ case Elements:
+ {
+ doc.set_elements(components);
+ }
+ break;
+
+ case WhitespacesDelimitors:
+ {
+ doc.set_whitespace_separators(seps, components);
+ }
+ break;
+
+ case HLineSeparators:
+ {
+ doc.set_hline_separators(seps, components);
+ }
+ break;
+
+ case VLineSeparators:
+ {
+ doc.set_vline_separators(seps, components);
}
break;
@@ -419,6 +546,17 @@ namespace scribo
}
break;
+ case WhitespacesDelimitorsImage:
+ case HLineSeparatorsImage:
+ case VLineSeparatorsImage:
+ {
+ QByteArray data = ch.toAscii();
+ data = QByteArray::fromBase64(data);
+ data = qUncompress(data);
+ memcpy((char *) seps.buffer(), data.data(), data.size());
+ }
+ break;
+
default:
;
}
@@ -453,7 +591,10 @@ namespace scribo
component_set<L> components;
object_links<L> links;
+
object_groups<L> groups;
+ mln::util::array<component_id_t> component_ids;
+ mln::util::array<group_info> group_info_;
// Lines
unsigned current_line_id;
@@ -468,6 +609,11 @@ namespace scribo
mln::util::array<line_info<L> > lines_data;
line_set<L> lines;
+
+ // Delimitors/separators
+ B seps; // Temporary image.
+
+ document<L>& doc;
};
@@ -484,7 +630,7 @@ namespace scribo
load_extended(document<L>& doc,
const std::string& output_name)
{
- xml_handler<L> handler;
+ xml_handler<L> handler(doc);
QXmlSimpleReader reader;
reader.setContentHandler(&handler);
@@ -498,8 +644,6 @@ namespace scribo
QXmlInputSource xmlInputSource(&file);
if (reader.parse(xmlInputSource))
qDebug() << "Loaded successfuly";
-
- doc.set_paragraphs(handler.parset);
}
} // end of namespace scribo::io::xml::internal
diff --git a/scribo/tests/unit_test/cond_tests_qt b/scribo/tests/unit_test/cond_tests_qt
index f7bc42e..4f4b667 100644
--- a/scribo/tests/unit_test/cond_tests_qt
+++ b/scribo/tests/unit_test/cond_tests_qt
@@ -1,4 +1,5 @@
scribo/convert/from_base64.hh
scribo/convert/from_qimage.hh
scribo/io/xml/internal/full_xml_visitor.hh
+scribo/io/xml/internal/save_image_to_xml.hh
scribo/io/xml/load.hh
--
1.5.6.5
1
0

last-svn-commit-848-g2fbfae8 scribo/toolchain/internal/content_in_doc_functor.hh: Make use of component::extract::alignments.
by Guillaume Lazzara 03 May '11
by Guillaume Lazzara 03 May '11
03 May '11
---
scribo/ChangeLog | 10 +++-
.../toolchain/internal/content_in_doc_functor.hh | 54 +++++++++++---------
2 files changed, 37 insertions(+), 27 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 570a3c1..637fca8 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,10 @@
2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ * scribo/toolchain/internal/content_in_doc_functor.hh: Make use of
+ component::extract::alignments.
+
+2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Small fixes.
* scribo/core/paragraph_info.hh: Add color information.
@@ -10,8 +15,9 @@
* scribo/make/text_components_image.hh: Fix wrong domain inclusions.
- * scribo/toolchain/text_in_picture.hh: Make use of
- component::extract::alignments.
+ * scribo/toolchain/text_in_picture.hh: Fix wrong include.
+
+ * src/debug/show_paragraph_blocks.cc: Add missing curly brackets.
2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
diff --git a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
index 0a920a6..25b328b 100644
--- a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
+++ b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
@@ -37,7 +37,8 @@
# include <scribo/primitive/extract/separators.hh>
# include <scribo/primitive/extract/vertical_separators.hh>
# include <scribo/primitive/extract/horizontal_separators.hh>
-# include <scribo/primitive/extract/separators_nonvisible.hh>
+
+# include <scribo/primitive/extract/alignments.hh>
# include <scribo/primitive/identify.hh>
@@ -197,24 +198,8 @@ namespace scribo
on_progress();
}
- mln_ch_value(I,bool) whitespaces;
- if (enable_whitespace_seps)
- {
- // Whitespace separators
- on_new_progress_label("Find whitespace separators...");
-
- whitespaces = primitive::extract::separators_nonvisible(input_cleaned);
-
- on_progress();
- }
-
- // Debug
# ifndef SCRIBO_NDEBUG
- if (enable_whitespace_seps)
- debug::logger().log_image(debug::AuxiliaryResults,
- whitespaces, "whitespaces");
-
// Debug
if (enable_line_seps)
{
@@ -264,11 +249,6 @@ namespace scribo
/// Set separator components.
if (enable_line_seps)
components.add_separators(separators);
- if (enable_whitespace_seps)
- {
- components.add_separators(whitespaces);
- doc.set_whitespace_separators(whitespaces);
- }
// Debug
# ifndef SCRIBO_NDEBUG
@@ -291,13 +271,14 @@ namespace scribo
object_links<L> left_link
= primitive::link::with_single_left_link_dmax_ratio(
components,
- primitive::link::internal::dmax_width_and_height(1),
+ primitive::link::internal::dmax_default(1),
anchor::MassCenter);
+
object_links<L> right_link
= primitive::link::with_single_right_link_dmax_ratio(
components,
- primitive::link::internal::dmax_width_and_height(1),
+ primitive::link::internal::dmax_default(1),
anchor::MassCenter);
// Debug
@@ -318,7 +299,6 @@ namespace scribo
}
# endif // ! SCRIBO_NDEBUG
-
// Validating left and right links.
object_links<L>
merged_links = primitive::link::merge_double_link(left_link,
@@ -364,10 +344,34 @@ namespace scribo
lines = scribo::make::line_set(groups);
+ // Extract whitespace to improve text merging results afterwards.
+ mln_ch_value(L,bool) whitespaces;
+ if (enable_whitespace_seps)
+ {
+ scribo::paragraph_set<L> parset = scribo::make::paragraph(lines);
+ doc.set_paragraphs(parset);
+
+ // Whitespace separators
+ on_new_progress_label("Find whitespace separators...");
+
+ mln::util::couple<component_set<L>, mln_ch_value(L,bool)>
+ res = primitive::extract::alignments(doc, 3, 3);
+ whitespaces = res.second();
+
+ on_progress();
+
+ components.add_separators(res.second());
+ doc.set_whitespace_separators(res.second(), res.first());
+ }
+
+
//===== DEBUG =====
# ifndef SCRIBO_NDEBUG
if (debug::logger().is_enabled())
{
+ if (enable_whitespace_seps)
+ debug::logger().log_image(debug::AuxiliaryResults,
+ whitespaces, "whitespaces");
// Bboxes image.
debug::logger().log_image(
--
1.5.6.5
1
0
* scribo/core/paragraph_info.hh: Add color information.
* scribo/debug/bboxes_image.hh: Reindent.
* scribo/draw/bounding_box_links.hh: Update use of is_link_valid.
* scribo/make/text_components_image.hh: Fix wrong domain inclusions.
* scribo/toolchain/text_in_picture.hh: Fix wrong include.
* src/debug/show_paragraph_blocks.cc: Add missing curly brackets.
---
scribo/ChangeLog | 15 +++++++++++++++
scribo/scribo/core/paragraph_info.hh | 27 +++++++++++++++++++++++++++
scribo/scribo/debug/bboxes_image.hh | 18 +++++++++---------
scribo/scribo/draw/bounding_box_links.hh | 16 ++++++----------
scribo/scribo/make/text_components_image.hh | 8 +++++---
scribo/scribo/toolchain/text_in_picture.hh | 10 +++++-----
scribo/src/debug/show_paragraph_blocks.cc | 2 ++
7 files changed, 69 insertions(+), 27 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 8a76ac6..570a3c1 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,20 @@
2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Small fixes.
+
+ * scribo/core/paragraph_info.hh: Add color information.
+
+ * scribo/debug/bboxes_image.hh: Reindent.
+
+ * scribo/draw/bounding_box_links.hh: Update use of is_link_valid.
+
+ * scribo/make/text_components_image.hh: Fix wrong domain inclusions.
+
+ * scribo/toolchain/text_in_picture.hh: Make use of
+ component::extract::alignments.
+
+2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
* scribo/primitive/extract/alignments.hh: Fix several bugs.
2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
diff --git a/scribo/scribo/core/paragraph_info.hh b/scribo/scribo/core/paragraph_info.hh
index 2a9b626..557ded7 100644
--- a/scribo/scribo/core/paragraph_info.hh
+++ b/scribo/scribo/core/paragraph_info.hh
@@ -61,10 +61,14 @@ namespace scribo
unsigned nlines() const;
+ const line_links<L>& llinks() const;
+
// FIXME: add boldness?
const mln::value::rgb8& color() const;
+ void set_color_(const mln::value::rgb8& v);
float color_reliability() const;
+ void set_color_reliability_(float v);
bool is_valid() const;
@@ -82,6 +86,9 @@ namespace scribo
bool needs_stats_update_;
};
+ template <typename L>
+ std::ostream& operator<<(std::ostream& ostr, const paragraph_info<L>& info);
+
# ifndef MLN_INCLUDE_ONLY
@@ -139,12 +146,25 @@ namespace scribo
}
template <typename L>
+ const line_links<L>&
+ paragraph_info<L>::llinks() const
+ {
+ return llinks_;
+ }
+
+ template <typename L>
const mln::value::rgb8&
paragraph_info<L>::color() const
{
return color_;
}
+ template <typename L>
+ void
+ paragraph_info<L>::set_color_(const mln::value::rgb8& v)
+ {
+ color_ = v;
+ }
template <typename L>
float
@@ -154,6 +174,13 @@ namespace scribo
}
template <typename L>
+ void
+ paragraph_info<L>::set_color_reliability_(float v)
+ {
+ color_reliability_ = v;
+ }
+
+ template <typename L>
bool
paragraph_info<L>::is_valid() const
{
diff --git a/scribo/scribo/debug/bboxes_image.hh b/scribo/scribo/debug/bboxes_image.hh
index ca3d646..d3dc64b 100644
--- a/scribo/scribo/debug/bboxes_image.hh
+++ b/scribo/scribo/debug/bboxes_image.hh
@@ -55,15 +55,15 @@ namespace scribo
template <typename I>
mln_ch_value(I, value::rgb8)
bboxes_image(const Image<I>& input,
- const mln::util::array< box<mln_site(I)> >& bboxes,
- const value::rgb8& value);
+ const mln::util::array< box<mln_site(I)> >& bboxes,
+ const value::rgb8& value);
template <typename I, typename L>
mln_ch_value(I, value::rgb8)
bboxes_image(const Image<I>& input,
- const line_set<L>& lines,
- const value::rgb8& value);
+ const line_set<L>& lines,
+ const value::rgb8& value);
/// \overload
/// value is set to literal::red.
@@ -72,15 +72,15 @@ namespace scribo
inline
mln_ch_value(I, value::rgb8)
bboxes_image(const Image<I>& input,
- const line_set<L>& lines);
+ const line_set<L>& lines);
/// \overload.
template <typename I, typename L>
inline
mln_ch_value(I, value::rgb8)
bboxes_image(const Image<I>& input,
- const component_set<L>& comps,
- const value::rgb8& value);
+ const component_set<L>& comps,
+ const value::rgb8& value);
# ifndef MLN_INCLUDE_ONLY
@@ -106,8 +106,8 @@ namespace scribo
inline
mln_ch_value(I, value::rgb8)
bboxes_image(const Image<I>& input,
- const line_set<L>& lines,
- const value::rgb8& value)
+ const line_set<L>& lines,
+ const value::rgb8& value)
{
trace::entering("scribo::debug::bboxes_image");
mln_precondition(exact(input).is_valid());
diff --git a/scribo/scribo/draw/bounding_box_links.hh b/scribo/scribo/draw/bounding_box_links.hh
index f2c9804..830da25 100644
--- a/scribo/scribo/draw/bounding_box_links.hh
+++ b/scribo/scribo/draw/bounding_box_links.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -294,15 +294,11 @@ namespace scribo
right_link_value);
- mln::util::couple<bool, unsigned>
- nbh = primitive::internal::is_link_valid(left_link,
- right_link,
- i);
-
- if (nbh.first())
+ if (primitive::internal::is_link_valid(left_link,
+ right_link, i))
mln::draw::line(input,
- primitive::link::internal::compute_anchor(comps, right_link(i), anchor),
- primitive::link::internal::compute_anchor(comps, nbh.second(), anchor),
+ primitive::link::internal::compute_anchor(comps, i, anchor),
+ primitive::link::internal::compute_anchor(comps, left_link(i), anchor),
validated_link_value);
}
diff --git a/scribo/scribo/make/text_components_image.hh b/scribo/scribo/make/text_components_image.hh
index e7c892e..522505e 100644
--- a/scribo/scribo/make/text_components_image.hh
+++ b/scribo/scribo/make/text_components_image.hh
@@ -80,9 +80,11 @@ namespace scribo
comp_ids = lines(l).component_ids();
const L& lbl = lines.components().labeled_image();
for_all_elements(c, comp_ids)
- data::fill((output | lines.components()(comp_ids(c)).bbox()).rw(),
- ((doc.binary_image() | lines.components()(comp_ids(c)).bbox())
- | (pw::value(lbl) == comp_ids(c))));
+ {
+ data::fill(((output | lines.components()(comp_ids(c)).bbox()).rw()
+ | (pw::value(lbl) == comp_ids(c))).rw(),
+ (doc.binary_image() | lines.components()(comp_ids(c)).bbox()));
+ }
}
}
diff --git a/scribo/scribo/toolchain/text_in_picture.hh b/scribo/scribo/toolchain/text_in_picture.hh
index 42e69db..6f87b9d 100644
--- a/scribo/scribo/toolchain/text_in_picture.hh
+++ b/scribo/scribo/toolchain/text_in_picture.hh
@@ -71,7 +71,7 @@
# include <scribo/filter/object_links_bbox_overlap.hh>
# include <scribo/filter/object_groups_small.hh>
-# include <scribo/filter/object_groups_v_thickness.hh>
+# include <scribo/filter/object_groups_mean_width.hh>
# include <scribo/debug/decision_image.hh>
# include <scribo/debug/linked_bboxes_image.hh>
@@ -138,7 +138,7 @@ namespace scribo
bbox_h_ratio = 1.60f;
bbox_overlap = 0.80f;
small_groups = 3;
- v_thickness = 8;
+ mean_width = 8;
regroup_dmax = 30;
group_min_holes = 3;
}
@@ -154,7 +154,7 @@ namespace scribo
float bbox_h_ratio;
float bbox_overlap;
unsigned small_groups;
- unsigned v_thickness;
+ unsigned mean_width;
unsigned regroup_dmax;
unsigned group_min_holes;
};
@@ -469,8 +469,8 @@ namespace scribo
object_groups<L> filtered_thin_groups;
std::cout << "** Using group too thin" << std::endl;
filtered_thin_groups
- = filter::object_groups_v_thickness(filtered_small_groups,
- conf.v_thickness);
+ = filter::object_groups_mean_width(filtered_small_groups,
+ conf.mean_width);
t_ = g_timer;
std::cout << "Groups too thin " << t_ << std::endl;
diff --git a/scribo/src/debug/show_paragraph_blocks.cc b/scribo/src/debug/show_paragraph_blocks.cc
index b16a751..e99c2ec 100644
--- a/scribo/src/debug/show_paragraph_blocks.cc
+++ b/scribo/src/debug/show_paragraph_blocks.cc
@@ -109,6 +109,7 @@ int main(int argc, char* argv[])
const line_info<L>& line = parset.lines()(parset(p).line_ids()(l));
if (last_box.is_valid())
+ {
if (last_box.pmax().row() < line.bbox().pmin().row())
{
last_tbox = last_box;
@@ -167,6 +168,7 @@ int main(int argc, char* argv[])
// mln::io::pgm::save(log, mln::debug::filename("log.pgm", i++));
}
}
+ }
mln::draw::box_plain(blocks, line.bbox(), true);
// mln::draw::box_plain(log, line.bbox(), 255);
--
1.5.6.5
1
0

last-svn-commit-846-g3f50eb7 scribo/primitive/extract/alignments.hh: Fix several bugs.
by Guillaume Lazzara 03 May '11
by Guillaume Lazzara 03 May '11
03 May '11
---
scribo/ChangeLog | 6 +-
scribo/scribo/primitive/extract/alignments.hh | 444 +++++++++++++------------
2 files changed, 229 insertions(+), 221 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 7bbfb9e..8a76ac6 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,4 +1,8 @@
-2011-05-03 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ * scribo/primitive/extract/alignments.hh: Fix several bugs.
+
+2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
Improve object_groups and object_links API.
diff --git a/scribo/scribo/primitive/extract/alignments.hh b/scribo/scribo/primitive/extract/alignments.hh
index 4bd925e..8d18d93 100644
--- a/scribo/scribo/primitive/extract/alignments.hh
+++ b/scribo/scribo/primitive/extract/alignments.hh
@@ -26,57 +26,54 @@
#ifndef SCRIBO_PRIMITIVE_EXTRACT_ALIGNMENTS_HH
# define SCRIBO_PRIMITIVE_EXTRACT_ALIGNMENTS_HH
-#include <iostream>
+# include <iostream>
-#include <mln/core/image/image2d.hh>
-#include <mln/core/alias/neighb2d.hh>
+# include <mln/core/image/image2d.hh>
+# include <mln/core/alias/neighb2d.hh>
-#include <mln/data/convert.hh>
+# include <mln/data/convert.hh>
-#include <mln/value/rgb8.hh>
-#include <mln/value/label_16.hh>
-#include <mln/value/int_u.hh>
-#include <mln/literal/colors.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/value/label_16.hh>
+# include <mln/value/int_u.hh>
+# include <mln/literal/colors.hh>
-#include <mln/util/array.hh>
-#include <mln/util/couple.hh>
+# include <mln/util/array.hh>
+# include <mln/util/couple.hh>
-#include <mln/io/pbm/load.hh>
-#include <mln/io/ppm/save.hh>
+# include <mln/io/pbm/load.hh>
-#include <mln/labeling/colorize.hh>
+# include <mln/labeling/colorize.hh>
-#include <mln/util/couple.hh>
+# include <mln/util/couple.hh>
-#include <scribo/core/def/lbl_type.hh>
-#include <scribo/primitive/extract/components.hh>
-#include <scribo/filter/object_links_aligned.hh>
-#include <scribo/filter/object_groups_small.hh>
-#include <scribo/preprocessing/denoise_fg.hh>
-// #include <scribo/primitive/link/with_single_right_link_dmax_ratio_aligned.hh>
-// #include <scribo/primitive/link/with_single_left_link_dmax_ratio_aligned.hh>
-#include <scribo/primitive/link/internal/link_single_dmax_ratio_aligned_delta_base.hh>
-#include <scribo/primitive/link/internal/dmax_default.hh>
-#include <scribo/primitive/link/internal/dmax_hrules.hh>
-#include <scribo/primitive/link/merge_double_link_closest_aligned.hh>
+# include <scribo/core/def/lbl_type.hh>
+# include <scribo/primitive/extract/components.hh>
+# include <scribo/filter/object_links_aligned.hh>
+# include <scribo/filter/object_groups_small.hh>
+# include <scribo/preprocessing/denoise_fg.hh>
+# include <scribo/primitive/link/internal/link_single_dmax_ratio_aligned_delta_base.hh>
+# include <scribo/primitive/link/internal/dmax_default.hh>
+# include <scribo/primitive/link/internal/dmax_hrules.hh>
+# include <scribo/primitive/link/merge_double_link_closest_aligned.hh>
-#include <scribo/debug/usage.hh>
-#include <scribo/debug/links_image.hh>
+# include <scribo/debug/usage.hh>
+# include <scribo/debug/links_image.hh>
-#include <scribo/core/document.hh>
-#include <scribo/core/component_set.hh>
-#include <scribo/core/line_set.hh>
-#include <scribo/primitive/extract/components.hh>
-#include <scribo/primitive/group/from_single_link.hh>
-#include <scribo/primitive/group/apply.hh>
-#include <scribo/primitive/link/with_single_left_link_dmax_ratio.hh>
-#include <scribo/primitive/link/with_single_right_link_dmax_ratio.hh>
-#include <scribo/primitive/link/merge_double_link.hh>
-#include <scribo/primitive/link/internal/dmax_width_and_height.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/line_set.hh>
+# include <scribo/primitive/extract/components.hh>
+# include <scribo/primitive/group/from_single_link.hh>
+# include <scribo/primitive/group/apply.hh>
+# include <scribo/primitive/link/with_single_left_link_dmax_ratio.hh>
+# include <scribo/primitive/link/with_single_right_link_dmax_ratio.hh>
+# include <scribo/primitive/link/merge_double_link.hh>
+# include <scribo/primitive/link/internal/dmax_width_and_height.hh>
-#include <scribo/preprocessing/rotate_90.hh>
-#include <scribo/filter/object_links_bbox_h_ratio.hh>
+# include <scribo/preprocessing/rotate_90.hh>
+# include <scribo/filter/object_links_bbox_h_ratio.hh>
# include <scribo/primitive/extract/separators.hh>
# include <scribo/primitive/extract/vertical_separators.hh>
@@ -442,7 +439,7 @@ namespace scribo
}
-
+ inline
bool
is_valid_left_right_skewed_delimitor(const box2d& brot,
const image2d<bool> input,
@@ -469,6 +466,8 @@ namespace scribo
return false;
}
+
+ inline
bool
is_valid_right_left_skewed_delimitor(const box2d& brot,
const image2d<bool> input,
@@ -496,6 +495,7 @@ namespace scribo
}
+ inline
box2d fast_rotate_positive(const box2d& box, const box2d& rbox)
{
box2d b(point2d(box.pmin().col(),
@@ -505,25 +505,12 @@ namespace scribo
return b;
}
+
+ inline
box2d fast_rotate_negative(const box2d& box, const box2d& rbox)
{
- // std::cout << point2d(rbox.ncols() - box.pmin().col() - 1,
- // box.pmin().row())
- // << " - "
- // << point2d(rbox.ncols() - box.pmax().col() - 1,
- // box.pmax().row()) << std::endl;
-
- // std::cout << box << " - " << rbox << std::endl;
-
- // box2d b(point2d(rbox.ncols() - box.pmin().col() - 1,
- // box.pmin().row()),
- // point2d(rbox.ncols() - box.pmax().col() - 1,
- // box.pmax().row()));
-
mln::def::coord max_row = rbox.ncols() - box.pmin().col() - 1;
mln::def::coord min_row = rbox.ncols() - box.pmax().col() - 1;
-// if (min_row > max_row)
- //std::swap(min_row, max_row);
box2d b(point2d(min_row,
box.pmin().row()),
@@ -533,6 +520,26 @@ namespace scribo
return b;
}
+
+ inline
+ unsigned
+ compute_reliable_ldelta(const value::int_u12& char_width,
+ const value::int_u12& char_space)
+ {
+ return 1.2 * char_width + char_space;
+ }
+
+
+ inline
+ unsigned
+ compute_unreliable_ldelta(const value::int_u12& max_char_width)
+ {
+ return max_char_width * 2; // FIXME: reduce to 1.5 ? Problem
+ // with 2 or 3 lines besides an
+ // image.
+ }
+
+
} // end of namespace scribo::primitive::extract
@@ -579,8 +586,7 @@ namespace scribo
mln::draw::box(bbox_ima,
internal::fast_rotate_positive(lines(l).bbox(),
rbbox),
- lines(l).id().value());
-
+ l);
// Compute component information
//
@@ -613,12 +619,7 @@ namespace scribo
// 2.1. BEGIN OF TOP LINKS PROCESSING
{
object_links<L> top_links;
-
- object_groups<L>
- top_groups,
- old_top_groups;
-
- util::array<unsigned> top_group_size;
+ object_groups<L> top_groups;
typedef mln::accu::stat::median_h<value::int_u<12u> > median_t;
mln::util::array<median_t>
@@ -656,9 +657,8 @@ namespace scribo
anchor::StrictTopCenter);
// Remove groups with not enough links.
- old_top_groups = primitive::group::from_single_link(top_links);
- top_groups = filter::object_groups_small(old_top_groups, min_card,
- top_group_size);
+ top_groups = primitive::group::from_single_link(top_links);
+ top_groups = filter::object_groups_small(top_groups, min_card);
// Compute char_width and char_space statistics.
@@ -674,17 +674,18 @@ namespace scribo
top_max_char_width.resize(top_groups.nelements());
for_all_groups(g, top_groups)
- if (top_groups.is_valid(g))
- {
- if (lines(g).card() > 1)
+ if (top_groups(g).is_valid())
+ for_all_elements(e, top_groups(g).component_ids())
{
- top_median_char_space(top_groups(g)).take(lines(g).char_space());
- top_median_char_width(top_groups(g)).take(lines(g).char_width());
+ unsigned l = top_groups(g).component_ids()(e);
+ if (lines(l).card() > 1)
+ {
+ top_median_char_space(g).take(lines(l).char_space());
+ top_median_char_width(g).take(lines(l).char_width());
+ }
+ else if (top_max_char_width(g) < lines(l).char_width())
+ top_max_char_width(g) = lines(l).char_width();
}
- else if (top_max_char_width(top_groups(g)) < lines(g).char_width())
- top_max_char_width(top_groups(g)) = lines(g).char_width();
- }
-
}
@@ -694,103 +695,104 @@ namespace scribo
group_bbox(top_groups.nelements());
// Compute group bboxes
- for_all_links(l, top_links)
- if (top_links.is_valid(l))
- {
- point2d p = components(top_links(l)).bbox().pmax();
- p.row() = components(top_links(l)).bbox().pmin().row();
+ for_all_groups(g, top_groups)
+ for_all_elements(e, top_groups(g).component_ids())
+ {
+ unsigned l = top_groups(g).component_ids()(e);
+ point2d p = components(top_links(l)).bbox().pmax();
+ p.row() = components(top_links(l)).bbox().pmin().row();
- if (top_groups.is_valid(l)
- && top_group_size(old_top_groups(l)) > 2)
- {
- group_bbox(top_groups(l)).take(p);
- group_bbox(top_groups(l)).take(components(l).bbox().pmin());
+ if (top_groups(g).is_valid())// && top_links.is_linked(l))
+ {
+ group_bbox(g).take(p);
+ group_bbox(g).take(components(l).bbox().pmin());
# ifndef SCRIBO_NDEBUG
- // Draw first component bbox.
- mln::draw::box(debug,
- internal::fast_rotate_positive(
- groups.components()(lines(l).component_ids()[0]).bbox(),
- rbbox),
- literal::cyan);
-
- mln::draw::box(debug,
- internal::fast_rotate_positive(
- groups.components()(lines(top_links(l)).component_ids()[0]).bbox(),
- rbbox),
- literal::cyan);
+ // Draw first component bbox.
+ mln::draw::box(debug,
+ internal::fast_rotate_positive(
+ groups.components()(lines(l).component_ids()[0]).bbox(),
+ rbbox),
+ literal::cyan);
+
+ mln::draw::box(debug,
+ internal::fast_rotate_positive(
+ groups.components()(lines(top_links(l)).component_ids()[0]).bbox(),
+ rbbox),
+ literal::cyan);
# endif // ! SCRIBO_NDEBUG
- }
-
+ }
# ifndef SCRIBO_NDEBUG
- else if (top_group_size(old_top_groups(l)) > 1)
- {
- mln::draw::line(debug,
- components(l).bbox().pmin(),
- p,
- literal::orange);
-
- // Draw first component bbox.
- mln::draw::box(debug,
- internal::fast_rotate_positive(
- groups.components()(lines(l).component_ids()[0]).bbox(),
- rbbox),
- literal::cyan);
-
- mln::draw::box(debug,
- internal::fast_rotate_positive(
- groups.components()(lines(top_links(l)).component_ids()[0]).bbox(),
- rbbox),
- literal::cyan);
-
- }
+ else if (top_groups(g).card() > 1)
+ {
+ mln::draw::line(debug,
+ components(l).bbox().pmin(),
+ p,
+ literal::orange);
+
+ // Draw first component bbox.
+ mln::draw::box(debug,
+ internal::fast_rotate_positive(
+ groups.components()(lines(l).component_ids()[0]).bbox(),
+ rbbox),
+ literal::cyan);
+
+ mln::draw::box(debug,
+ internal::fast_rotate_positive(
+ groups.components()(lines(top_links(l)).component_ids()[0]).bbox(),
+ rbbox),
+ literal::cyan);
+ }
# endif // ! SCRIBO_NDEBUG
- }
-
+ }
// Looking for whitespaces (if needed)
- for_all_elements(c, group_bbox)
- if (group_bbox(c).to_result().is_valid())
+ for_all_groups(g, top_groups)
+ if (top_groups(g).is_valid())
{
unsigned ldelta = delta;
- // Handle low connection groups.
- if (top_group_size(c) >= 3 && top_group_size(c) < 5)
+
+ // Special case : handle low connected groups.
+ if (top_groups(g).card() >= 3 && top_groups(g).card() < 5)
{
// Stats are not reliable, prefer using max char width.
- if (top_median_char_width(c).card() == 0)
- ldelta = top_max_char_width(c) * 2;
+ if (top_median_char_width(g).card() == 0)
+ ldelta = internal::compute_unreliable_ldelta(top_max_char_width(g));
else
- ldelta = 1.2 * top_median_char_width(c) + top_median_char_space(c);
+ ldelta = internal::compute_reliable_ldelta(top_median_char_width(g),
+ top_median_char_space(g));
+
+ point2d p(group_bbox(g).to_result().pmin().row() - ldelta,
+ group_bbox(g).to_result().pmin().col());
- point2d p(group_bbox(c).to_result().pmin().row() - ldelta,
- group_bbox(c).to_result().pmin().col());
p = scribo::internal::point_row_adjust(p, bbox_ima);
// Checking whitespace area
- for (; p.col() <= group_bbox(c).to_result().pmax().col()
+ for (; p.col() <= group_bbox(g).to_result().pmax().col()
&& (bbox_ima(p) == 0);)
++p.col();
if (bbox_ima(p) != 0)
{
+ top_groups(g).invalidate();
+
# ifndef SCRIBO_NDEBUG
mln::draw::line(debug,
scribo::internal::point_row_adjust(
- point2d(group_bbox(c).to_result().pmin().row() - ldelta,
- group_bbox(c).to_result().pmin().col()), debug),
+ point2d(group_bbox(g).to_result().pmin().row() - ldelta,
+ group_bbox(g).to_result().pmin().col()), debug),
scribo::internal::point_row_adjust(
- point2d(group_bbox(c).to_result().pmin().row() - ldelta,
- group_bbox(c).to_result().pmax().col()), debug),
+ point2d(group_bbox(g).to_result().pmin().row() - ldelta,
+ group_bbox(g).to_result().pmax().col()), debug),
literal::red);
# endif // ! SCRIBO_NDEBUG
-
continue;
}
}
box2d
- brot = internal::fast_rotate_negative(group_bbox(c).to_result(),
+ brot = internal::fast_rotate_negative(group_bbox(g).to_result(),
rbbox);
// Checking if the delimitor is skewed.
@@ -821,24 +823,25 @@ namespace scribo
else
{
mln::draw::line(delimitors,
- scribo::internal::point_col_adjust(point2d(brot.pmin().row(),
- brot.pmin().col() - delta), delimitors),
- scribo::internal::point_col_adjust(point2d(brot.pmax().row(),
- brot.pmin().col() - delta), delimitors),
+ scribo::internal::point_col_adjust(
+ point2d(brot.pmin().row(),
+ brot.pmin().col() - delta), delimitors),
+ scribo::internal::point_col_adjust(
+ point2d(brot.pmax().row(),
+ brot.pmin().col() - delta), delimitors),
true);
}
# ifndef SCRIBO_NDEBUG
mln::draw::line(debug,
scribo::internal::point_row_adjust(
- point2d(group_bbox(c).to_result().pmin().row() - ldelta,
- group_bbox(c).to_result().pmin().col()), debug),
+ point2d(group_bbox(g).to_result().pmin().row() - ldelta,
+ group_bbox(g).to_result().pmin().col()), debug),
scribo::internal::point_row_adjust(
- point2d(group_bbox(c).to_result().pmin().row() - ldelta,
- group_bbox(c).to_result().pmax().col()), debug),
+ point2d(group_bbox(g).to_result().pmin().row() - ldelta,
+ group_bbox(g).to_result().pmax().col()), debug),
literal::green);
# endif // ! SCRIBO_NDEBUG
-
}
}
@@ -849,12 +852,7 @@ namespace scribo
// 2.2. BEGIN OF BOTTOM LINKS PROCESSING
{
object_links<L> bot_links;
-
- object_groups<L>
- bot_groups,
- old_bot_groups;
-
- util::array<unsigned> bot_group_size;
+ object_groups<L> bot_groups;
typedef mln::accu::stat::median_h<value::int_u<12u> > median_t;
mln::util::array<median_t>
@@ -892,27 +890,30 @@ namespace scribo
anchor::StrictBottomCenter);
// Remove groups with not enough links.
- old_bot_groups = primitive::group::from_single_link(bot_links);
- bot_groups = filter::object_groups_small(old_bot_groups, min_card,
- bot_group_size);
+ bot_groups = primitive::group::from_single_link(bot_links);
+
+ bot_groups = filter::object_groups_small(bot_groups, min_card);
bot_median_char_space.resize(bot_groups.nelements());
bot_median_char_width.resize(bot_groups.nelements());
bot_max_char_width.resize(bot_groups.nelements());
for_all_groups(g, bot_groups)
- if (bot_groups.is_valid(g))
- {
- if (lines(g).card() > 1)
+ if (bot_groups(g).is_valid())
+ for_all_elements(e, bot_groups(g).component_ids())
{
- bot_median_char_space(bot_groups(g)).take(lines(g).char_space());
- bot_median_char_width(bot_groups(g)).take(lines(g).char_width());
+ unsigned l = bot_groups(g).component_ids()(e);
+
+ if (lines(l).card() > 1)
+ {
+ bot_median_char_space(g).take(lines(l).char_space());
+ bot_median_char_width(g).take(lines(l).char_width());
+ }
+ // This data will be used if alignments are made with single
+ // components only.
+ else if (bot_max_char_width(g) < lines(l).char_width())
+ bot_max_char_width(g) = lines(l).char_width();
}
- // This data will be used if alignments are made with single
- // components only.
- else if (bot_max_char_width(bot_groups(g)) < lines(g).char_width())
- bot_max_char_width(bot_groups(g)) = lines(g).char_width();
- }
}
@@ -921,19 +922,20 @@ namespace scribo
util::array<accu::shape::bbox<point2d> >
group_bbox(bot_groups.nelements());
- // Compute group bboxes
- for_all_links(l, bot_links)
- if (bot_links.is_valid(l))
- {
- point2d p = components(l).bbox().pmin();
- p.row() = components(l).bbox().pmax().row();
+ // Compute group bboxes
+ for_all_groups(g, bot_groups)
+ for_all_elements(e, bot_groups(g).component_ids())
+ {
+ unsigned l = bot_groups(g).component_ids()(e);
+ point2d p = components(l).bbox().pmin();
+ p.row() = components(l).bbox().pmax().row();
- if (bot_groups.is_valid(l)
- && bot_group_size(old_bot_groups(l)) > 2)
+ if (bot_groups(g).is_valid())// && bot_links.is_linked(l))
+ {
+ if (bot_groups.group_of(l).is_valid())
{
- group_bbox(bot_groups(l)).take(p);
- group_bbox(bot_groups(l)).take(
- components(bot_links(l)).bbox().pmax());
+ group_bbox(g).take(p);
+ group_bbox(g).take(components(bot_links(l)).bbox().pmax());
# ifndef SCRIBO_NDEBUG
// Draw first component box
@@ -950,76 +952,78 @@ namespace scribo
literal::cyan);
# endif // ! SCRIBO_NDEBUG
}
-
+ }
# ifndef SCRIBO_NDEBUG
- else if (bot_group_size(old_bot_groups(l)) > 1)
- {
- mln::draw::line(debug,
- p,
- components(bot_links(l)).bbox().pmax(),
- literal::orange);
-
- // Draw first component box
- mln::draw::box(debug,
- internal::fast_rotate_positive(
- groups.components()(lines(l).component_ids()[lines(l).card() - 1]).bbox(),
- rbbox),
- literal::cyan);
-
- mln::draw::box(debug,
- internal::fast_rotate_positive(
- groups.components()(lines(bot_links(l)).component_ids()[lines(bot_links(l)).card() - 1]).bbox(),
- rbbox),
- literal::cyan);
- }
-# endif // ! SCRIBO_NDEBUG
+ else if (bot_groups(g).card() > 1)
+ {
+ mln::draw::line(debug,
+ p,
+ components(bot_links(l)).bbox().pmax(),
+ literal::orange);
+
+ // Draw first component box
+ mln::draw::box(debug,
+ internal::fast_rotate_positive(
+ groups.components()(lines(l).component_ids()[lines(l).card() - 1]).bbox(),
+ rbbox),
+ literal::cyan);
+
+ mln::draw::box(debug,
+ internal::fast_rotate_positive(
+ groups.components()(lines(bot_links(l)).component_ids()[lines(bot_links(l)).card() - 1]).bbox(),
+ rbbox),
+ literal::cyan);
}
-
+# endif // ! SCRIBO_NDEBUG
+ }
// Looking for whitespaces
- for_all_elements(c, group_bbox)
- if (group_bbox(c).is_valid())
+ for_all_groups(g, bot_groups)
+ if (bot_groups(g).is_valid())
{
unsigned ldelta = delta;
- if (bot_group_size(c) >= 3 && bot_group_size(c) < 5)
+ // Special case : handle low connected groups.
+ if (bot_groups(g).card() >= 3 && bot_groups(g).card() < 5)
{
// Stats are not reliable, prefer using max char width.
- if (bot_median_char_width(c).card() == 0)
- ldelta = bot_max_char_width(c) * 2;
+ if (bot_median_char_width(g).card() == 0)
+ ldelta = internal::compute_unreliable_ldelta(bot_max_char_width(g));
else
- ldelta = 1.2 * bot_median_char_width(c)
- + bot_median_char_space(c);
+ ldelta = internal::compute_reliable_ldelta(bot_median_char_width(g),
+ bot_median_char_space(g));
- point2d p(group_bbox(c).to_result().pmax().row() + ldelta,
- group_bbox(c).to_result().pmin().col());
+ point2d p(bot_groups(g).bbox().pmax().row() + ldelta,
+ bot_groups(g).bbox().pmin().col());
p = scribo::internal::point_row_adjust(p, bbox_ima);
// Checking whitespace area
- for (; p.col() <= group_bbox(c).to_result().pmax().col()
+ for (; p.col() <= group_bbox(g).to_result().pmax().col()
&& (bbox_ima(p) == 0);)
++p.col();
if (bbox_ima(p) != 0)
{
+ bot_groups(g).invalidate();
+
# ifndef SCRIBO_NDEBUG
mln::draw::line(debug,
scribo::internal::point_row_adjust(
- point2d(group_bbox(c).to_result().pmax().row() + ldelta,
- group_bbox(c).to_result().pmin().col()), debug),
+ point2d(group_bbox(g).to_result().pmax().row() + ldelta,
+ group_bbox(g).to_result().pmin().col()), debug),
scribo::internal::point_row_adjust(
- point2d(group_bbox(c).to_result().pmax().row() + ldelta,
- group_bbox(c).to_result().pmax().col()), debug),
+ point2d(group_bbox(g).to_result().pmax().row() + ldelta,
+ group_bbox(g).to_result().pmax().col()), debug),
literal::red);
# endif // ! SCRIBO_NDEBUG
-
continue;
}
}
box2d
- brot = internal::fast_rotate_negative(group_bbox(c).to_result(),
+ brot = internal::fast_rotate_negative(group_bbox(g).to_result(),
rbbox);
+ // Checking if delimitor is skewed.
if (internal::is_valid_left_right_skewed_delimitor(brot, input,
- delta))
{
@@ -1066,11 +1070,11 @@ namespace scribo
# ifndef SCRIBO_NDEBUG
mln::draw::line(debug,
scribo::internal::point_row_adjust(
- point2d(group_bbox(c).to_result().pmax().row() + ldelta,
- group_bbox(c).to_result().pmin().col()), debug),
+ point2d(group_bbox(g).to_result().pmax().row() + ldelta,
+ group_bbox(g).to_result().pmin().col()), debug),
scribo::internal::point_row_adjust(
- point2d(group_bbox(c).to_result().pmax().row() + ldelta,
- group_bbox(c).to_result().pmax().col()), debug),
+ point2d(group_bbox(g).to_result().pmax().row() + ldelta,
+ group_bbox(g).to_result().pmax().col()), debug),
literal::green);
# endif // ! SCRIBO_NDEBUG
}
--
1.5.6.5
1
0

last-svn-commit-845-g7e736d6 Improve object_groups and object_links API.
by Guillaume Lazzara 03 May '11
by Guillaume Lazzara 03 May '11
03 May '11
* scribo/core/group_info.hh,
* scribo/core/internal/sort_comp_ids.hh: New.
* scribo/core/object_groups.hh,
* scribo/core/object_links.hh: Improve API.
* scribo/core/line_info.hh,
* scribo/core/line_set.hh,
* scribo/debug/decision_image.hh,
* scribo/estim/object_groups_mean_width.hh,
* scribo/filter/object_groups_mean_width.hh,
* scribo/filter/object_groups_size_ratio.hh,
* scribo/filter/object_groups_small.hh,
* scribo/filter/object_groups_with_holes.hh,
* scribo/filter/object_links_bbox_overlap.hh,
* scribo/filter/object_links_bbox_ratio.hh,
* scribo/filter/object_links_non_aligned_simple.hh,
* scribo/primitive/group/from_double_link_any.hh,
* scribo/primitive/group/from_single_link.hh,
* scribo/primitive/internal/is_link_valid.hh,
* scribo/primitive/link/internal/link_functor_base.hh,
* scribo/primitive/link/internal/link_several_dmax_base.hh,
* scribo/primitive/link/merge_double_link.hh,
* scribo/primitive/link/merge_double_link_closest_aligned.hh,
* tests/filter/object_groups_mean_width.cc,
* tests/filter/object_groups_size_ratio.cc,
* tests/filter/object_groups_small.cc,
* tests/filter/object_groups_with_holes.cc: Update code to take
API changes into account.
---
scribo/ChangeLog | 34 +++
scribo/scribo/core/group_info.hh | 184 ++++++++++++++++
.../sort_comp_ids.hh} | 57 +++---
scribo/scribo/core/line_info.hh | 140 ++++++++-----
scribo/scribo/core/line_set.hh | 66 ++++---
scribo/scribo/core/object_groups.hh | 228 +++++++++++++++-----
scribo/scribo/core/object_links.hh | 81 ++++++-
scribo/scribo/debug/decision_image.hh | 8 +-
scribo/scribo/estim/object_groups_mean_width.hh | 21 +--
scribo/scribo/filter/object_groups_mean_width.hh | 10 +-
scribo/scribo/filter/object_groups_size_ratio.hh | 16 +-
scribo/scribo/filter/object_groups_small.hh | 36 +---
scribo/scribo/filter/object_groups_with_holes.hh | 2 +-
scribo/scribo/filter/object_links_bbox_overlap.hh | 6 +-
scribo/scribo/filter/object_links_bbox_ratio.hh | 10 +-
.../filter/object_links_non_aligned_simple.hh | 6 +-
.../scribo/primitive/group/from_double_link_any.hh | 57 ++++--
scribo/scribo/primitive/group/from_single_link.hh | 13 --
scribo/scribo/primitive/internal/is_link_valid.hh | 12 +-
.../primitive/link/internal/link_functor_base.hh | 2 +-
.../link/internal/link_several_dmax_base.hh | 10 +-
scribo/scribo/primitive/link/merge_double_link.hh | 17 +-
.../link/merge_double_link_closest_aligned.hh | 6 +-
scribo/tests/filter/object_groups_mean_width.cc | 11 +-
scribo/tests/filter/object_groups_size_ratio.cc | 10 +-
scribo/tests/filter/object_groups_small.cc | 28 +--
scribo/tests/filter/object_groups_with_holes.cc | 10 +-
27 files changed, 743 insertions(+), 338 deletions(-)
create mode 100644 scribo/scribo/core/group_info.hh
copy scribo/scribo/core/{component_features_data.hh => internal/sort_comp_ids.hh} (59%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 8d95b3a..7bbfb9e 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,37 @@
+2011-05-03 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+
+ Improve object_groups and object_links API.
+
+ * scribo/core/group_info.hh,
+ * scribo/core/internal/sort_comp_ids.hh: New.
+
+ * scribo/core/object_groups.hh,
+ * scribo/core/object_links.hh: Improve API.
+
+ * scribo/core/line_info.hh,
+ * scribo/core/line_set.hh,
+ * scribo/debug/decision_image.hh,
+ * scribo/estim/object_groups_mean_width.hh,
+ * scribo/filter/object_groups_mean_width.hh,
+ * scribo/filter/object_groups_size_ratio.hh,
+ * scribo/filter/object_groups_small.hh,
+ * scribo/filter/object_groups_with_holes.hh,
+ * scribo/filter/object_links_bbox_overlap.hh,
+ * scribo/filter/object_links_bbox_ratio.hh,
+ * scribo/filter/object_links_non_aligned_simple.hh,
+ * scribo/primitive/group/from_double_link_any.hh,
+ * scribo/primitive/group/from_single_link.hh,
+ * scribo/primitive/internal/is_link_valid.hh,
+ * scribo/primitive/link/internal/link_functor_base.hh,
+ * scribo/primitive/link/internal/link_several_dmax_base.hh,
+ * scribo/primitive/link/merge_double_link.hh,
+ * scribo/primitive/link/merge_double_link_closest_aligned.hh,
+ * tests/filter/object_groups_mean_width.cc,
+ * tests/filter/object_groups_size_ratio.cc,
+ * tests/filter/object_groups_small.cc,
+ * tests/filter/object_groups_with_holes.cc: Update code to take
+ API changes into account.
+
2011-04-07 Guillaume Lazzara <z(a)lrde.epita.fr>
Add test data in EXTRA_DIST.
diff --git a/scribo/scribo/core/group_info.hh b/scribo/scribo/core/group_info.hh
new file mode 100644
index 0000000..19a8ecc
--- /dev/null
+++ b/scribo/scribo/core/group_info.hh
@@ -0,0 +1,184 @@
+// Copyright (C) 2011 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_CORE_GROUP_INFO_HH
+# define SCRIBO_CORE_GROUP_INFO_HH
+
+/// \file
+///
+/// \brief Object groups representation.
+
+# include <mln/util/array.hh>
+
+# include <scribo/core/object_links.hh>
+# include <scribo/core/component_set.hh>
+
+# include <scribo/core/internal/sort_comp_ids.hh>
+# include <scribo/core/concept/serializable.hh>
+
+
+namespace scribo
+{
+
+ using namespace mln;
+
+ class group_info
+ {
+ public:
+ group_info();
+ group_info(unsigned id, const mln::util::array<component_id_t>& comps,
+ unsigned pixel_area, const box2d& bbox);
+ // used for incremental construction (xml loading).
+ group_info(unsigned id, unsigned pixel_area, const box2d& bbox,
+ bool valid = false);
+
+ const mln::util::array<component_id_t>& component_ids() const;
+
+ // Used for incremental construction (xml loading)
+ mln::util::array<component_id_t>& component_ids_();
+
+ bool is_valid() const;
+ void invalidate();
+
+ unsigned card() const;
+ unsigned id() const;
+ unsigned pixel_area() const;
+ const box2d& bbox() const;
+
+ private:
+ unsigned id_;
+ mln::util::array<component_id_t> comps_;
+ bool valid_;
+ unsigned pixel_area_;
+ box2d bbox_;
+ };
+
+ bool operator==(const group_info& lhs, const group_info& rhs);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ group_info::group_info()
+ : valid_(false)
+ {
+ }
+
+ group_info::group_info(unsigned id, const mln::util::array<component_id_t>& comps,
+ unsigned pixel_area, const box2d& bbox)
+ : id_(id), comps_(comps), valid_(true),
+ pixel_area_(pixel_area), bbox_(bbox)
+ {
+ }
+
+ group_info::group_info(unsigned id, unsigned pixel_area, const box2d& bbox, bool valid)
+ : id_(id), valid_(valid),
+ pixel_area_(pixel_area), bbox_(bbox)
+ {
+ }
+
+ const mln::util::array<component_id_t>&
+ group_info::component_ids() const
+ {
+ return comps_;
+ }
+
+ mln::util::array<component_id_t>&
+ group_info::component_ids_()
+ {
+ return comps_;
+ }
+
+ bool group_info::is_valid() const
+ {
+ return valid_;
+ }
+
+ void
+ group_info::invalidate()
+ {
+ valid_ = false;
+ }
+
+ unsigned
+ group_info::card() const
+ {
+ return comps_.nelements();
+ }
+
+ unsigned
+ group_info::id() const
+ {
+ return id_;
+ }
+
+ unsigned
+ group_info::pixel_area() const
+ {
+ return pixel_area_;
+ }
+
+ const box2d&
+ group_info::bbox() const
+ {
+ return bbox_;
+ }
+
+ inline
+ std::ostream&
+ operator<<(std::ostream& ostr, const group_info& group_info)
+ {
+ ostr << "group_info[";
+
+ ostr << "id=" << group_info.id() << ", "
+ << "valid=" << group_info.is_valid() << ", "
+ << "pixel_area=" << group_info.pixel_area() << ", "
+ << "bbox=" << group_info.bbox() << ", "
+ << "component_ids=" << group_info.component_ids();
+
+ ostr << "]";
+
+ return ostr;
+ }
+
+ inline
+ bool
+ operator==(const group_info& lhs, const group_info& rhs)
+ {
+ return
+ lhs.id() == rhs.id()
+ && lhs.component_ids() == rhs.component_ids()
+ && lhs.is_valid() == rhs.is_valid()
+ && lhs.pixel_area() == rhs.pixel_area()
+ && lhs.bbox() == rhs.bbox();
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_CORE_GROUP_INFO_HH
diff --git a/scribo/scribo/core/component_features_data.hh b/scribo/scribo/core/internal/sort_comp_ids.hh
similarity index 59%
copy from scribo/scribo/core/component_features_data.hh
copy to scribo/scribo/core/internal/sort_comp_ids.hh
index 07b3e4a..83cd507 100644
--- a/scribo/scribo/core/component_features_data.hh
+++ b/scribo/scribo/core/internal/sort_comp_ids.hh
@@ -23,54 +23,55 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_CORE_COMPONENT_FEATURES_DATA_HH
-# define SCRIBO_CORE_COMPONENT_FEATURES_DATA_HH
+#ifndef SCRIBO_CORE_INTERNAL_SORT_COMP_IDS_HH
+# define SCRIBO_CORE_INTERNAL_SORT_COMP_IDS_HH
/// \file
///
-/// \brief Component features data structure.
+/// Functor ordering Components by location, from left to right.
-# include <scribo/core/def/color_type.hh>
+# include <scribo/core/component_set.hh>
+
namespace scribo
{
- struct component_features_data
+ namespace internal
{
- component_features_data();
-
- bool valid;
- scribo::def::color_type color;
- float boldness;
- };
+ template <typename L>
+ struct sort_comp_ids
+ {
+ sort_comp_ids(const component_set<L>& comp_set);
+ bool operator()(const component_id_t& l, const component_id_t& r) const;
- std::ostream&
- operator<<(std::ostream& ostr, const component_features_data& data);
+ component_set<L> comps_;
+ };
# ifndef MLN_INCLUDE_ONLY
- component_features_data::component_features_data()
- : valid(false)
- {
- }
+ template <typename L>
+ sort_comp_ids<L>::sort_comp_ids(const component_set<L>& comp_set)
+ : comps_(comp_set)
+ {
+ }
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const component_features_data& data)
- {
- return ostr << "features["
- << "valid=" << data.valid
- << ", color=" << data.color
- << ", boldness=" << data.boldness
- << "]" << std::endl;
- }
+ template <typename L>
+ bool
+ sort_comp_ids<L>::operator()(const component_id_t& l,
+ const component_id_t& r) const
+ {
+ return comps_(l).bbox().pmin().col() < comps_(r).bbox().pmin().col()
+ && comps_(l).bbox().pmax().col() < comps_(r).bbox().pmax().col();
+ }
# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace scribo::internal
+
} // end of namespace scribo
-#endif // ! SCRIBO_CORE_COMPONENT_FEATURES_DATA_HH
+#endif // ! SCRIBO_CORE_INTERNAL_SORT_COMP_IDS_HH
diff --git a/scribo/scribo/core/line_info.hh b/scribo/scribo/core/line_info.hh
index e925db7..b8a8be3 100644
--- a/scribo/scribo/core/line_info.hh
+++ b/scribo/scribo/core/line_info.hh
@@ -54,9 +54,11 @@
# include <scribo/core/tag/component.hh>
# include <scribo/core/tag/line.hh>
+# include <scribo/core/object_groups.hh>
# include <scribo/core/line_set.hh>
# include <scribo/core/component_set.hh>
+# include <scribo/core/internal/sort_comp_ids.hh>
# include <scribo/core/concept/serializable.hh>
@@ -79,14 +81,16 @@ namespace scribo
{
line_info_data();
line_info_data(const line_set<L>& holder,
- const mln::util::array<component_id_t>& comps);
-
+ const group_info& group);
+ // Used for incremental construction (xml loading)
+ line_info_data(const line_set<L>& holder,
+ const mln::util::array<component_id_t>& component_ids);
bool hidden_;
line::Tag tag_;
mln::box2d bbox_;
mln::box2d ebbox_;
- mln::util::array<component_id_t> components_;
+ mln::util::array<component_id_t> component_ids_;
// The number of pixels used for line characters.
unsigned pixel_area_;
@@ -138,21 +142,11 @@ namespace scribo
// Line set holding this element.
line_set<L> holder_;
- };
-
-
- // Functor used to sort components ids.
- // Order by location from left to right.
- template <typename L>
- struct sort_comp_ids
- {
- sort_comp_ids(const component_set<L>& comp_set);
- bool operator()(const component_id_t& l, const component_id_t& r) const;
+ private:
+ void init_();
- component_set<L> comps_;
};
-
} // end of namespace scribo::internal
@@ -176,7 +170,7 @@ namespace scribo
line_info(const line_set<L>& holder,
const line_id_t& id,
- const mln::util::array<component_id_t>& comps);
+ const group_info& group);
/// The line id of the target instance is preserved if it is valid.
line_info(const line_info<L>& other);
@@ -317,6 +311,10 @@ namespace scribo
std::ostream&
operator<<(std::ostream& ostr, const line_info<L>& info);
+ template <typename L>
+ bool
+ operator==(const line_info<L>& lhs, const line_info<L>& rhs);
+
# ifndef MLN_INCLUDE_ONLY
@@ -365,13 +363,28 @@ namespace scribo
hidden_ = false;
}
+ template <typename L>
+ line_info_data<L>::line_info_data(const line_set<L>& holder,
+ const group_info& group)
+ : hidden_(false), tag_(line::None), component_ids_(group.component_ids()),
+ type_(line::Undefined), holder_(holder)
+ {
+ init_();
+ }
template <typename L>
line_info_data<L>::line_info_data(const line_set<L>& holder,
- const mln::util::array<component_id_t>& comps)
- : hidden_(false), tag_(line::None), components_(comps),
+ const mln::util::array<component_id_t>& component_ids)
+ : hidden_(false), tag_(line::None), component_ids_(component_ids),
type_(line::Undefined), holder_(holder)
{
+ init_();
+ }
+
+ template <typename L>
+ void
+ line_info_data<L>::init_()
+ {
// FIXME: set valid information for these attributes in
// force_stats_update.
word_space_ = 0;
@@ -384,26 +397,6 @@ namespace scribo
indented_ = false;
}
-
-
- // sort_comp_ids functor
-
- template <typename L>
- sort_comp_ids<L>::sort_comp_ids(const component_set<L>& comp_set)
- : comps_(comp_set)
- {
- }
-
-
- template <typename L>
- bool
- sort_comp_ids<L>::operator()(const component_id_t& l,
- const component_id_t& r) const
- {
- return comps_(l).bbox().pmin().col() < comps_(r).bbox().pmin().col()
- && comps_(l).bbox().pmax().col() < comps_(r).bbox().pmax().col();
- }
-
} // end of namespace scribo::internal
@@ -480,10 +473,10 @@ namespace scribo
template <typename L>
line_info<L>::line_info(const line_set<L>& holder,
const line_id_t& id,
- const mln::util::array<component_id_t>& comps)
+ const group_info& group)
: id_(id)
{
- data_ = new data_t(holder, comps);
+ data_ = new data_t(holder, group);
force_stats_update();
}
@@ -540,7 +533,7 @@ namespace scribo
const mln::util::array<typename line_info<L>::component_id_t>&
line_info<L>::component_ids() const
{
- return data_->components_;
+ return data_->component_ids_;
}
@@ -548,7 +541,7 @@ namespace scribo
unsigned
line_info<L>::card() const
{
- return data_->components_.size();
+ return data_->component_ids_.size();
}
@@ -691,9 +684,9 @@ namespace scribo
void
line_info<L>::update_components_type(component::Type type)
{
- for_all_elements(i, data_->components_)
+ for_all_elements(i, data_->component_ids_)
{
- unsigned c = data_->components_[i];
+ unsigned c = data_->component_ids_[i];
data_->holder_.components_()(c).update_type(type);
}
}
@@ -954,7 +947,7 @@ namespace scribo
// Update bbox and ebbox
update_bbox_and_ebox(other);
- data_->components_.append(other.component_ids());
+ data_->component_ids_.append(other.component_ids());
}
@@ -1006,9 +999,9 @@ namespace scribo
// Workaround to avoid overflow with int_u<12> in median accumulators.
//
// FIXME: not optimal...
- for_all_elements(i, data_->components_)
+ for_all_elements(i, data_->component_ids_)
{
- unsigned c = data_->components_(i);
+ unsigned c = data_->component_ids_(i);
// Ignore punctuation for stats computation but not for bbox
// computation.
@@ -1020,9 +1013,9 @@ namespace scribo
unsigned used_comps = 0;
- for_all_elements(i, data_->components_)
+ for_all_elements(i, data_->component_ids_)
{
- unsigned c = data_->components_(i);
+ unsigned c = data_->component_ids_(i);
pixel_area += comp_set(c).card();
@@ -1111,8 +1104,8 @@ namespace scribo
// Order component ids according to component localization (left
// to right).
- std::sort(data_->components_.hook_std_vector_().begin(),
- data_->components_.hook_std_vector_().end(),
+ std::sort(data_->component_ids_.hook_std_vector_().begin(),
+ data_->component_ids_.hook_std_vector_().end(),
internal::sort_comp_ids<L>(comp_set));
// Boldness
@@ -1142,8 +1135,8 @@ namespace scribo
// Char width
if (card() == 2)
- data_->char_width_ = (comp_set(data_->components_[0]).bbox().width()
- + comp_set(data_->components_[1]).bbox().width()) / 2;
+ data_->char_width_ = (comp_set(data_->component_ids_[0]).bbox().width()
+ + comp_set(data_->component_ids_[1]).bbox().width()) / 2;
else
data_->char_width_ = char_width.to_result();
@@ -1218,6 +1211,47 @@ namespace scribo
}
+ template <typename L>
+ bool
+ operator==(const line_info<L>& lhs, const line_info<L>& rhs)
+ {
+ if (! lhs.is_valid() && ! rhs.is_valid())
+ return true;
+
+ return
+ lhs.is_valid() == rhs.is_valid()
+ && lhs.id() == rhs.id()
+ && lhs.pixel_area() == rhs.pixel_area()
+ && lhs.tag() == rhs.tag()
+ && lhs.type() == rhs.type()
+ && lhs.bbox() == rhs.bbox()
+ && lhs.ebbox() == rhs.ebbox()
+ && lhs.boldness() == rhs.boldness()
+ && lhs.boldness_reliability() == rhs.boldness_reliability()
+ && lhs.color() == rhs.color()
+ && lhs.color_reliability() == rhs.color_reliability()
+ && lhs.component_ids() == rhs.component_ids()
+ && lhs.baseline() == rhs.baseline()
+ && lhs.meanline() == rhs.meanline()
+ && lhs.ascent() == rhs.ascent()
+ && lhs.descent() == rhs.descent()
+ && lhs.x_height() == rhs.x_height()
+ && lhs.d_height() == rhs.d_height()
+ && lhs.a_height() == rhs.a_height()
+ && lhs.char_space() == rhs.char_space()
+ && lhs.char_width() == rhs.char_width()
+ && lhs.word_space() == rhs.word_space()
+ && lhs.reading_orientation() == rhs.reading_orientation()
+ && lhs.type() == rhs.type()
+ && lhs.reverse_video() == rhs.reverse_video()
+ && lhs.orientation() == rhs.orientation()
+ && lhs.reading_orientation() == rhs.reading_orientation()
+ && lhs.indented() == rhs.indented()
+ && lhs.is_hidden() == rhs.is_hidden()
+ && lhs.text() == rhs.text()
+ && lhs.html_text() == rhs.html_text();
+ }
+
# endif// ! MLN_INCLUDE_ONLY
diff --git a/scribo/scribo/core/line_set.hh b/scribo/scribo/core/line_set.hh
index f1e443b..db987e6 100644
--- a/scribo/scribo/core/line_set.hh
+++ b/scribo/scribo/core/line_set.hh
@@ -123,6 +123,9 @@ namespace scribo
/// Return line information for a given line id \p id.
const line_info<L>& operator()(const line_id_t& id) const;
+ /// Return all the line information.
+ const mln::util::array<line_info<L> >& infos() const;
+
/// Update tag of lines set to 'false' in \p f with \p tag.
template <typename F>
void update_tags(const mln::Function_v2b<F>& f, line::Tag tag);
@@ -166,7 +169,6 @@ namespace scribo
void update_line_data_(const mln::util::array<line_info<L> >& line_data);
-
private:
/// Duplicate the underlying image and create a new line_set.
void init_(const line_set<L>& model);
@@ -174,6 +176,11 @@ namespace scribo
mln::util::tracked_ptr< internal::line_set_data<L> > data_;
};
+
+ template <typename L>
+ bool
+ operator==(const line_set<L>& lhs, const line_set<L>& rhs);
+
template <typename L>
std::ostream&
operator<<(std::ostream& ostr, const line_set<L>& lines);
@@ -260,38 +267,14 @@ namespace scribo
{
data_ = new internal::line_set_data<L>(groups);
- typedef mln_site(L) P;
-
- mln_value(L) n_groups = groups.nelements() - 1;
- mln::fun::i2v::array<mln_value(L)>
- packed_groups = mln::make::relabelfun(groups.comp_to_group(),
- n_groups, n_groups);
-
- // FIXME: object_groups should store the relation 'group -> comp'.
- mln::util::array< mln::util::array<component_id_t> >
- group_to_comps(value::next(n_groups));
-
-
- // 1st pass - Compute data.
- for_all_comps(i, data_->components_)
- if (data_->components_(i).is_valid())
- {
- unsigned group_id = packed_groups(i);
- if (group_id != 0) // Is this component part of a group?
- {
- // Component id.
- group_to_comps(group_id).append(i);
- }
- }
-
// 2nd pass - Store data.
- data_->infos_.reserve(group_to_comps.size());
+ data_->infos_.reserve(groups.nelements());
data_->infos_.append(line_info<L>()); // line with id 0 is invalid.
- for_all_groups(i, group_to_comps)
+ for_all_groups(i, groups)
{
// Add line info.
- line_info<L> info(*this, i, group_to_comps(i));
+ line_info<L> info(*this, i, groups(i));
data_->infos_.append(info);
}
}
@@ -339,6 +322,13 @@ namespace scribo
}
template <typename L>
+ const mln::util::array<line_info<L> >&
+ line_set<L>::infos() const
+ {
+ return this->data_->infos_;
+ }
+
+ template <typename L>
template <typename F>
inline
void
@@ -437,6 +427,26 @@ namespace scribo
data_ = new internal::line_set_data<L>(set.infos_(), set.groups());
}
+ template <typename L>
+ bool
+ operator==(const line_set<L>& lhs, const line_set<L>& rhs)
+ {
+ if (! (lhs.groups() == rhs.groups() && lhs.nelements() == rhs.nelements()))
+ {
+ std::cout << "line.group" << std::endl;
+ return false;
+ }
+
+ for_all_lines(l, lhs)
+ if ( ! (lhs(l) != rhs(l)))
+ {
+ std::cout << "line.info" << std::endl;
+ return false;
+ }
+
+ return true;
+ }
+
template <typename L>
diff --git a/scribo/scribo/core/object_groups.hh b/scribo/scribo/core/object_groups.hh
index 2a4b0b1..1cc8815 100644
--- a/scribo/scribo/core/object_groups.hh
+++ b/scribo/scribo/core/object_groups.hh
@@ -36,8 +36,13 @@
# include <scribo/core/object_links.hh>
# include <scribo/core/component_set.hh>
+# include <scribo/core/group_info.hh>
+# include <scribo/core/internal/sort_comp_ids.hh>
# include <scribo/core/concept/serializable.hh>
+// Not to include.
+//#include <scribo/core/line_info.hh>
+
namespace scribo
{
@@ -47,7 +52,6 @@ namespace scribo
// Forward declaration.
template <typename L> class object_groups;
-
namespace internal
{
/// Data structure for \c scribo::object_groups<I>.
@@ -56,9 +60,12 @@ namespace scribo
{
object_groups_data();
object_groups_data(const object_links<L>& links);
- object_groups_data(const object_links<L>& links, unsigned value);
+ object_groups_data(const object_links<L>& links,
+ const mln::util::array<group_info>& info);
mln::util::array<unsigned> comp_to_group_;
+ mln::util::array<group_info> group_info_;
+
component_set<L> components_;
object_links<L> links_;
};
@@ -78,26 +85,34 @@ namespace scribo
public:
object_groups();
object_groups(const object_links<L>& links);
- object_groups(const object_links<L>& links, unsigned value);
+ // Used for incremental construction (xml loading)
+ object_groups(const object_links<L>& links,
+ const mln::util::array<group_info>& info);
const component_set<L>& components() const;
const object_links<L>& links() const;
- void init_(const object_links<L>& links);
-
bool is_valid() const;
- bool is_valid(unsigned comp_id) const;
+
+ // Return the number of groups
unsigned nelements() const;
- unsigned& operator()(unsigned comp_id);
- const unsigned& operator()(unsigned comp_id) const;
+ /// Return the group id of the component \p comp_id.
+ const group_info& group_of(unsigned comp_id) const;
+ group_info& group_of(unsigned comp_id);
+
+ /// Return group info data for group with id \p group_id.
+ /// Valid id starts from 1.
+ const group_info& operator()(unsigned group_id) const;
+ group_info& operator()(unsigned group_id);
+
+ // Map component ids to group ids.
const mln::util::array<unsigned>& comp_to_group() const;
object_groups<L> duplicate() const;
- void init();
private: // attributes
mln::util::tracked_ptr<data_t> data_;
@@ -108,6 +123,10 @@ namespace scribo
std::ostream&
operator<<(std::ostream& ostr, const object_groups<L>& groups);
+ template <typename L>
+ bool
+ operator==(const object_groups<L>& lhs, const object_groups<L>& rhs);
+
# ifndef MLN_INCLUDE_ONLY
@@ -127,17 +146,93 @@ namespace scribo
: comp_to_group_(unsigned(links.nelements())),
components_(links.components()), links_(links)
{
- };
-
+ comp_to_group_ = links.comp_to_link();
+
+ unsigned ngroups = 0;
+ util::array<unsigned> new_id(comp_to_group_.nelements(), 0);
+ mln::util::array<mln::util::array<component_id_t> > comp_ids(1);
+ mln::util::array<accu::shape::bbox<mln_site(L)> > bboxes(1);
+ mln::util::array<unsigned> pixel_areas(1);
+
+ // Remove potential loops in linking
+ // FIXME: we may try to avoid loops while linking...
+ {
+ util::array<bool> deja_vu(comp_to_group_.nelements());
+ for_all_elements(e, comp_to_group_)
+ if (comp_to_group_(e) != e && comp_to_group_(e) != 0)
+ {
+ deja_vu.fill(false); // FIXME: ugly!
+ unsigned cur = e;
+ deja_vu(cur) = true;
+ while (comp_to_group_(cur) != cur && !deja_vu(comp_to_group_(cur)))
+ {
+ cur = comp_to_group_(cur);
+ deja_vu(cur) = true;
+ }
+ // Break the loop!
+ if (comp_to_group_(cur) != cur && deja_vu(comp_to_group_(cur)))
+ comp_to_group_(cur) = cur;
+ }
+ }
+
+ for_all_elements(e, comp_to_group_)
+ if (comp_to_group_(e) != 0)
+ {
+ // Make sure there is no intermediate ids to reach the root.
+ // FIXME: useful?
+ unsigned e_root = internal::find_root(comp_to_group_, e);
+
+ if (! new_id(e_root))
+ {
+ new_id(e_root) = ++ngroups;
+ comp_ids.resize(comp_ids.size() + 1);
+ bboxes.resize(bboxes.size() + 1);
+ pixel_areas.resize(pixel_areas.size() + 1, 0);
+ }
+
+ unsigned nid = new_id(e_root);
+ comp_ids(nid).append(e);
+
+ bboxes(nid).take(components_(e).bbox());
+ pixel_areas(nid) += components_(e).card();
+ }
+
+ group_info_.resize(1);
+ group_info_.reserve(ngroups);
+ util::array<unsigned> group_idx(ngroups + 1, 0);
+
+ for (unsigned i = 1; i < new_id.nelements(); ++i)
+ if (new_id(i))
+ {
+ unsigned id = new_id(i);
+
+ // Order component ids according to component localization (left
+ // to right).
+ std::sort(comp_ids(id).hook_std_vector_().begin(),
+ comp_ids(id).hook_std_vector_().end(),
+ internal::sort_comp_ids<L>(components_));
+
+ group_idx(id) = group_info_.size();
+ group_info_.append(group_info(group_info_.size(), comp_ids(id), pixel_areas(id), bboxes(id)));
+ }
+
+ // Update mapping comp/group with new ids. Note: group id is
+ // different from its location in group_info array during
+ // construction.
+ for (unsigned i = 0; i < comp_to_group_.nelements(); ++i)
+ comp_to_group_(i) = group_idx(new_id(comp_to_group_(i)));
+ }
template <typename L>
object_groups_data<L>::object_groups_data(const object_links<L>& links,
- unsigned value)
- : comp_to_group_(unsigned(links.nelements()), value),
+ const mln::util::array<group_info>& info)
+ : comp_to_group_(unsigned(links.nelements())), group_info_(info),
components_(links.components()), links_(links)
{
- };
-
+ for_all_groups(g, group_info_)
+ for_all_elements(e, group_info_(g).component_ids())
+ comp_to_group_(group_info_(g).component_ids()(e)) = group_info_(g).id();
+ }
} // end of namespace scribo::internal
@@ -154,9 +249,10 @@ namespace scribo
}
template <typename L>
- object_groups<L>::object_groups(const object_links<L>& links, unsigned value)
+ object_groups<L>::object_groups(const object_links<L>& links,
+ const mln::util::array<group_info>& info)
{
- data_ = new data_t(links, value);
+ data_ = new data_t(links, info);
}
template <typename L>
@@ -175,60 +271,66 @@ namespace scribo
}
template <typename L>
- void
- object_groups<L>::init_(const object_links<L>& links)
- {
- mln_assertion(data_ != 0);
- data_->comp_to_group_ = links.comp_to_link();
- }
-
- template <typename L>
bool
object_groups<L>::is_valid() const
{
- mln_assertion(data_->components_.nelements() == (nelements() - 1));
+ mln_assertion(data_->components_.nelements() == data_->comp_to_group_.nelements() - 1);
return data_->links_.is_valid();
}
template <typename L>
- bool
- object_groups<L>::is_valid(unsigned comp_id) const
+ unsigned
+ object_groups<L>::nelements() const
{
- mln_assertion(is_valid());
- mln_assertion(comp_id < data_->links_.nelements());
- return data_->links_(comp_id) != 0;
+ return data_->group_info_.nelements();
}
template <typename L>
- unsigned
- object_groups<L>::nelements() const
+ const group_info&
+ object_groups<L>::group_of(unsigned comp_id) const
{
- return data_->comp_to_group_.nelements();
+ mln_precondition(comp_id < data_->comp_to_group_.nelements());
+ mln_assertion(data_->group_info_(data_->comp_to_group_(comp_id)).id()
+ == data_->comp_to_group_(comp_id));
+ return data_->group_info_(data_->comp_to_group_(comp_id));
}
+ template <typename L>
+ group_info&
+ object_groups<L>::group_of(unsigned comp_id)
+ {
+ mln_precondition(comp_id < data_->comp_to_group_.nelements());
+ mln_assertion(data_->group_info_(data_->comp_to_group_(comp_id)).id()
+ == data_->comp_to_group_(comp_id));
+ return data_->group_info_(data_->comp_to_group_(comp_id));
+ }
template <typename L>
- unsigned&
- object_groups<L>::operator()(unsigned comp_id)
+ const util::array<unsigned>&
+ object_groups<L>::comp_to_group() const
{
- return data_->comp_to_group_(comp_id);
+ return data_->comp_to_group_;
}
template <typename L>
- const unsigned&
- object_groups<L>::operator()(unsigned comp_id) const
+ const group_info&
+ object_groups<L>::operator()(unsigned group_id) const
{
- return data_->comp_to_group_(comp_id);
+ mln_precondition(group_id < data_->group_info_.nelements());
+ return data_->group_info_(group_id);
}
+
template <typename L>
- const mln::util::array<unsigned>&
- object_groups<L>::comp_to_group() const
+ group_info&
+ object_groups<L>::operator()(unsigned group_id)
{
- return data_->comp_to_group_;
+ mln_precondition(group_id < data_->group_info_.nelements());
+ return data_->group_info_(group_id);
}
+
template <typename L>
inline
object_groups<L>
@@ -242,22 +344,15 @@ namespace scribo
}
template <typename L>
- void
- object_groups<L>::init()
- {
- for (unsigned i = 0; i < nelements(); ++i)
- data_->comp_to_group_(i) = i;
- }
-
-
- template <typename L>
std::ostream&
operator<<(std::ostream& ostr, const object_groups<L>& groups)
{
ostr << "object_groups[";
for_all_groups(g, groups)
- ostr << g << "->" << groups.comp_to_group()[g] << ", ";
+ ostr << groups(g) << ", ";
+
+ ostr << " | comp_to_group=" << groups.comp_to_group();
ostr << "]";
@@ -265,6 +360,33 @@ namespace scribo
}
+ template <typename L>
+ bool
+ operator==(const object_groups<L>& lhs, const object_groups<L>& rhs)
+ {
+ if (! (lhs.components() == rhs.components()))
+ {
+ std::cout << "group.comp" << std::endl;
+ return false;
+ }
+
+ if (!( lhs.comp_to_group() == rhs.comp_to_group() && lhs.nelements() == rhs.nelements()))
+ {
+ std::cout << "group.comp_to_group" << std::endl;
+ return false;
+ }
+
+
+ for_all_groups(g, lhs)
+ if (! (lhs(g) == rhs(g)))
+ {
+ std::cout << "group.info" << std::endl;
+ return false;
+ }
+
+ return true;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/scribo/core/object_links.hh b/scribo/scribo/core/object_links.hh
index 1fbcd5a..386de41 100644
--- a/scribo/scribo/core/object_links.hh
+++ b/scribo/scribo/core/object_links.hh
@@ -39,7 +39,6 @@
# include <scribo/core/concept/serializable.hh>
-
namespace scribo
{
@@ -51,6 +50,18 @@ namespace scribo
namespace internal
{
+
+ inline
+ unsigned
+ find_root(mln::util::array<unsigned>& parent, unsigned x)
+ {
+ if (parent(x) == x)
+ return x;
+ else
+ return parent(x) = find_root(parent, parent(x));
+ }
+
+
/// Data structure for \c scribo::object_links<I>.
template <typename L>
struct object_links_data
@@ -83,13 +94,36 @@ namespace scribo
const component_set<L>& components() const;
+ /// Return True if this object_links structure is correctly
+ /// constructed.
bool is_valid() const;
- bool is_valid(unsigned comp_id) const;
+
+ /// Return True if component \p comp_id can be linked to another
+ /// component.
+ bool has_linking_enabled(unsigned comp_id) const;
+
+ /// Return True if component \p comp_id has a link starting from
+ /// itself to another one.
+ bool is_linked(unsigned comp_id) const;
unsigned nelements() const;
- unsigned& operator()(unsigned comp_id);
+ /// Link related methods.
+ /// \{
+ /// Set link between component \p from_id and \p to_id.
+ void update(unsigned from_id, unsigned to_id);
+
+ /// Reset link for component with id \p id. This component can be
+ /// linked later.
+ void clear(unsigned id);
+
+ /// Do not allow component with id \p id to be linked to anyother
+ /// ones.
+ void disable_linking(unsigned id);
+
+ /// Get link id for component \p comp_id.
const unsigned& operator()(unsigned comp_id) const;
+ /// \}
const mln::util::array<unsigned>& comp_to_link() const;
@@ -183,13 +217,25 @@ namespace scribo
template <typename L>
bool
- object_links<L>::is_valid(unsigned comp_id) const
+ object_links<L>::has_linking_enabled(unsigned comp_id) const
{
mln_precondition(is_valid());
mln_precondition(comp_id < data_->comp_to_link_.nelements());
+
return data_->comp_to_link_(comp_id) != 0;
}
+ template <typename L>
+ bool
+ object_links<L>::is_linked(unsigned comp_id) const
+ {
+ mln_precondition(is_valid());
+ mln_precondition(comp_id < data_->comp_to_link_.nelements());
+
+ return has_linking_enabled(comp_id)
+ && data_->comp_to_link_(comp_id) != comp_id;
+ }
+
template <typename L>
unsigned
@@ -200,20 +246,32 @@ namespace scribo
template <typename L>
- unsigned&
- object_links<L>::operator()(unsigned comp_id)
+ const unsigned&
+ object_links<L>::operator()(unsigned comp_id) const
{
return data_->comp_to_link_(comp_id);
}
+ template <typename L>
+ void
+ object_links<L>::update(unsigned from_id, unsigned to_id)
+ {
+ data_->comp_to_link_(from_id) = to_id;
+ }
template <typename L>
- const unsigned&
- object_links<L>::operator()(unsigned comp_id) const
+ void
+ object_links<L>::clear(unsigned id)
{
- return data_->comp_to_link_(comp_id);
+ data_->comp_to_link_(id) = id;
}
+ template <typename L>
+ void
+ object_links<L>::disable_linking(unsigned id)
+ {
+ data_->comp_to_link_(id) = 0;
+ }
template <typename L>
const mln::util::array<unsigned>&
@@ -222,16 +280,15 @@ namespace scribo
return data_->comp_to_link_;
}
-
template <typename L>
void
object_links<L>::init()
{
for (unsigned i = 0; i < nelements(); ++i)
if (data_->components_(i).tag() == component::Ignored)
- data_->comp_to_link_(i) = 0;
+ disable_linking(i);
else
- data_->comp_to_link_(i) = i;
+ clear(i);
}
template <typename L>
diff --git a/scribo/scribo/debug/decision_image.hh b/scribo/scribo/debug/decision_image.hh
index aa1a188..ff298e6 100644
--- a/scribo/scribo/debug/decision_image.hh
+++ b/scribo/scribo/debug/decision_image.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -150,10 +150,10 @@ namespace scribo
for_all_comps(i, comps)
mln::draw::box(decision_image, comps(i).bbox(), literal::blue);
- for (unsigned i = 1; i < links.nelements(); ++i)
+ for_all_links(i, links)
{
- if (links(i) != i)
+ if (links.is_linked(i))
{
mln_site(L)
p1 = primitive::link::internal::compute_anchor(comps, i, anchor),
diff --git a/scribo/scribo/estim/object_groups_mean_width.hh b/scribo/scribo/estim/object_groups_mean_width.hh
index c74137a..65d843c 100644
--- a/scribo/scribo/estim/object_groups_mean_width.hh
+++ b/scribo/scribo/estim/object_groups_mean_width.hh
@@ -72,24 +72,17 @@ namespace scribo
const component_set<L>& components = groups.components();
- //FIXME: remove when object_groups will store the number of
- //elements per group.
- mln::util::array<unsigned> group_card(groups.nelements(), 0.0);
-
mln::util::array<float> output(groups.nelements(), 0.0);
- for_all_comps(i, components)
- if (components(i).is_valid())
- {
- output(groups(i)) += components(i).bbox().width();
- ++group_card(groups(i));
- }
+ for_all_groups(g, groups)
+ for_all_elements(e, groups(g).component_ids())
+ output(g) += components(groups(g).component_ids()(e)).bbox().width();
output(0) = 0;
- for_all_groups(i, output)
- if (components(i).is_valid())
- output(i) /= static_cast<float>(group_card(i));
+ for_all_groups(g, groups)
+ if (groups(g).is_valid())
+ output(g) /= groups(g).card();
else
- output(i) = 0;
+ output(g) = 0;
trace::exiting("scribo::estim::object_groups_mean_width");
return output;
diff --git a/scribo/scribo/filter/object_groups_mean_width.hh b/scribo/scribo/filter/object_groups_mean_width.hh
index 0668205..b9c7b8a 100644
--- a/scribo/scribo/filter/object_groups_mean_width.hh
+++ b/scribo/scribo/filter/object_groups_mean_width.hh
@@ -77,11 +77,11 @@ namespace scribo
group_width = estim::object_groups_mean_width(groups);
object_groups<L> output = groups.duplicate();
- output(0) = 0;
- for (unsigned i = 1; i < output.nelements(); ++i)
- if (groups.components()(i).is_valid()
- && group_width[groups(i)] < width)
- output(i) = 0;
+
+ for_all_groups(g, groups)
+ if (groups(g).is_valid()
+ && group_width[g] < width)
+ output(g).invalidate();
trace::exiting("scribo::filter::object_groups_mean_width");
return output;
diff --git a/scribo/scribo/filter/object_groups_size_ratio.hh b/scribo/scribo/filter/object_groups_size_ratio.hh
index 01676c4..6f2e33e 100644
--- a/scribo/scribo/filter/object_groups_size_ratio.hh
+++ b/scribo/scribo/filter/object_groups_size_ratio.hh
@@ -65,29 +65,23 @@ namespace scribo
const component_set<L>& comps = groups.components();
- // FIXME: estimating the group size should be removed once
- // available in the object_group structure.
// Counting the number of objects per group with a size ratio >
// max_ratio.
mln::util::array<unsigned>
- group_size(groups.nelements(), 0),
invalid_object_in_group(groups.nelements(), 0);
for_all_comps(i, comps)
{
if ((comps(i).bbox().height() / comps(i).bbox().width())
>= max_size_ratio)
- ++invalid_object_in_group(groups(i));
-
- ++group_size(groups(i));
+ ++invalid_object_in_group(groups.group_of(i).id());
}
object_groups<L> output(groups);
- output(0) = 0;
- for (unsigned i = 1; i < output.nelements(); ++i)
- if ((invalid_object_in_group(groups(i)) / static_cast<float>(group_size(groups(i)))) >= max_invalid_ratio_per_group
- || !comps(i).is_valid())
- output(i) = 0;
+ for_all_groups(g, groups)
+ if ((invalid_object_in_group(g) / static_cast<float>(groups(g).card())) >= max_invalid_ratio_per_group
+ || !groups(g).is_valid())
+ output(g).invalidate();
trace::exiting("scribo::filter::object_groups_size_ratio");
return output;
diff --git a/scribo/scribo/filter/object_groups_small.hh b/scribo/scribo/filter/object_groups_small.hh
index 8dd244c..dd92852 100644
--- a/scribo/scribo/filter/object_groups_small.hh
+++ b/scribo/scribo/filter/object_groups_small.hh
@@ -50,7 +50,6 @@ namespace scribo
\param[in] groups Information about object groups.
\param[in] n_links The minimum number of links per group.
- \param[out] group_size Return the group sizes _before_ filtering.
\return A copy of object group in which small groups have been
removed.
@@ -58,13 +57,6 @@ namespace scribo
template <typename L>
object_groups<L>
object_groups_small(const object_groups<L>& groups,
- unsigned n_links,
- mln::util::array<unsigned>& group_size);
-
- // \overload
- template <typename L>
- object_groups<L>
- object_groups_small(const object_groups<L>& groups,
unsigned n_links);
@@ -76,42 +68,22 @@ namespace scribo
inline
object_groups<L>
object_groups_small(const object_groups<L>& groups,
- unsigned n_links,
- mln::util::array<unsigned>& group_size)
+ unsigned n_links)
{
trace::entering("scribo::filter::object_groups_small");
mln_precondition(groups.is_valid());
- // Counting the number of objects per group.
- group_size = mln::util::array<unsigned>(groups.nelements(), 0);
- for_all_groups(i, group_size)
- ++group_size[groups(i)];
-
object_groups<L> output = groups.duplicate();
- output(0) = 0;
+
for_all_groups(i, output)
- if (group_size[groups(i)] < n_links
- || !groups.components()(i).is_valid())
- output(i) = 0;
+ if (output(i).is_valid() && output(i).card() < n_links)
+ output(i).invalidate();
trace::exiting("scribo::filter::object_groups_small");
return output;
}
-
- template <typename L>
- inline
- object_groups<L>
- object_groups_small(const object_groups<L>& groups,
- unsigned n_links)
- {
- mln::util::array<unsigned> group_size;
- return object_groups_small(groups, n_links, group_size);
- }
-
-
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::filter
diff --git a/scribo/scribo/filter/object_groups_with_holes.hh b/scribo/scribo/filter/object_groups_with_holes.hh
index b86b10e..a59beec 100644
--- a/scribo/scribo/filter/object_groups_with_holes.hh
+++ b/scribo/scribo/filter/object_groups_with_holes.hh
@@ -298,7 +298,7 @@ namespace scribo
object_groups<L> output = groups.duplicate();
for_all_groups(c, groups)
if (! to_keep(group_2_comp(c)))
- output(c) = 0;
+ output(c).invalidate();
trace::exiting("scribo::filter::impl::generic::object_groups_with_holes");
return output;
diff --git a/scribo/scribo/filter/object_links_bbox_overlap.hh b/scribo/scribo/filter/object_links_bbox_overlap.hh
index 995ad68..3bf3c50 100644
--- a/scribo/scribo/filter/object_links_bbox_overlap.hh
+++ b/scribo/scribo/filter/object_links_bbox_overlap.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -109,7 +109,7 @@ namespace scribo
if (ratio_i >= max_overlap_ratio
|| ratio_link_i >= max_overlap_ratio)
- output(i) = i;
+ output.clear(i);
}
trace::exiting("scribo::filter::object_links_bbox_overlap");
diff --git a/scribo/scribo/filter/object_links_bbox_ratio.hh b/scribo/scribo/filter/object_links_bbox_ratio.hh
index 5318b57..d6c9286 100644
--- a/scribo/scribo/filter/object_links_bbox_ratio.hh
+++ b/scribo/scribo/filter/object_links_bbox_ratio.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -78,10 +78,10 @@ namespace scribo
mln_precondition(links.is_valid());
const component_set<L>& components = links.components();
-
object_links<L> output = links.duplicate();
+
for_all_links(i, links)
- if (links(i) && links(i) != i)
+ if (links.is_linked(i))
{
float
lmin = components(i).bbox().pmax()[dim]
@@ -93,7 +93,7 @@ namespace scribo
std::swap(lmin, lmax);
if ((lmax/ lmin) > max_ratio)
- output(i) = i;
+ output.clear(i);
}
trace::exiting("scribo::filter::object_links_bbox_ratio");
diff --git a/scribo/scribo/filter/object_links_non_aligned_simple.hh b/scribo/scribo/filter/object_links_non_aligned_simple.hh
index 5abf598..f8db5cf 100644
--- a/scribo/scribo/filter/object_links_non_aligned_simple.hh
+++ b/scribo/scribo/filter/object_links_non_aligned_simple.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -112,7 +112,7 @@ namespace scribo
if (!::scribo::filter::internal::component_aligned_rad(comps, i, links(i),
anchor,
max_alpha_rad))
- output(i) = i;
+ output.clear(i);
trace::exiting("scribo::filter::object_links_non_aligned_simple");
diff --git a/scribo/scribo/primitive/group/from_double_link_any.hh b/scribo/scribo/primitive/group/from_double_link_any.hh
index b3bd82a..7ed15e2 100644
--- a/scribo/scribo/primitive/group/from_double_link_any.hh
+++ b/scribo/scribo/primitive/group/from_double_link_any.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -42,6 +43,7 @@
# include <scribo/core/macros.hh>
+# include <scribo/core/object_links.hh>
# include <scribo/core/object_groups.hh>
# include <scribo/core/component_set.hh>
# include <scribo/primitive/internal/find_root.hh>
@@ -73,6 +75,21 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ template <typename L>
+ util::array<unsigned> make_parent(const object_links<L>& link)
+ {
+ mln::util::array<unsigned> parent = link.comp_to_link();
+ for_all_links(l, link)
+ parent(l) = scribo::internal::find_root(parent, l);
+
+ return parent;
+ }
+
+ } // end of namespace scribo::primitive::group::internal
+
template <typename L>
inline
@@ -82,40 +99,46 @@ namespace scribo
{
trace::entering("scribo::primitive::group::from_double_link_any");
- object_groups<L> parent(left_link);
- parent.init();
+ object_links<L> merged_link(left_link.components());
+ merged_link.init();
+
+ util::array<unsigned> lparent = internal::make_parent(left_link);
+ util::array<unsigned> rparent = internal::make_parent(right_link);
- for_all_comps(i, left_link.components())
+ for_all_links(i, merged_link)
{
+ // Looking for new left link
unsigned
- pi = internal::find_root(parent, i),
- pli = internal::find_root(parent, left_link(i));
+ pi = scribo::internal::find_root(lparent, i),
+ pli = scribo::internal::find_root(lparent, left_link(i));
if (pi != pli)
{
- if (pli < pi)
- parent(pli) = pi;
+ merged_link.update(i, left_link(i));
+ if (pi < pli)
+ lparent(pli) = pi;
else
- parent(pi) = pli;
+ lparent(pi) = pli;
}
- pi = internal::find_root(parent, i);
- unsigned pri = internal::find_root(parent, right_link(i));
+ // Looking for new right link
+ pi = scribo::internal::find_root(lparent, i);
+ unsigned pri = scribo::internal::find_root(rparent, right_link(i));
if (pi != pri)
{
- if (pri < pi)
- parent(pri) = pi;
+ merged_link.update(i, right_link(i));
+ if (pi < pli)
+ lparent(pli) = pi;
else
- parent(pi) = pri;
+ lparent(pi) = pli;
}
}
- for_all_groups(g, parent)
- internal::find_root(parent, g);
+ object_groups<L> output(merged_link);
trace::exiting("scribo::primitive::group::from_double_link_any");
- return parent;
+ return output;
}
diff --git a/scribo/scribo/primitive/group/from_single_link.hh b/scribo/scribo/primitive/group/from_single_link.hh
index 05efdc7..0a2cca3 100644
--- a/scribo/scribo/primitive/group/from_single_link.hh
+++ b/scribo/scribo/primitive/group/from_single_link.hh
@@ -82,19 +82,6 @@ namespace scribo
mln_precondition(links.is_valid());
object_groups<L> parent(links);
- parent.init_(links);
-
- for_all_groups(i, parent)
- if (!links.components()(i).is_valid())
- parent(i) = 0;
- else
- ::scribo::primitive::internal::find_root(parent, i);
-
-
- // FIXME: useful?
- // Make sure the root is propagated.
- for_all_groups(g, parent)
- internal::find_root(parent, g);
trace::exiting("scribo::primitive::group::from_single_link");
return parent;
diff --git a/scribo/scribo/primitive/internal/is_link_valid.hh b/scribo/scribo/primitive/internal/is_link_valid.hh
index b18e55c..30823cb 100644
--- a/scribo/scribo/primitive/internal/is_link_valid.hh
+++ b/scribo/scribo/primitive/internal/is_link_valid.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -51,9 +51,8 @@ namespace scribo
/// \param[in] i The component id.
///
/// \return True if the link is between the \p i-th component
- /// and it neighbor is validated.
template <typename L>
- mln::util::couple<bool,unsigned>
+ bool
is_link_valid(const object_links<L>& left_link,
const object_links<L>& right_link,
unsigned i);
@@ -61,13 +60,12 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
template <typename L>
- mln::util::couple<bool,unsigned>
+ bool
is_link_valid(const object_links<L>& left_link,
const object_links<L>& right_link,
unsigned i)
{
- bool b = (right_link(left_link(i)) == i && left_link(i) != i);
- return mln::make::couple(b, left_link(i));
+ return left_link.is_linked(i) && right_link(left_link(i)) == i;
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/scribo/primitive/link/internal/link_functor_base.hh b/scribo/scribo/primitive/link/internal/link_functor_base.hh
index 11066c5..a509126 100644
--- a/scribo/scribo/primitive/link/internal/link_functor_base.hh
+++ b/scribo/scribo/primitive/link/internal/link_functor_base.hh
@@ -477,7 +477,7 @@ namespace scribo
{
(void) start_point;
(void) anchor;
- this->links_(current_object) = this->labeled_image_(p);
+ this->links_.update(current_object, this->labeled_image_(p));
}
diff --git a/scribo/scribo/primitive/link/internal/link_several_dmax_base.hh b/scribo/scribo/primitive/link/internal/link_several_dmax_base.hh
index 422eed9..08681c7 100644
--- a/scribo/scribo/primitive/link/internal/link_several_dmax_base.hh
+++ b/scribo/scribo/primitive/link/internal/link_several_dmax_base.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -248,15 +248,15 @@ namespace scribo
if (nratio == 1)
{
- this->links_(current_object)
- = labeled_image_(potential_links_(id_max_ratio).second());
+ this->links_.update(current_object,
+ labeled_image_(potential_links_(id_max_ratio).second()));
return potential_links_(id_max_ratio);
}
}
- this->links_(current_object) = current_object;
+ this->links_.clear(current_object);
return mln::make::couple(anchor::Invalid, P());
}
diff --git a/scribo/scribo/primitive/link/merge_double_link.hh b/scribo/scribo/primitive/link/merge_double_link.hh
index e58c1ab..2416a77 100644
--- a/scribo/scribo/primitive/link/merge_double_link.hh
+++ b/scribo/scribo/primitive/link/merge_double_link.hh
@@ -93,19 +93,20 @@ namespace scribo
const component_set<L>& components = left_link.components();
- object_links<L> merge = left_link.duplicate();
+ object_links<L> merge(components);
+ merge.init();
- for_all_ncomponents(i, components.nelements())
+ for_all_comps(i, components)
{
if (components(i).tag() == component::Ignored)
- merge(i) = 0;
+ merge.disable_linking(i);
else
{
- mln::util::couple<bool, unsigned>
- nbh = primitive::internal::is_link_valid(left_link,
- right_link, i);
- if (!nbh.first())
- merge(i) = i;
+ if (primitive::internal::is_link_valid(left_link,
+ right_link, i))
+ merge.update(i, left_link(i));
+ else
+ merge.clear(i);
}
}
diff --git a/scribo/scribo/primitive/link/merge_double_link_closest_aligned.hh b/scribo/scribo/primitive/link/merge_double_link_closest_aligned.hh
index 6c6e67f..d80fe85 100644
--- a/scribo/scribo/primitive/link/merge_double_link_closest_aligned.hh
+++ b/scribo/scribo/primitive/link/merge_double_link_closest_aligned.hh
@@ -129,14 +129,12 @@ namespace scribo
if (right(left(l)) == left(l))
{
- output(left(l)) = l;
- //output.update_link(left(l), l);
+ output.update(left(l), l);
}
else if ((dh < align_data(left(l)).first() * 0.66f)
|| (alpha < align_data(left(l)).second()))
{
- output(left(l)) = l;
- //output.update_link(left(l), l);
+ output.update(left(l), l);
align_data(left(l)).first() = dh;
align_data(left(l)).second() = alpha;
}
diff --git a/scribo/tests/filter/object_groups_mean_width.cc b/scribo/tests/filter/object_groups_mean_width.cc
index 81da661..751649d 100644
--- a/scribo/tests/filter/object_groups_mean_width.cc
+++ b/scribo/tests/filter/object_groups_mean_width.cc
@@ -45,8 +45,8 @@ int main()
std::string img = SCRIBO_IMG_DIR "/the_valleys.pbm";
- const unsigned ref[] = { 0, 1, 7, 3, 4, 3, 3, 7, 7, 3, 3, 3, 3 };
- const unsigned filtered_ref[] = { 0, 0, 7, 3, 0, 3, 3, 7, 7, 3, 3, 3, 3 };
+ const bool ref[] = { false, true, true, true, true };
+ const unsigned filtered_ref[] = { false, false, true, false, true };
image2d<bool> input;
io::pbm::load(input, img.c_str());
@@ -61,12 +61,13 @@ int main()
object_groups<L> groups = primitive::group::from_single_link(links);
+ mln_assertion(groups.nelements() == 5);
for_all_groups(g, groups)
- mln_assertion(groups(g) == ref[g]);
+ mln_assertion(groups(g).is_valid() == ref[g]);
groups = filter::object_groups_mean_width(groups, 10);
+ mln_assertion(groups.nelements() == 5);
for_all_groups(g, groups)
- mln_assertion(groups(g) == filtered_ref[g]);
-
+ mln_assertion(groups(g).is_valid() == filtered_ref[g]);
}
diff --git a/scribo/tests/filter/object_groups_size_ratio.cc b/scribo/tests/filter/object_groups_size_ratio.cc
index 90e353a..4051c71 100644
--- a/scribo/tests/filter/object_groups_size_ratio.cc
+++ b/scribo/tests/filter/object_groups_size_ratio.cc
@@ -45,8 +45,8 @@ int main()
std::string img = SCRIBO_IMG_DIR "/the_valleys.pbm";
- const unsigned ref[] = { 0, 1, 7, 3, 4, 3, 3, 7, 7, 3, 3, 3, 3 };
- const unsigned filtered_ref[] = { 0, 1, 0, 3, 0, 3, 3, 0, 0, 3, 3, 3, 3 };
+ const bool ref[] = { false, true, true, true, true };
+ const bool filtered_ref[] = { false, true, true, false, false };
image2d<bool> input;
io::pbm::load(input, img.c_str());
@@ -61,11 +61,13 @@ int main()
object_groups<L> groups = primitive::group::from_single_link(links);
+ mln_assertion(groups.nelements() == 5);
for_all_groups(g, groups)
- mln_assertion(groups(g) == ref[g]);
+ mln_assertion(groups(g).is_valid() == ref[g]);
groups = filter::object_groups_size_ratio(groups, 1.2, 0.3);
+ mln_assertion(groups.nelements() == 5);
for_all_groups(g, groups)
- mln_assertion(groups(g) == filtered_ref[g]);
+ mln_assertion(groups(g).is_valid() == filtered_ref[g]);
}
diff --git a/scribo/tests/filter/object_groups_small.cc b/scribo/tests/filter/object_groups_small.cc
index 165634d..9812b70 100644
--- a/scribo/tests/filter/object_groups_small.cc
+++ b/scribo/tests/filter/object_groups_small.cc
@@ -45,9 +45,9 @@ int main()
std::string img = SCRIBO_IMG_DIR "/the_valleys.pbm";
- const unsigned ref[] = { 0, 1, 7, 3, 4, 3, 3, 7, 7, 3, 3, 3, 3 };
- const unsigned filtered_ref[] = { 0, 0, 0, 3, 0, 3, 3, 0, 0, 3, 3, 3, 3 };
- const unsigned size_ref[] = { 0, 1, 0, 7, 1, 0, 0, 3, 0, 0, 0, 0, 0 };
+ const bool ref[] = { false, true, true, true, true };
+ const bool filtered_ref[] = { false, false, true, false, false };
+ const unsigned size_ref[] = { 0, 1, 7, 1, 3 };
image2d<bool> input;
@@ -63,25 +63,17 @@ int main()
object_groups<L> groups = primitive::group::from_single_link(links);
+ mln_assertion(groups.nelements() == 5);
for_all_groups(g, groups)
- mln_assertion(groups(g) == ref[g]);
+ mln_assertion(groups(g).is_valid() == ref[g]);
- {
- object_groups<L> groups2 = filter::object_groups_small(groups, 4);
-
- for_all_groups(g, groups2)
- mln_assertion(groups2(g) == filtered_ref[g]);
- }
+ object_groups<L> groups2 = filter::object_groups_small(groups, 4);
+ for_all_groups(g, groups2)
{
- mln::util::array<unsigned> group_size;
- object_groups<L> groups2 = filter::object_groups_small(groups, 4, group_size);
-
- for_all_groups(g, groups2)
- {
- mln_assertion(groups2(g) == filtered_ref[g]);
- mln_assertion(group_size(g) == size_ref[g]);
- }
+ mln_assertion(groups2(g).is_valid() == filtered_ref[g]);
+ mln_assertion(groups2(g).card() == size_ref[g]);
}
+
}
diff --git a/scribo/tests/filter/object_groups_with_holes.cc b/scribo/tests/filter/object_groups_with_holes.cc
index 3b5b29f..72f8464 100644
--- a/scribo/tests/filter/object_groups_with_holes.cc
+++ b/scribo/tests/filter/object_groups_with_holes.cc
@@ -45,8 +45,8 @@ int main()
std::string img = SCRIBO_IMG_DIR "/the_valleys.pbm";
- const unsigned ref[] = { 0, 1, 7, 3, 4, 3, 3, 7, 7, 3, 3, 3, 3 };
- const unsigned filtered_ref[] = { 0, 0, 7, 3, 0, 3, 3, 7, 7, 3, 3, 3, 3 };
+ const bool ref[] = { false, true, true, true, true };
+ const bool filtered_ref[] = { 0, false, true, true, false };
image2d<bool> input;
io::pbm::load(input, img.c_str());
@@ -61,11 +61,13 @@ int main()
object_groups<L> groups = primitive::group::from_single_link(links);
+ mln_assertion(groups.nelements() == 5);
for_all_groups(g, groups)
- mln_assertion(groups(g) == ref[g]);
+ mln_assertion(groups(g).is_valid() == ref[g]);
groups = filter::object_groups_with_holes(groups, 3);
+ mln_assertion(groups.nelements() == 5);
for_all_groups(g, groups)
- mln_assertion(groups(g) == filtered_ref[g]);
+ mln_assertion(groups(g).is_valid() == filtered_ref[g]);
}
--
1.5.6.5
1
0
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Olena, a generic and efficient image processing platform".
The branch coddy has been created
at f78df6e36baadcfbce50bb22a0cf84fa86ed750f (commit)
- Log -----------------------------------------------------------------
f78df6e disabled tesseract, debug functions added
-----------------------------------------------------------------------
hooks/post-receive
--
Olena, a generic and efficient image processing platform
1
0