* scribo/Makefile: add a new target.
* scribo/Makefile.am,
* scribo/scribo.mk,
* scribo/src/Makefile.am,
* scribo/tests/Makefile.am,
* scribo/tests/data.hh.in,
* scribo/tests/filter/Makefile.am,
* scribo/tests/text/Makefile.am,
* scribo/tests/table/Makefile.am: prepare build system integration.
* scribo/text/grouping/group_with_single_left_link.hh,
* scribo/text/grouping/group_with_single_right_link.hh,
* scribo/text/grouping/group_with_several_right_links.hh,
* scribo/text/grouping/group_with_several_left_links.hh,
* scribo/debug/save_linked_textbboxes_image.hh: do not compute mass
centers anymore.
* scribo/draw/bounding_box_links.hh: remove duplicate preconditions.
* scribo/tests/table/repair_lines.cc
* scribo/tests/filter/small_and_large_bboxes.cc
* scribo/tests/table/extract_lines_with_rank.cc
* scribo/src/table_rebuild_opening.cc
* scribo/src/table_rebuild_rank.cc
* scribo/src/table_extract.cc
* scribo/src/morpho.cc,
* scribo/filter/large_components.hh: fix.
* scribo/text/grouping/group_from_single_link.hh,
* scribo/text/grouping/group_from_double_link.hh,
* scribo/filter/thin_bboxes.hh,
* scribo/filter/small_components.hh: add a fixme.
* scribo/filter/thick_bboxes.hh: new routine.
* scribo/make/debug_filename.hh: use a std::string instead of a char*.
* scribo/make/text.hh: prepare a new routine.
* scribo/src/extract_text_double_several_links.cc: add timer info.
* scribo/src/extract_text_multiple_links.cc,,
* scribo/src/extract_text_several_multiple_links.cc,
* scribo/text/grouping/group_from_multiple_links.hh,
* scribo/text/grouping/group_with_multiple_links.hh,
* scribo/text/grouping/group_with_several_multiple_links.hh,
* scribo/text/grouping/internal/find_left_graph_link.hh,
* scribo/text/grouping/internal/update_link_graph.hh: rename as...
* scribo/src/extract_text_graph.cc,
* scribo/src/extract_text_several_graphes.cc,
* scribo/text/grouping/group_from_graph.hh,
* scribo/text/grouping/group_with_graph.hh,
* scribo/text/grouping/group_with_several_graphes.hh,
* scribo/text/grouping/internal/find_graph_link.hh,
* scribo/text/grouping/internal/update_graph_link.hh: ... this.
* scribo/src/photo_basic.cc: new sample code. Process text in photos.
* scribo/src/table_rebuild.cc: remove.
* scribo/text/extract_lines.hh: use double several links routines.
* scribo/util/text.hh: store the bbox mass centers.
---
milena/sandbox/ChangeLog | 70 +++++++++++++++++
milena/sandbox/scribo/Makefile | 3 +
milena/sandbox/scribo/Makefile.am | 6 ++
.../scribo/debug/save_linked_textbboxes_image.hh | 20 +----
milena/sandbox/scribo/draw/bounding_box_links.hh | 8 --
milena/sandbox/scribo/filter/large_components.hh | 67 ++++++++++-------
milena/sandbox/scribo/filter/small_components.hh | 1 +
.../filter/{thin_bboxes.hh => thick_bboxes.hh} | 57 +++++++-------
milena/sandbox/scribo/filter/thin_bboxes.hh | 1 +
milena/sandbox/scribo/make/debug_filename.hh | 6 +-
milena/sandbox/scribo/make/text.hh | 33 ++++++++
milena/sandbox/scribo/scribo.mk | 5 +
milena/sandbox/scribo/src/Makefile.am | 33 ++++++++
.../src/extract_text_double_several_links.cc | 27 +++++++
...ext_multiple_links.cc => extract_text_graph.cc} | 10 +-
...iple_links.cc => extract_text_several_graph.cc} | 10 +-
milena/sandbox/scribo/src/morpho.cc | 2 +-
...text_double_several_links.cc => photo_basic.cc} | 61 +++++++++-------
milena/sandbox/scribo/src/table_extract.cc | 2 +-
milena/sandbox/scribo/src/table_rebuild.cc | 79 --------------------
milena/sandbox/scribo/src/table_rebuild_opening.cc | 3 +-
milena/sandbox/scribo/src/table_rebuild_rank.cc | 3 +-
milena/sandbox/scribo/tests/Makefile.am | 7 ++
.../{src/table_extract.cc => tests/data.hh.in} | 46 ++---------
milena/sandbox/scribo/tests/filter/Makefile.am | 10 +++
.../scribo/tests/filter/small_and_large_bboxes.cc | 45 +++++++-----
milena/sandbox/scribo/tests/table/Makefile.am | 12 +++
.../scribo/tests/table/extract_lines_with_rank.cc | 47 ++++++++++--
milena/sandbox/scribo/tests/table/repair_lines.cc | 43 +++++++++--
milena/sandbox/scribo/tests/text/Makefile.am | 7 ++
milena/sandbox/scribo/text/extract_lines.hh | 26 ++++---
.../scribo/text/grouping/group_from_double_link.hh | 1 +
..._from_multiple_links.hh => group_from_graph.hh} | 21 +++---
.../scribo/text/grouping/group_from_single_link.hh | 1 +
..._with_multiple_links.hh => group_with_graph.hh} | 46 ++++--------
...iple_links.hh => group_with_several_graphes.hh} | 37 +++++-----
.../text/grouping/group_with_several_left_links.hh | 27 +++----
.../grouping/group_with_several_right_links.hh | 27 +++----
.../text/grouping/group_with_single_left_link.hh | 6 +-
.../text/grouping/group_with_single_right_link.hh | 6 +-
...{find_left_graph_link.hh => find_graph_link.hh} | 49 +++++++-----
.../{update_link_graph.hh => update_graph_link.hh} | 22 ++++--
milena/sandbox/scribo/util/text.hh | 59 ++++++++++++--
43 files changed, 628 insertions(+), 424 deletions(-)
create mode 100644 milena/sandbox/scribo/Makefile.am
copy milena/sandbox/scribo/filter/{thin_bboxes.hh => thick_bboxes.hh} (72%)
create mode 100644 milena/sandbox/scribo/scribo.mk
create mode 100644 milena/sandbox/scribo/src/Makefile.am
rename milena/sandbox/scribo/src/{extract_text_multiple_links.cc =>
extract_text_graph.cc} (91%)
rename milena/sandbox/scribo/src/{extract_text_several_multiple_links.cc =>
extract_text_several_graph.cc} (90%)
copy milena/sandbox/scribo/src/{extract_text_double_several_links.cc =>
photo_basic.cc} (60%)
delete mode 100644 milena/sandbox/scribo/src/table_rebuild.cc
create mode 100644 milena/sandbox/scribo/tests/Makefile.am
copy milena/sandbox/scribo/{src/table_extract.cc => tests/data.hh.in} (56%)
create mode 100644 milena/sandbox/scribo/tests/filter/Makefile.am
create mode 100644 milena/sandbox/scribo/tests/table/Makefile.am
create mode 100644 milena/sandbox/scribo/tests/text/Makefile.am
rename milena/sandbox/scribo/text/grouping/{group_from_multiple_links.hh =>
group_from_graph.hh} (87%)
rename milena/sandbox/scribo/text/grouping/{group_with_multiple_links.hh =>
group_with_graph.hh} (63%)
rename milena/sandbox/scribo/text/grouping/{group_with_several_multiple_links.hh =>
group_with_several_graphes.hh} (71%)
rename milena/sandbox/scribo/text/grouping/internal/{find_left_graph_link.hh =>
find_graph_link.hh} (68%)
rename milena/sandbox/scribo/text/grouping/internal/{update_link_graph.hh =>
update_graph_link.hh} (79%)
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 59c395c..1290810 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,3 +1,73 @@
+2009-03-25 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Update Scribo's code.
+
+ * scribo/Makefile: add a new target.
+
+ * scribo/Makefile.am,
+ * scribo/scribo.mk,
+ * scribo/src/Makefile.am,
+ * scribo/tests/Makefile.am,
+ * scribo/tests/data.hh.in,
+ * scribo/tests/filter/Makefile.am,
+ * scribo/tests/text/Makefile.am,
+ * scribo/tests/table/Makefile.am: prepare build system integration.
+
+ * scribo/text/grouping/group_with_single_left_link.hh,
+ * scribo/text/grouping/group_with_single_right_link.hh,
+ * scribo/text/grouping/group_with_several_right_links.hh,
+ * scribo/text/grouping/group_with_several_left_links.hh,
+ * scribo/debug/save_linked_textbboxes_image.hh: do not compute mass
+ centers anymore.
+
+ * scribo/draw/bounding_box_links.hh: remove duplicate preconditions.
+
+ * scribo/tests/table/repair_lines.cc
+ * scribo/tests/filter/small_and_large_bboxes.cc
+ * scribo/tests/table/extract_lines_with_rank.cc
+ * scribo/src/table_rebuild_opening.cc
+ * scribo/src/table_rebuild_rank.cc
+ * scribo/src/table_extract.cc
+ * scribo/src/morpho.cc,
+ * scribo/filter/large_components.hh: fix.
+
+ * scribo/text/grouping/group_from_single_link.hh,
+ * scribo/text/grouping/group_from_double_link.hh,
+ * scribo/filter/thin_bboxes.hh,
+ * scribo/filter/small_components.hh: add a fixme.
+
+ * scribo/filter/thick_bboxes.hh: new routine.
+
+ * scribo/make/debug_filename.hh: use a std::string instead of a char*.
+
+ * scribo/make/text.hh: prepare a new routine.
+
+ * scribo/src/extract_text_double_several_links.cc: add timer info.
+
+ * scribo/src/extract_text_multiple_links.cc,,
+ * scribo/src/extract_text_several_multiple_links.cc,
+ * scribo/text/grouping/group_from_multiple_links.hh,
+ * scribo/text/grouping/group_with_multiple_links.hh,
+ * scribo/text/grouping/group_with_several_multiple_links.hh,
+ * scribo/text/grouping/internal/find_left_graph_link.hh,
+ * scribo/text/grouping/internal/update_link_graph.hh: rename as...
+
+ * scribo/src/extract_text_graph.cc,
+ * scribo/src/extract_text_several_graphes.cc,
+ * scribo/text/grouping/group_from_graph.hh,
+ * scribo/text/grouping/group_with_graph.hh,
+ * scribo/text/grouping/group_with_several_graphes.hh,
+ * scribo/text/grouping/internal/find_graph_link.hh,
+ * scribo/text/grouping/internal/update_graph_link.hh: ... this.
+
+ * scribo/src/photo_basic.cc: new sample code. Process text in photos.
+
+ * scribo/src/table_rebuild.cc: remove.
+
+ * scribo/text/extract_lines.hh: use double several links routines.
+
+ * scribo/util/text.hh: store the bbox mass centers.
+
2009-03-25 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Update Fabien' sandbox.
diff --git a/milena/sandbox/scribo/Makefile b/milena/sandbox/scribo/Makefile
index 3c3e1a5..d8b9a68 100644
--- a/milena/sandbox/scribo/Makefile
+++ b/milena/sandbox/scribo/Makefile
@@ -55,6 +55,9 @@ table_erase:
thin_bboxes:
g++ $(CXX_FLAGS) src/thin_bboxes.cc -o bin/thin_bboxes.out
+photo_basic:
+ g++ $(CXX_FLAGS) src/photo_basic.cc -o bin/photo_basic.out
+
clean:
rm *.ppm *.pgm *.pbm
diff --git a/milena/sandbox/scribo/Makefile.am b/milena/sandbox/scribo/Makefile.am
new file mode 100644
index 0000000..bf33f79
--- /dev/null
+++ b/milena/sandbox/scribo/Makefile.am
@@ -0,0 +1,6 @@
+SUBDIRS = tests
+
+.PHONY: bin
+
+bin:
+ make -C src
diff --git a/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh
b/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh
index e7d2a40..1b53262 100644
--- a/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh
+++ b/milena/sandbox/scribo/debug/save_linked_textbboxes_image.hh
@@ -119,11 +119,8 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input);
- mln::util::array<mln_site(I)::vec> mass_centers
- = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
-
draw::bounding_boxes(tmp, text.bboxes(), box_value);
- draw::bounding_box_links(tmp, mass_centers, link_array, link_value);
+ draw::bounding_box_links(tmp, text.mass_centers(), link_array, link_value);
io::ppm::save(tmp, filename);
@@ -147,11 +144,8 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input);
- mln::util::array<mln_site(I)::vec> mass_centers
- = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
-
draw::bounding_boxes(tmp, text.bboxes(), box_value);
- draw::bounding_box_links(tmp, mass_centers,
+ draw::bounding_box_links(tmp, text.mass_centers(),
left_link, right_link,
value);
@@ -179,11 +173,8 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input);
- mln::util::array<mln_site(I)::vec> mass_centers
- = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
-
draw::bounding_boxes(tmp, text.bboxes(), box_value);
- draw::bounding_box_links(tmp, mass_centers,
+ draw::bounding_box_links(tmp, text.mass_centers(),
left_link, right_link,
left_link_value, right_link_value,
validated_link_value);
@@ -211,10 +202,7 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = level::convert(value::rgb8(), input);
- mln::util::array<mln_site(I)::vec> mass_centers
- = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
-
- draw::bounding_boxes(tmp, mass_centers, box_value);
+ draw::bounding_boxes(tmp, text.bboxes(), box_value);
draw::bounding_box_links(tmp, text.bboxes(), g, link_value);
io::ppm::save(tmp, filename);
diff --git a/milena/sandbox/scribo/draw/bounding_box_links.hh
b/milena/sandbox/scribo/draw/bounding_box_links.hh
index 5d695f6..b7f410a 100644
--- a/milena/sandbox/scribo/draw/bounding_box_links.hh
+++ b/milena/sandbox/scribo/draw/bounding_box_links.hh
@@ -230,10 +230,8 @@ namespace scribo
const mln_value(I)& value)
{
trace::entering("scribo::draw::bounding_box_links");
- mln_precondition(exact(input).is_valid());
I& input = exact(input_);
-
mln_precondition(input.is_valid());
for_all_components(i, left_link)
@@ -259,10 +257,8 @@ namespace scribo
const mln_value(I)& value)
{
trace::entering("scribo::draw::bounding_box_links");
- mln_precondition(exact(input).is_valid());
I& input = exact(input_);
-
mln_precondition(input.is_valid());
for_all_components(i, left_link)
@@ -292,10 +288,8 @@ namespace scribo
const mln_value(I)& validated_link_value)
{
trace::entering("scribo::draw::bounding_box_links");
- mln_precondition(exact(input).is_valid());
I& input = exact(input_);
-
mln_precondition(input.is_valid());
mln_site(I)::vec dleft = literal::origin;
@@ -339,10 +333,8 @@ namespace scribo
const mln_value(I)& validated_link_value)
{
trace::entering("scribo::draw::bounding_box_links");
- mln_precondition(exact(input).is_valid());
I& input = exact(input_);
-
mln_precondition(input.is_valid());
mln_site(I)::vec dleft = literal::origin;
diff --git a/milena/sandbox/scribo/filter/large_components.hh
b/milena/sandbox/scribo/filter/large_components.hh
index 9ea4e02..7b4964b 100644
--- a/milena/sandbox/scribo/filter/large_components.hh
+++ b/milena/sandbox/scribo/filter/large_components.hh
@@ -70,20 +70,17 @@ namespace scribo
const V& label_type,
unsigned max_size);
-
- /// Remove large bboxes in a binary image.
- /// Set to 'false' all the removed bboxes.
+ /// Remove too large text components.
///
- /// \param[in] input_ A binary image.
- /// \param[in] bboxes Bounding boxes of components extracted from \p
- /// input_.
- /// \param[in] max_size The minimum cardinality of a component.
+ /// \param[in] text Text data.
+ /// \param[in] min_size The minimum cardinality of a component.
///
- /// \return A binary image without large bboxes.
- template <typename P>
- util::array< box<P> >
- large_components(const util::array< box<P> >& bboxes,
- unsigned max_size);
+ /// \return updated text data.
+ template <typename I>
+ scribo::util::text<I>
+ small_components(const scribo::util::text<I>& text,
+ unsigned min_size);
+
# ifndef MLN_INCLUDE_ONLY
@@ -97,9 +94,9 @@ namespace scribo
/// large.
template <typename R>
struct filter_large_components_functor
- : Function_l2b< filter_large_and_large_functor<R> >
+ : Function_l2b< filter_large_components_functor<R> >
{
- filter_large_components_functor(const util::array<R>& nsitecomp,
+ filter_large_components_functor(const mln::util::array<R>& nsitecomp,
unsigned max_size)
: nsitecomp_(nsitecomp), max_size_(max_size)
{
@@ -114,7 +111,7 @@ namespace scribo
}
- const util::array<R>& nsitecomp_;
+ const mln::util::array<R>& nsitecomp_;
unsigned max_size_;
};
@@ -144,10 +141,10 @@ namespace scribo
typedef accu::count<mln_psite(I)> accu_count_t;
typedef mln_result(accu_count_t) accu_count_res_t;
- typedef util::array<accu_count_res_t> nsitecomp_t;
+ typedef mln::util::array<accu_count_res_t> nsitecomp_t;
nsitecomp_t nsitecomp = labeling::compute(accu_count_t(), lbl, nlabels);
- typedef internal::filter_large_and_large_functor<accu_count_res_t> func_t;
+ typedef internal::filter_large_components_functor<accu_count_res_t> func_t;
func_t fl2b(nsitecomp, max_size);
labeling::relabel_inplace(lbl, nlabels, fl2b);
@@ -159,31 +156,45 @@ namespace scribo
}
- template <typename P>
+ template <typename I>
inline
- util::array< box<P> >
- large_components(const util::array< box<P> >& bboxes,
+ scribo::util::text<I>
+ large_components(const scribo::util::text<I>& text,
unsigned max_size)
{
trace::entering("scribo::filter::large_components");
- mln_precondition(input.is_valid());
+ mln_precondition(text.is_valid());
+ typedef mln_site(I) P;
typedef accu::count<P> accu_count_t;
typedef mln_result(accu_count_t) accu_count_res_t;
- typedef util::array<accu_count_res_t> nsitecomp_t;
+ typedef mln::util::array<accu_count_res_t> nsitecomp_t;
- util::array<box<P> > result;
- result.append(box<P>());
- for_all_components(i, bboxes)
+ fun::i2v::array<bool> f(text.nbboxes().next(), false);
+ f(0) = true;
+ mln::util::array<box<P> > bresult;
+ bresult.append(box<P>());
+ for_all_components(i, text.bboxes())
{
- accu_count_res_t count = set::compute(accu_count_t(), bboxes[i]);
+ accu_count_res_t count = set::compute(accu_count_t(), text.bbox(i));
if (count <= max_size)
- result.append(bboxes[i]);
+ {
+ bresult.append(text.bbox(i));
+ f(i) = true;
+ }
}
+ mln_value(I) new_nbboxes;
+ I new_lbl = labeling::relabel(text.label_image(), text.nbboxes(),
+ mln::make::relabelfun(f, text.nbboxes(),
+ new_nbboxes));
+
+ mln_assertion(new_nbboxes.next() == bresult.nelements());
+
trace::exiting("scribo::filter::large_components");
- return result;
+ /// FIXME: construct a new util::text from the old one.
+ return scribo::make::text(bresult, new_lbl, new_nbboxes);
}
diff --git a/milena/sandbox/scribo/filter/small_components.hh
b/milena/sandbox/scribo/filter/small_components.hh
index fb8ff5a..55ee9b1 100644
--- a/milena/sandbox/scribo/filter/small_components.hh
+++ b/milena/sandbox/scribo/filter/small_components.hh
@@ -198,6 +198,7 @@ namespace scribo
mln_assertion(new_nbboxes.next() == bresult.nelements());
trace::exiting("scribo::filter::small_components");
+ /// FIXME: construct a new util::text from the old one.
return scribo::make::text(bresult, new_lbl, new_nbboxes);
}
diff --git a/milena/sandbox/scribo/filter/thin_bboxes.hh
b/milena/sandbox/scribo/filter/thick_bboxes.hh
similarity index 72%
copy from milena/sandbox/scribo/filter/thin_bboxes.hh
copy to milena/sandbox/scribo/filter/thick_bboxes.hh
index de99242..006065b 100644
--- a/milena/sandbox/scribo/filter/thin_bboxes.hh
+++ b/milena/sandbox/scribo/filter/thick_bboxes.hh
@@ -25,12 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef SCRIBO_FILTER_THIN_BBOXES_HH
-# define SCRIBO_FILTER_THIN_BBOXES_HH
+#ifndef SCRIBO_FILTER_THICK_BBOXES_HH
+# define SCRIBO_FILTER_THICK_BBOXES_HH
-/// \file scribo/filter/thin_bboxes.hh
+/// \file scribo/filter/thick_bboxes.hh
///
-/// Remove too thin bboxes.
+/// Remove too thick bboxes.
# include <mln/labeling/blobs.hh>
# include <mln/labeling/compute.hh>
@@ -53,27 +53,27 @@ namespace scribo
/// Filter Functor. Return false for all components which are too
/// large.
template <typename R>
- struct filter_too_thin_component_functor
- : Function_l2b< filter_too_thin_component_functor<R> >
+ struct filter_too_thick_component_functor
+ : Function_l2b< filter_too_thick_component_functor<R> >
{
- filter_too_thin_component_functor(const mln::util::array<R>& compbboxes,
- unsigned min_thickness)
- : compbboxes_(compbboxes), min_thickness_(min_thickness)
+ filter_too_thick_component_functor(const mln::util::array<R>& compbboxes,
+ unsigned max_thickness)
+ : compbboxes_(compbboxes), max_thickness_(max_thickness)
{
}
- /// Return false if the components is thinner than
- /// \p min_thickness_.
+ /// Return false if the components is thickner than
+ /// \p max_thickness_.
bool operator()(const value::label_16& l) const
{
- return compbboxes_[l].nrows() > min_thickness_
- && compbboxes_[l].ncols() > min_thickness_;
+ return compbboxes_[l].nrows() < max_thickness_
+ && compbboxes_[l].ncols() < max_thickness_;
}
const mln::util::array<R>& compbboxes_;
- unsigned min_thickness_;
+ unsigned max_thickness_;
};
@@ -83,12 +83,12 @@ namespace scribo
template <typename I, typename N, typename V>
inline
mln_concrete(I)
- thin_bboxes(const Image<I>& input_,
+ thick_bboxes(const Image<I>& input_,
const Neighborhood<N>& nbh_,
const V& label_type,
- unsigned min_thickness)
+ unsigned max_thickness)
{
- trace::entering("scribo::filter::thin_bboxes");
+ trace::entering("scribo::filter::thick_bboxes");
const I& input = exact(input_);
const N& nbh = exact(nbh_);
@@ -104,14 +104,14 @@ namespace scribo
typedef mln::util::array<accu_bbox_res_t> compbboxes_t;
compbboxes_t compbboxes = labeling::compute(accu_bbox_t(), lbl, nlabels);
- typedef internal::filter_too_thin_component_functor<accu_bbox_res_t> func_t;
- func_t fl2b(compbboxes, min_thickness);
+ typedef internal::filter_too_thick_component_functor<accu_bbox_res_t>
func_t;
+ func_t fl2b(compbboxes, max_thickness);
labeling::relabel_inplace(lbl, nlabels, fl2b);
mln_concrete(I) output = duplicate(input);
data::fill((output | pw::value(lbl) == literal::zero).rw(), false);
- trace::exiting("scribo::filter::thin_bboxes");
+ trace::exiting("scribo::filter::thick_bboxes");
return output;
}
@@ -119,10 +119,10 @@ namespace scribo
template <typename L>
inline
scribo::util::text<L>
- thin_bboxes(const scribo::util::text<L>& text,
- unsigned min_thickness)
+ thick_bboxes(const scribo::util::text<L>& text,
+ unsigned max_thickness)
{
- trace::entering("scribo::filter::thin_bboxes");
+ trace::entering("scribo::filter::thick_bboxes");
mln_precondition(text.is_valid());
@@ -131,15 +131,15 @@ namespace scribo
typedef mln_result(accu_bbox_t) accu_bbox_res_t;
typedef mln::util::array<accu_bbox_res_t> nsitecomp_t;
- typedef internal::filter_too_thin_component_functor<accu_bbox_res_t> func_t;
- func_t is_not_too_thin(text.bboxes(), min_thickness);
+ typedef internal::filter_too_thick_component_functor<accu_bbox_res_t>
func_t;
+ func_t is_not_too_thick(text.bboxes(), max_thickness);
fun::i2v::array<bool> f(text.nbboxes().next(), false);
f(0) = true;
mln::util::array<box<P> > bresult;
bresult.append(box<P>());
for_all_components(i, text.bboxes())
- if (is_not_too_thin(i))
+ if (is_not_too_thick(i))
{
bresult.append(text.bbox(i));
f(i) = true;
@@ -151,7 +151,8 @@ namespace scribo
mln_assertion(new_nbboxes.next() == bresult.nelements());
- trace::exiting("scribo::filter::thin_bboxes");
+ trace::exiting("scribo::filter::thick_bboxes");
+ /// FIXME: construct a new util::text from the old one.
return scribo::make::text(bresult, new_lbl, new_nbboxes);
}
@@ -162,4 +163,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_FILTER_THIN_BBOXES_HH
+#endif // ! SCRIBO_FILTER_THICK_BBOXES_HH
diff --git a/milena/sandbox/scribo/filter/thin_bboxes.hh
b/milena/sandbox/scribo/filter/thin_bboxes.hh
index de99242..30d7bb9 100644
--- a/milena/sandbox/scribo/filter/thin_bboxes.hh
+++ b/milena/sandbox/scribo/filter/thin_bboxes.hh
@@ -152,6 +152,7 @@ namespace scribo
mln_assertion(new_nbboxes.next() == bresult.nelements());
trace::exiting("scribo::filter::thin_bboxes");
+ /// FIXME: construct a new util::text from the old one.
return scribo::make::text(bresult, new_lbl, new_nbboxes);
}
diff --git a/milena/sandbox/scribo/make/debug_filename.hh
b/milena/sandbox/scribo/make/debug_filename.hh
index 5a9728c..839255c 100644
--- a/milena/sandbox/scribo/make/debug_filename.hh
+++ b/milena/sandbox/scribo/make/debug_filename.hh
@@ -56,7 +56,7 @@ namespace scribo
{
/// Set the default debug filename prefix.
- extern char *debug_filename_prefix;
+ extern std::string debug_filename_prefix;
} // end of namespace scribo::make::internal
@@ -67,7 +67,7 @@ namespace scribo
namespace internal
{
- char *debug_filename_prefix = 0;
+ std::string debug_filename_prefix = "";
} // end of namespace scribo::make::internal
@@ -80,7 +80,7 @@ namespace scribo
std::ostringstream os;
- if (internal::debug_filename_prefix != 0)
+ if (! internal::debug_filename_prefix.empty())
os << internal::debug_filename_prefix << "_";
else
mln::trace::warning("You may like to set a default filename prefix.");
diff --git a/milena/sandbox/scribo/make/text.hh b/milena/sandbox/scribo/make/text.hh
index 3c32ad0..c4a8a09 100644
--- a/milena/sandbox/scribo/make/text.hh
+++ b/milena/sandbox/scribo/make/text.hh
@@ -105,6 +105,39 @@ namespace scribo
return make::text(cboxes, lbl, nbboxes);
}
+ //FIXME: we want the following routine to construct a new util::text
+ // from another one and a relabeling function. It avoid recomputing
+ // the whole underlying data (mass centers, bboxes...)
+// template <typename L>
+// scribo::util::text<L>
+// text(const scribo::util::text<L>& text,
+// const Function_v2v<F>& f)
+// {
+// trace::entering("scribo::make::text");
+//
+// mln_precondition(text.is_valid());
+//
+// mln_value(L) new_nbboxes;
+// mln::fun::l2l::relabel<mln_value(L)> fl2l
+// = mln::make::relabelfun(f, nbboxes_, new_nbboxes);
+// lbl_ = labeling::relabel(lbl_, nbboxes_, l2l);
+// nbboxes_ = new_nbboxes;
+//
+// mln::util::array< accu::bbox<mln_site(I)> > tboxes(nbboxes_);
+// mln::util::array< accu::center<mln_site(I)> > tcenters(nbboxes_);
+// for_all_components(i, text.bboxes())
+// {
+// abboxes[fl2l(i)].take(text.bbox(i));
+// acenters[fl2l(i)].take(text.bbox(i));
+// }
+// convert::from_to(abboxes, text.bboxes());
+// convert::from_to(acenters, text.mass_centers_);
+//
+// trace::exiting("scribo::make::text");
+// return scribo::util::text<L>(;
+// }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::make
diff --git a/milena/sandbox/scribo/scribo.mk b/milena/sandbox/scribo/scribo.mk
new file mode 100644
index 0000000..13b617a
--- /dev/null
+++ b/milena/sandbox/scribo/scribo.mk
@@ -0,0 +1,5 @@
+include $(top_srcdir)/milena/tests/tests.mk
+
+# Add path to Scribo's headers
+AM_CPPFLAGS += -I$(top_srcdir)/milena/sandbox/ -I$(top_builddir)/milena/sandbox/
+
diff --git a/milena/sandbox/scribo/src/Makefile.am
b/milena/sandbox/scribo/src/Makefile.am
new file mode 100644
index 0000000..805ce84
--- /dev/null
+++ b/milena/sandbox/scribo/src/Makefile.am
@@ -0,0 +1,33 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/sandbox/scribo/scribo.mk
+
+bin_PROGRAMS = \
+ dmap \
+ extract_text_single_link \
+ table_erase \
+ extract_text_double_link \
+ table_extract \
+ extract_text_double_several_links \
+ morpho \
+ extract_text_graph \
+ table_rebuild_opening \
+ extract_text_several_graph \
+ table_rebuild_rank \
+ extract_text_several_left_links \
+ thin_bboxes
+
+dmap_SOURCES = dmap.cc
+extract_text_single_link_SOURCES = extract_text_single_link.cc
+table_erase_SOURCES = table_erase.cc
+extract_text_double_link_SOURCES = extract_text_double_link.cc
+table_extract_SOURCES = table_extract.cc
+extract_text_double_several_links_SOURCES = extract_text_double_several_links.cc
+morpho_SOURCES = morpho.cc
+extract_text_graph_SOURCES = extract_text_graph.cc
+table_rebuild_opening_SOURCES = table_rebuild_opening.cc
+extract_text_several_graph_SOURCES = extract_text_several_graph.cc
+table_rebuild_rank_SOURCES = table_rebuild_rank.cc
+extract_text_several_left_links_SOURCES = extract_text_several_left_links.cc
+thin_bboxes_SOURCES = thin_bboxes.cc
+
diff --git a/milena/sandbox/scribo/src/extract_text_double_several_links.cc
b/milena/sandbox/scribo/src/extract_text_double_several_links.cc
index ee7d384..1fead0a 100644
--- a/milena/sandbox/scribo/src/extract_text_double_several_links.cc
+++ b/milena/sandbox/scribo/src/extract_text_double_several_links.cc
@@ -29,6 +29,7 @@
#include <mln/essential/2d.hh>
#include <mln/debug/colorize.hh>
+#include <mln/util/timer.hh>
#include <scribo/text/extract_bboxes.hh>
#include <scribo/text/grouping/group_with_several_left_links.hh>
@@ -57,19 +58,40 @@ int main(int argc, char* argv[])
scribo::make::internal::debug_filename_prefix =
"extract_text_double_several_links";
+ mln::util::timer t, t2;
image2d<bool> input;
+ std::cout << "Loading" << std::endl;
+ t.start();
io::pbm::load(input, argv[1]);
+ std::cout << t << std::endl;
+
value::label_16 nbboxes;
+ std::cout << "extract bboxes" << std::endl;
+ t.restart();
+ t2.start();
scribo::util::text<image2d<value::label_16> > text
= text::extract_bboxes(input, c8(), nbboxes);
+ std::cout << t << std::endl;
+ mln::util::timer t3;
+ std::cout << "Remove small components" << std::endl;
+ t.restart();
+ t3.start();
text = filter::small_components(text,4);
+ std::cout << t << std::endl;
+ std::cout << "Group with left link" << std::endl;
+ t.restart();
mln::util::array<unsigned> left_link
= text::grouping::group_with_several_left_links(text, 30);
+ std::cout << t << std::endl;
+
+ std::cout << "Group with right link" << std::endl;
+ t.restart();
mln::util::array<unsigned> right_link
= text::grouping::group_with_several_right_links(text, 30);
+ std::cout << t << std::endl;
std::cout << "BEFORE - nbboxes = " << nbboxes <<
std::endl;
@@ -80,8 +102,13 @@ int main(int argc, char* argv[])
scribo::make::debug_filename("links.ppm"));
// With validation.
+ std::cout << "Group from double link" << std::endl;
+ t.restart();
scribo::util::text<image2d<value::label_16> > grouped_text
= text::grouping::group_from_double_link(text, left_link, right_link);
+ std::cout << t << std::endl;
+ std::cout << "Full process: " << t2 << std::endl;
+ std::cout << "Cleanup and grouping process: " << t3 <<
std::endl;
io::ppm::save(mln::debug::colorize(value::rgb8(),
grouped_text.label_image(),
diff --git a/milena/sandbox/scribo/src/extract_text_multiple_links.cc
b/milena/sandbox/scribo/src/extract_text_graph.cc
similarity index 91%
rename from milena/sandbox/scribo/src/extract_text_multiple_links.cc
rename to milena/sandbox/scribo/src/extract_text_graph.cc
index eacef81..fdcf54b 100644
--- a/milena/sandbox/scribo/src/extract_text_multiple_links.cc
+++ b/milena/sandbox/scribo/src/extract_text_graph.cc
@@ -30,8 +30,8 @@
#include <mln/essential/2d.hh>
#include <scribo/text/extract_bboxes.hh>
-#include <scribo/text/grouping/group_with_multiple_links.hh>
-#include <scribo/text/grouping/group_from_multiple_links.hh>
+#include <scribo/text/grouping/group_with_graph.hh>
+#include <scribo/text/grouping/group_from_graph.hh>
#include <scribo/debug/save_textbboxes_image.hh>
#include <scribo/debug/save_linked_textbboxes_image.hh>
@@ -51,7 +51,7 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix =
"extract_text_multiple_links";
+ scribo::make::internal::debug_filename_prefix = "extract_text_graph";
image2d<bool> input;
io::pbm::load(input, argv[1]);
@@ -60,7 +60,7 @@ int main(int argc, char* argv[])
scribo::util::text<image2d<value::label_16> > text
= text::extract_bboxes(input, c8(), nbboxes);
- mln::util::graph g = text::grouping::group_with_multiple_links(text, 30);
+ mln::util::graph g = text::grouping::group_with_graph(text, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes.next() <<
std::endl;
scribo::debug::save_linked_textbboxes_image(input,
@@ -73,7 +73,7 @@ int main(int argc, char* argv[])
// scribo::make::debug_filename("lbl_before.ppm"));
scribo::util::text<image2d<value::label_16> > grouped_text
- = text::grouping::group_from_multiple_links(text, g);
+ = text::grouping::group_from_graph(text, g);
std::cout << "AFTER - nbboxes = " <<
grouped_text.bboxes().nelements() << std::endl;
diff --git a/milena/sandbox/scribo/src/extract_text_several_multiple_links.cc
b/milena/sandbox/scribo/src/extract_text_several_graph.cc
similarity index 90%
rename from milena/sandbox/scribo/src/extract_text_several_multiple_links.cc
rename to milena/sandbox/scribo/src/extract_text_several_graph.cc
index 3c85c20..8c84bc9 100644
--- a/milena/sandbox/scribo/src/extract_text_several_multiple_links.cc
+++ b/milena/sandbox/scribo/src/extract_text_several_graph.cc
@@ -30,8 +30,8 @@
#include <mln/essential/2d.hh>
#include <scribo/text/extract_bboxes.hh>
-#include <scribo/text/grouping/group_with_several_multiple_links.hh>
-#include <scribo/text/grouping/group_from_multiple_links.hh>
+#include <scribo/text/grouping/group_with_several_graphes.hh>
+#include <scribo/text/grouping/group_from_graph.hh>
#include <scribo/debug/save_textbboxes_image.hh>
#include <scribo/debug/save_linked_textbboxes_image.hh>
@@ -51,7 +51,7 @@ int main(int argc, char* argv[])
if (argc < 1)
return usage(argv[0]);
- scribo::make::internal::debug_filename_prefix =
"extract_text_several_multiple_links";
+ scribo::make::internal::debug_filename_prefix =
"extract_text_several_graph";
image2d<bool> input;
io::pbm::load(input, argv[1]);
@@ -60,7 +60,7 @@ int main(int argc, char* argv[])
scribo::util::text<image2d<value::label_16> > text
= text::extract_bboxes(input, c8(), nbboxes);
- mln::util::graph g = text::grouping::group_with_several_multiple_links(text, 30);
+ mln::util::graph g = text::grouping::group_with_several_graphes(text, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes.next() <<
std::endl;
scribo::debug::save_linked_textbboxes_image(input,
@@ -69,7 +69,7 @@ int main(int argc, char* argv[])
scribo::make::debug_filename("left_linked.ppm"));
scribo::util::text<image2d<value::label_16> > grouped_text
- = text::grouping::group_from_multiple_links(text, g);
+ = text::grouping::group_from_graph(text, g);
std::cout << "AFTER - nbboxes = " <<
grouped_text.bboxes().nelements() << std::endl;
diff --git a/milena/sandbox/scribo/src/morpho.cc b/milena/sandbox/scribo/src/morpho.cc
index a527a3d..27b9f98 100644
--- a/milena/sandbox/scribo/src/morpho.cc
+++ b/milena/sandbox/scribo/src/morpho.cc
@@ -61,4 +61,4 @@ int main(int argc, char *argv[])
scribo::make::debug_filename("wsd_disk_51.ppm"));
}
-???
+}
diff --git a/milena/sandbox/scribo/src/extract_text_double_several_links.cc
b/milena/sandbox/scribo/src/photo_basic.cc
similarity index 60%
copy from milena/sandbox/scribo/src/extract_text_double_several_links.cc
copy to milena/sandbox/scribo/src/photo_basic.cc
index ee7d384..baba806 100644
--- a/milena/sandbox/scribo/src/extract_text_double_several_links.cc
+++ b/milena/sandbox/scribo/src/photo_basic.cc
@@ -28,17 +28,20 @@
#include <iostream>
#include <mln/essential/2d.hh>
-#include <mln/debug/colorize.hh>
#include <scribo/text/extract_bboxes.hh>
-#include <scribo/text/grouping/group_with_several_left_links.hh>
-#include <scribo/text/grouping/group_with_several_right_links.hh>
-#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/text/grouping/group_with_single_left_link.hh>
+#include <scribo/text/grouping/group_with_single_right_link.hh>
#include <scribo/text/grouping/group_from_double_link.hh>
#include <scribo/filter/small_components.hh>
+#include <scribo/filter/large_components.hh>
+#include <scribo/filter/thin_bboxes.hh>
+#include <scribo/filter/thick_bboxes.hh>
+#include <scribo/util/text.hh>
-#include <scribo/debug/save_textbboxes_image.hh>
#include <scribo/make/debug_filename.hh>
+#include <scribo/debug/save_textbboxes_image.hh>
+#include <scribo/debug/save_linked_textbboxes_image.hh>
int usage(const char *name)
{
@@ -46,53 +49,57 @@ int usage(const char *name)
return 1;
}
-
int main(int argc, char* argv[])
{
using namespace scribo;
using namespace mln;
- if (argc < 1)
- return usage(argv[0]);
-
- scribo::make::internal::debug_filename_prefix =
"extract_text_double_several_links";
+ scribo::make::internal::debug_filename_prefix = "photo_basic";
image2d<bool> input;
io::pbm::load(input, argv[1]);
+ logical::not_inplace(input);
+ typedef scribo::util::text<image2d<value::label_16> > text_t;
value::label_16 nbboxes;
- scribo::util::text<image2d<value::label_16> > text
- = text::extract_bboxes(input, c8(), nbboxes);
+ text_t textbboxes = text::extract_bboxes(input, c8(), nbboxes);
+
+ text_t filtered_textbboxes
+ = scribo::filter::small_components(textbboxes, 6);
+
+ filtered_textbboxes
+ = scribo::filter::thin_bboxes(filtered_textbboxes, 3);
+
+ filtered_textbboxes
+ = scribo::filter::thick_bboxes(filtered_textbboxes,
+ math::min(input.ncols(), input.nrows()) / 6);
- text = filter::small_components(text,4);
mln::util::array<unsigned> left_link
- = text::grouping::group_with_several_left_links(text, 30);
+ = text::grouping::group_with_single_left_link(filtered_textbboxes, 30);
mln::util::array<unsigned> right_link
- = text::grouping::group_with_several_right_links(text, 30);
+ = text::grouping::group_with_single_right_link(filtered_textbboxes, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes <<
std::endl;
-
scribo::debug::save_linked_textbboxes_image(input,
- text, left_link, right_link,
+ filtered_textbboxes, left_link, right_link,
literal::red, literal::cyan, literal::yellow,
literal::green,
scribo::make::debug_filename("links.ppm"));
- // With validation.
- scribo::util::text<image2d<value::label_16> > grouped_text
- = text::grouping::group_from_double_link(text, left_link, right_link);
+ scribo::debug::save_textbboxes_image(input, filtered_textbboxes.bboxes(),
+ literal::red,
+ scribo::make::debug_filename("test_graph_filtered_text.ppm"));
+ text_t grouped_textbboxes
+ = text::grouping::group_from_double_link(filtered_textbboxes, left_link,
right_link);
- io::ppm::save(mln::debug::colorize(value::rgb8(),
- grouped_text.label_image(),
- grouped_text.nbboxes()),
- scribo::make::debug_filename("label_color.ppm"));
+ std::cout << "AFTER - nbboxes = " <<
grouped_textbboxes.nbboxes().next() << std::endl;
- std::cout << "AFTER double grouping - nbboxes = " <<
grouped_text.bboxes().nelements() << std::endl;
- scribo::debug::save_textbboxes_image(input, grouped_text.bboxes(),
+ scribo::debug::save_textbboxes_image(input, grouped_textbboxes.bboxes(),
literal::red,
- scribo::make::debug_filename("bboxes.ppm"));
+ scribo::make::debug_filename("test_graph_grouped_text.ppm"));
+
}
diff --git a/milena/sandbox/scribo/src/table_extract.cc
b/milena/sandbox/scribo/src/table_extract.cc
index 36142a2..273bd5d 100644
--- a/milena/sandbox/scribo/src/table_extract.cc
+++ b/milena/sandbox/scribo/src/table_extract.cc
@@ -57,7 +57,7 @@ int main(int argc, char* argv[])
trace::quiet = false;
value::label_16 ncells;
- image2d<value::label_16> tables = scribo::table::extract(input, ncells);
+ image2d<value::label_16> tables = scribo::table::extract(input, ncells).first();
std::cout << "ncells (including background) = " << ncells
<< std::endl;
io::ppm::save(mln::debug::colorize(value::rgb8(), tables, ncells),
diff --git a/milena/sandbox/scribo/src/table_rebuild.cc
b/milena/sandbox/scribo/src/table_rebuild.cc
deleted file mode 100644
index d195b5b..0000000
--- a/milena/sandbox/scribo/src/table_rebuild.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory
-//
-// This file is part of the Olena Library. This library is free
-// software; you can redistribute it and/or modify it under the terms
-// of the GNU General Public License version 2 as published by the
-// Free Software Foundation.
-//
-// This library 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 this library; see the file COPYING. If not, write to
-// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
-// Boston, MA 02111-1307, USA.
-//
-// As a special exception, you may use this file as part of a free
-// software library 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.
-
-#include <iostream>
-
-#include <mln/essential/2d.hh>
-
-#include <scribo/table/rebuild.hh>
-#include <scribo/table/erase.hh>
-#include <scribo/table/extract_lines_with_rank.hh>
-#include <scribo/make/debug_filename.hh>
-
-
-int usage(const char *name)
-{
- std::cout << "Usage: " << name << " <input.pbm>
" << std::endl;
- return 1;
-}
-
-
-int main(int argc, char* argv[])
-{
- using namespace scribo;
- using namespace mln;
-
- if (argc < 1)
- return usage(argv[0]);
-
- scribo::make::internal::debug_filename_prefix = argv[0];
-
- image2d<bool> input;
- io::pbm::load(input, argv[1]);
- logical::not_inplace(input);
-
- typedef util::couple<util::array<box2d>,util::array<box2d> >
tblboxes_t;
-
- win::vline2d vline(51);
- win::hline2d hline(51);
- tblboxes_t lineboxes
- = table::extract_lines_with_rank(input, c8(), value::label_16(),
- vline, hline, 6, 6);
-
- value::label_8 ncells;
- image2d<value::label_8> tables = scribo::table::rebuild(input, lineboxes, 30,
ncells);
-
-
- std::cout << "ncells (including background) = " << ncells
<< std::endl;
- io::ppm::save(mln::debug::colorize(value::rgb8(), tables, ncells),
- scribo::make::debug_filename("table_cells.ppm"));
- io::pgm::save(tables, scribo::make::debug_filename("table_cells.pgm"));
-
- image2d<bool> in_wo_tables = table::erase(input, lineboxes);
- io::pbm::save(in_wo_tables,
- scribo::make::debug_filename("input_wo_tables.pbm"));
-}
diff --git a/milena/sandbox/scribo/src/table_rebuild_opening.cc
b/milena/sandbox/scribo/src/table_rebuild_opening.cc
index 375646d..0add582 100644
--- a/milena/sandbox/scribo/src/table_rebuild_opening.cc
+++ b/milena/sandbox/scribo/src/table_rebuild_opening.cc
@@ -66,7 +66,8 @@ int main(int argc, char* argv[])
vline, hline);
value::label_8 ncells;
- image2d<value::label_8> tables = scribo::table::rebuild(input, lineboxes, 30,
ncells);
+ image2d<value::label_8> tables
+ = scribo::table::rebuild(input, lineboxes, 30, ncells).first();
std::cout << "ncells (including background) = " << ncells
<< std::endl;
diff --git a/milena/sandbox/scribo/src/table_rebuild_rank.cc
b/milena/sandbox/scribo/src/table_rebuild_rank.cc
index 77b2b79..1368591 100644
--- a/milena/sandbox/scribo/src/table_rebuild_rank.cc
+++ b/milena/sandbox/scribo/src/table_rebuild_rank.cc
@@ -66,7 +66,8 @@ int main(int argc, char* argv[])
vline, hline, 6, 6);
value::label_8 ncells;
- image2d<value::label_8> tables = scribo::table::rebuild(input, lineboxes, 5,
ncells);
+ image2d<value::label_8> tables
+ = scribo::table::rebuild(input, lineboxes, 5, ncells).first();
std::cout << "ncells (including background) = " << ncells
<< std::endl;
diff --git a/milena/sandbox/scribo/tests/Makefile.am
b/milena/sandbox/scribo/tests/Makefile.am
new file mode 100644
index 0000000..2436042
--- /dev/null
+++ b/milena/sandbox/scribo/tests/Makefile.am
@@ -0,0 +1,7 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+SUBDIRS = \
+ filter \
+ table \
+ text
+
diff --git a/milena/sandbox/scribo/src/table_extract.cc
b/milena/sandbox/scribo/tests/data.hh.in
similarity index 56%
copy from milena/sandbox/scribo/src/table_extract.cc
copy to milena/sandbox/scribo/tests/data.hh.in
index 36142a2..7196653 100644
--- a/milena/sandbox/scribo/src/table_extract.cc
+++ b/milena/sandbox/scribo/tests/data.hh.in
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,43 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#include <iostream>
+#ifndef SCRIBO_TESTS_DATA_HH
+# define SCRIBO_TESTS_DATA_HH
-#include <mln/essential/2d.hh>
-#include <mln/io/dump/save.hh>
+# include <string>
-#include <scribo/table/extract.hh>
+/* Macros are evil, but they save us an extra compilation unit here
+ (as well as additional burden in Makefiles, too.). */
+/// \brief The absolute path to the img directory of Scribo.
+# define SCRIBO_IMG_DIR "@abs_top_srcdir@/milena/sandbox/scribo/tests/img"
-int usage(const char *name)
-{
- std::cout << "Usage: " << name << " <input.pbm>
" << std::endl;
- return 1;
-}
-
-
-int main(int argc, char* argv[])
-{
- using namespace scribo;
- using namespace mln;
-
- if (argc < 1)
- return usage(argv[0]);
-
- scribo::make::internal::debug_filename_prefix = argv[0];
-
- image2d<bool> input;
- io::pbm::load(input, argv[1]);
- logical::not_inplace(input);
-
- trace::quiet = false;
-
- value::label_16 ncells;
- image2d<value::label_16> tables = scribo::table::extract(input, ncells);
-
- std::cout << "ncells (including background) = " << ncells
<< std::endl;
- io::ppm::save(mln::debug::colorize(value::rgb8(), tables, ncells),
- scribo::make::debug_filename("table_cells.ppm"));
-
- io::dump::save(tables, scribo::make::debug_filename("table_cells.dump"));
-}
+#endif // ! SCRIBO_TESTS_DATA_HH
diff --git a/milena/sandbox/scribo/tests/filter/Makefile.am
b/milena/sandbox/scribo/tests/filter/Makefile.am
new file mode 100644
index 0000000..c2a02ef
--- /dev/null
+++ b/milena/sandbox/scribo/tests/filter/Makefile.am
@@ -0,0 +1,10 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/sandbox/scribo/scribo.mk
+
+check_PROGRAMS = \
+ small_and_large_bboxes
+
+small_and_large_bboxes_SOURCES = small_and_large_bboxes.cc
+
+TESTS = $(check_PROGRAMS)
diff --git a/milena/sandbox/scribo/tests/filter/small_and_large_bboxes.cc
b/milena/sandbox/scribo/tests/filter/small_and_large_bboxes.cc
index 2cf7ebc..98fbcd7 100644
--- a/milena/sandbox/scribo/tests/filter/small_and_large_bboxes.cc
+++ b/milena/sandbox/scribo/tests/filter/small_and_large_bboxes.cc
@@ -30,13 +30,17 @@
#include <mln/essential/2d.hh>
#include <scribo/text/extract_bboxes.hh>
-#include <scribo/text/grouping/group_with_multiple_links.hh>
-#include <scribo/text/grouping/group_from_multiple_links.hh>
+#include <scribo/text/grouping/group_with_graph.hh>
+#include <scribo/text/grouping/group_from_graph.hh>
#include <scribo/filter/small_components.hh>
+#include <scribo/util/text.hh>
+#include <scribo/make/debug_filename.hh>
#include <scribo/debug/save_textbboxes_image.hh>
#include <scribo/debug/save_linked_textbboxes_image.hh>
+#include <scribo/tests/data.hh>
+
int usage(const char *name)
{
std::cout << "Usage: " << name << " <input.pbm>
" << std::endl;
@@ -48,42 +52,47 @@ int main(int argc, char* argv[])
using namespace scribo;
using namespace mln;
- if (argc < 1)
- return usage(argv[0]);
+ std::string img;
+ if (argc < 2)
+ {
+ usage(argv[0]);
+ img = SCRIBO_IMG_DIR "/text_to_group.pbm";
+ }
+ else
+ img = argv[1];
scribo::make::internal::debug_filename_prefix = argv[0];
image2d<bool> input;
- io::pbm::load(input, argv[1]);
+ io::pbm::load(input, img.c_str());
+ typedef scribo::util::text<image2d<value::label_16> > text_t;
value::label_16 nbboxes;
- util::array<box2d> textbboxes = text::extract_bboxes(input, c8(), nbboxes);
+ text_t textbboxes = text::extract_bboxes(input, c8(), nbboxes);
- util::graph g = text::grouping::group_with_multiple_links(input,
- c8(), nbboxes,
- textbboxes, 30);
+ mln::util::graph g = text::grouping::group_with_graph(textbboxes, 30);
std::cout << "BEFORE - nbboxes = " << nbboxes <<
std::endl;
scribo::debug::save_linked_textbboxes_image(input,
textbboxes, g,
literal::red, literal::cyan,
- "test_multiple_links_left_linked.ppm");
+ "test_graph_left_linked.ppm");
- util::array<box2d> grouped_textbboxes
- = text::grouping::group_from_multiple_links(textbboxes, g);
+ text_t grouped_textbboxes
+ = text::grouping::group_from_graph(textbboxes, g);
- std::cout << "AFTER - nbboxes = " <<
grouped_textbboxes.nelements() << std::endl;
+ std::cout << "AFTER - nbboxes = " <<
grouped_textbboxes.nbboxes().next() << std::endl;
- scribo::debug::save_textbboxes_image(input, grouped_textbboxes,
+ scribo::debug::save_textbboxes_image(input, grouped_textbboxes.bboxes(),
literal::red,
- "test_multiple_links_grouped_text.ppm");
+ "test_graph_grouped_text.ppm");
- util::array<box2d> filtered_textbboxes
+ text_t filtered_textbboxes
= scribo::filter::small_components(grouped_textbboxes, 6);
- scribo::debug::save_textbboxes_image(input, filtered_textbboxes,
+ scribo::debug::save_textbboxes_image(input, filtered_textbboxes.bboxes(),
literal::red,
- "test_multiple_links_filtered_text.ppm");
+ "test_graph_filtered_text.ppm");
}
diff --git a/milena/sandbox/scribo/tests/table/Makefile.am
b/milena/sandbox/scribo/tests/table/Makefile.am
new file mode 100644
index 0000000..1a4c5c3
--- /dev/null
+++ b/milena/sandbox/scribo/tests/table/Makefile.am
@@ -0,0 +1,12 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/sandbox/scribo/scribo.mk
+
+check_PROGRAMS = \
+ extract_lines_with_rank \
+ repair_lines
+
+extract_lines_with_rank_SOURCES = extract_lines_with_rank.cc
+repair_lines_SOURCES = repair_lines.cc
+
+TESTS = $(check_PROGRAMS)
diff --git a/milena/sandbox/scribo/tests/table/extract_lines_with_rank.cc
b/milena/sandbox/scribo/tests/table/extract_lines_with_rank.cc
index ed5ce3c..6b36b35 100644
--- a/milena/sandbox/scribo/tests/table/extract_lines_with_rank.cc
+++ b/milena/sandbox/scribo/tests/table/extract_lines_with_rank.cc
@@ -1,20 +1,51 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library 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 this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library 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.
+
#include <mln/essential/2d.hh>
+#include <mln/util/couple.hh>
+
#include <scribo/table/extract_lines_with_rank.hh>
#include <scribo/debug/save_table_image.hh>
-#include <mln/util/couple.hh>
+
+#include <scribo/tests/data.hh>
int main(int argc, char *argv[])
{
using namespace mln;
+ std::string img;
if (argc < 2)
- {
- std::cout << "Usage: " << argv[0] << "
<image.pbm>" << std::endl;
- return 1;
- }
+ img = SCRIBO_IMG_DIR "/table_to_be_repaired.pbm";
+ else
+ img = argv[1];
image2d<bool> input;
- io::pbm::load(input, argv[1]);
+ io::pbm::load(input, img.c_str());
typedef util::couple<util::array<box2d>,
util::array<box2d> > tblboxes_t;
@@ -27,9 +58,9 @@ int main(int argc, char *argv[])
lineboxes.second().append(make::box2d(27,0, 31, 26));
lineboxes.second().append(make::box2d(27,34, 31,59));
-
+ value::label_16 nbboxes;
tblboxes_t lineboxes_test = scribo::table::extract_lines_with_rank(input, c8(),
- value::label_16(), win::vline2d(11),
+ nbboxes, win::vline2d(11),
win::hline2d(11), 2, 2);
mln_assertion(lineboxes == lineboxes_test);
diff --git a/milena/sandbox/scribo/tests/table/repair_lines.cc
b/milena/sandbox/scribo/tests/table/repair_lines.cc
index ff5551c..ff7e92f 100644
--- a/milena/sandbox/scribo/tests/table/repair_lines.cc
+++ b/milena/sandbox/scribo/tests/table/repair_lines.cc
@@ -1,22 +1,53 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library 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 this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library 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.
+
#include <mln/essential/2d.hh>
+#include <mln/util/couple.hh>
+
#include <scribo/table/repair_vertical_lines.hh>
#include <scribo/table/repair_horizontal_lines.hh>
#include <scribo/table/extract_lines_with_rank.hh>
#include <scribo/debug/save_table_image.hh>
-#include <mln/util/couple.hh>
+
+#include <scribo/tests/data.hh>
int main(int argc, char *argv[])
{
using namespace mln;
+ std::string img;
if (argc < 2)
- {
- std::cout << "Usage: " << argv[0] << "
<image.pbm>" << std::endl;
- return 1;
- }
+ img = SCRIBO_IMG_DIR "/table_to_be_repaired.pbm";
+ else
+ img = argv[1];
image2d<bool> input;
- io::pbm::load(input, argv[1]);
+ io::pbm::load(input, img.c_str());
typedef util::couple<util::array<box2d>,
util::array<box2d> > tblboxes_t;
diff --git a/milena/sandbox/scribo/tests/text/Makefile.am
b/milena/sandbox/scribo/tests/text/Makefile.am
new file mode 100644
index 0000000..d9df32a
--- /dev/null
+++ b/milena/sandbox/scribo/tests/text/Makefile.am
@@ -0,0 +1,7 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/sandbox/scribo/scribo.mk
+
+check_PROGRAMS =
+
+TESTS = $(check_PROGRAMS)
diff --git a/milena/sandbox/scribo/text/extract_lines.hh
b/milena/sandbox/scribo/text/extract_lines.hh
index 6be2e37..c08a4c4 100644
--- a/milena/sandbox/scribo/text/extract_lines.hh
+++ b/milena/sandbox/scribo/text/extract_lines.hh
@@ -49,11 +49,13 @@
# include <mln/util/graph.hh>
# include <mln/value/label_16.hh>
-# include <scribo/text/grouping/group_with_multiple_links.hh>
-# include <scribo/text/grouping/group_from_multiple_links.hh>
+# include <scribo/text/grouping/group_with_several_left_links.hh>
+# include <scribo/text/grouping/group_with_several_right_links.hh>
+# include <scribo/text/grouping/group_from_double_link.hh>
# include <scribo/filter/small_components.hh>
# include <scribo/util/text.hh>
+# include <scribo/make/debug_filename.hh>
# include <scribo/debug/save_textbboxes_image.hh>
# include <scribo/debug/save_linked_textbboxes_image.hh>
@@ -95,22 +97,26 @@ namespace scribo
# ifndef SCRIBO_NDEBUG
debug::save_textbboxes_image(input, text.bboxes(), literal::red,
- scrib::make::debug_filename("character-bboxes.ppm"));
+ scribo::make::debug_filename("character-bboxes.ppm"));
# endif // ! SCRIBO_NDEBUG
//Link character bboxes to their left neighboor if possible.
- mln::util::graph g
- = text::grouping::group_with_multiple_links(text, 30);
+ mln::util::array<unsigned> left_link
+ = text::grouping::group_with_several_left_links(text, 30);
+ mln::util::array<unsigned> right_link
+ = text::grouping::group_with_several_right_links(text, 30);
+
# ifndef SCRIBO_NDEBUG
- debug::save_linked_textbboxes_image(input,
- text, g,
- literal::red, literal::cyan,
- scribo::make::debug_filename("multiple_links_left_linked.ppm"));
+ scribo::debug::save_linked_textbboxes_image(input,
+ text, left_link, right_link,
+ literal::red, literal::cyan,
+ literal::yellow, literal::green,
+ scribo::make::debug_filename("links.ppm"));
# endif // ! SCRIBO_NDEBUG
//Merge character bboxes through a graph.
scribo::util::text<mln_ch_value(I,V)> grouped_text
- = text::grouping::group_from_multiple_links(text, g);
+ = text::grouping::group_from_double_link(text, left_link, right_link);
# ifndef SCRIBO_NDEBUG
debug::save_textbboxes_image(input, grouped_text.bboxes(),
diff --git a/milena/sandbox/scribo/text/grouping/group_from_double_link.hh
b/milena/sandbox/scribo/text/grouping/group_from_double_link.hh
index d4e5d71..8720c3a 100644
--- a/milena/sandbox/scribo/text/grouping/group_from_double_link.hh
+++ b/milena/sandbox/scribo/text/grouping/group_from_double_link.hh
@@ -124,6 +124,7 @@ namespace scribo
mln_assertion(bresult.nelements() == new_nbboxes.next());
+ /// FIXME: construct a new util::text from the old one.
scribo::util::text<I> result(bresult, new_lbl, new_nbboxes);
trace::exiting("scribo::text::grouping::group_from_double_link");
diff --git a/milena/sandbox/scribo/text/grouping/group_from_multiple_links.hh
b/milena/sandbox/scribo/text/grouping/group_from_graph.hh
similarity index 87%
rename from milena/sandbox/scribo/text/grouping/group_from_multiple_links.hh
rename to milena/sandbox/scribo/text/grouping/group_from_graph.hh
index 059fa22..a9cfd93 100644
--- a/milena/sandbox/scribo/text/grouping/group_from_multiple_links.hh
+++ b/milena/sandbox/scribo/text/grouping/group_from_graph.hh
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef SCRIBO_TEXT_GROUPING_GROUP_FROM_MULTIPLE_LINKS_HH
-# define SCRIBO_TEXT_GROUPING_GROUP_FROM_MULTIPLE_LINKS_HH
+#ifndef SCRIBO_TEXT_GROUPING_GROUP_FROM_GRAPH_HH
+# define SCRIBO_TEXT_GROUPING_GROUP_FROM_GRAPH_HH
-/// \file scribo/text/grouping/group_from_multiple_links.hh
+/// \file scribo/text/grouping/group_from_graph.hh
///
/// Link text bounding boxes with their neighbors.
@@ -63,8 +63,8 @@ namespace scribo
/// FIXME: Add much more doc!
template <typename I, typename G>
scribo::util::text<I>
- group_from_multiple_links(const scribo::util::text<I>& text,
- const Graph<G>& g_);
+ group_from_graph(const scribo::util::text<I>& text,
+ const Graph<G>& g_);
# ifndef MLN_INCLUDE_ONLY
@@ -116,10 +116,10 @@ namespace scribo
template <typename I, typename G>
inline
scribo::util::text<I>
- group_from_multiple_links(const scribo::util::text<I>& text,
- const Graph<G>& g_)
+ group_from_graph(const scribo::util::text<I>& text,
+ const Graph<G>& g_)
{
- trace::entering("scribo::text::grouping::group_from_multiple_links");
+ trace::entering("scribo::text::grouping::group_from_graph");
const G& g = exact(g_);
@@ -151,7 +151,8 @@ namespace scribo
mln_assertion(new_nbboxes.next() == bresult.nelements());
- trace::exiting("scribo::text::grouping::group_from_multiple_links");
+ trace::exiting("scribo::text::grouping::group_from_graph");
+ /// FIXME: construct a new util::text from the old one.
return scribo::make::text(bresult, new_lbl, new_nbboxes);
}
@@ -164,4 +165,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_GROUP_FROM_MULTIPLE_LINKS_HH
+#endif // ! SCRIBO_TEXT_GROUPING_GROUP_FROM_GRAPH_HH
diff --git a/milena/sandbox/scribo/text/grouping/group_from_single_link.hh
b/milena/sandbox/scribo/text/grouping/group_from_single_link.hh
index 43bb7b1..3dae34f 100644
--- a/milena/sandbox/scribo/text/grouping/group_from_single_link.hh
+++ b/milena/sandbox/scribo/text/grouping/group_from_single_link.hh
@@ -96,6 +96,7 @@ namespace scribo
convert::to<fun::l2l::relabel<mln_value(I)> >(parent_array));
mln_value(I) new_nbboxes = result.nelements() - 1;
trace::exiting("scribo::text::grouping::group_from_single_link");
+ /// FIXME: construct a new util::text from the old one.
return scribo::make::text(result, lbl, new_nbboxes);
}
diff --git a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
b/milena/sandbox/scribo/text/grouping/group_with_graph.hh
similarity index 63%
rename from milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
rename to milena/sandbox/scribo/text/grouping/group_with_graph.hh
index bfe1bc3..3089d56 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_multiple_links.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_graph.hh
@@ -27,16 +27,14 @@
// Public License.
-#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
-# define SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
+#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_GRAPH_HH
+# define SCRIBO_TEXT_GROUPING_GROUP_WITH_GRAPH_HH
-/// \file scribo/text/grouping/group_with_multiple_links.hh
+/// \file scribo/text/grouping/group_with_graph.hh
///
-/// Group character bounding boxes with multiple links.
+/// Group character bounding boxes with a graph.
# include <mln/core/concept/image.hh>
-# include <mln/labeling/compute.hh>
-# include <mln/accu/center.hh>
# include <mln/math/abs.hh>
@@ -44,7 +42,7 @@
# include <scribo/core/macros.hh>
# include <scribo/text/grouping/internal/init_link_array.hh>
-# include <scribo/text/grouping/internal/update_link_graph.hh>
+# include <scribo/text/grouping/internal/find_graph_link.hh>
# include <scribo/util/text.hh>
namespace scribo
@@ -56,56 +54,40 @@ namespace scribo
namespace grouping
{
- /// Group character bounding boxes with multiple links.
+ /// Group character bounding boxes with a graph.
/// Look up for neighbors on the right of each box.
template <typename L>
mln::util::graph
- group_with_multiple_links(const scribo::util::text<L>& text,
- unsigned neighb_max_distance);
+ group_with_graph(const scribo::util::text<L>& text,
+ unsigned neighb_max_distance);
# ifndef MLN_INCLUDE_ONLY
template <typename L>
inline
mln::util::graph
- group_with_multiple_links(const scribo::util::text<L>& text,
- unsigned neighb_max_distance)
+ group_with_graph(const scribo::util::text<L>& text,
+ unsigned neighb_max_distance)
{
- trace::entering("scribo::text::grouping::group_with_multiple_links");
+ trace::entering("scribo::text::grouping::group_with_graph");
mln::util::graph g(text.nbboxes().next());
- mln::util::array<mln_site(L)::vec> centers
- = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
-
for_all_ncomponents(i, text.nbboxes())
{
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
- mln_site(L) c = centers[i];
// -------
// | |
- // | |
- // | |
// | X------->
// | |
- // | |
- // | |
// -------
- /// First site on the right of the central site
- mln_site(L) p = c + right;
-
- const L& lbl = text.label_image();
- while (lbl.domain().has(p) && (lbl(p) == literal::zero || lbl(p) == i)
- && math::abs(p.col() - c.col()) < dmax)
- ++p.col();
-
- internal::update_link_graph(lbl, g, p, c, i, dmax);
+ internal::find_graph_link(g, text, i, dmax, text.mass_center(i));
}
- trace::exiting("scribo::text::grouping::group_with_multiple_links");
+ trace::exiting("scribo::text::grouping::group_with_graph");
return g;
}
@@ -117,4 +99,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_MULTIPLE_LINKS_HH
+#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_GRAPH_HH
diff --git a/milena/sandbox/scribo/text/grouping/group_with_several_multiple_links.hh
b/milena/sandbox/scribo/text/grouping/group_with_several_graphes.hh
similarity index 71%
rename from milena/sandbox/scribo/text/grouping/group_with_several_multiple_links.hh
rename to milena/sandbox/scribo/text/grouping/group_with_several_graphes.hh
index 4dec5c7..d50b837 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_several_multiple_links.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_several_graphes.hh
@@ -27,12 +27,12 @@
// Public License.
-#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_MULTIPLE_LINKS_HH
-# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_MULTIPLE_LINKS_HH
+#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_GRAPHES_HH
+# define SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_GRAPHES_HH
-/// \file scribo/text/grouping/group_with_several_multiple_links.hh
+/// \file scribo/text/grouping/group_with_several_graphes.hh
///
-/// Group character bounding boxes with several multiple links.
+/// Group character bounding boxes with several graphes.
# include <mln/core/concept/image.hh>
# include <mln/labeling/compute.hh>
@@ -44,8 +44,7 @@
# include <scribo/core/macros.hh>
# include <scribo/text/grouping/internal/init_link_array.hh>
-# include <scribo/text/grouping/internal/update_link_graph.hh>
-# include <scribo/text/grouping/internal/find_left_graph_link.hh>
+# include <scribo/text/grouping/internal/find_graph_link.hh>
# include <scribo/util/text.hh>
namespace scribo
@@ -57,11 +56,11 @@ namespace scribo
namespace grouping
{
- /// Group character bounding boxes with several_multiple links.
+ /// Group character bounding boxes with several graphes.
/// Look up for neighbors on the left of each box.
template <typename L>
mln::util::graph
- group_with_several_multiple_links(const scribo::util::text<L>& text,
+ group_with_several_graphes(const scribo::util::text<L>& text,
unsigned neighb_max_distance);
# ifndef MLN_INCLUDE_ONLY
@@ -69,22 +68,19 @@ namespace scribo
template <typename L>
inline
mln::util::graph
- group_with_several_multiple_links(const scribo::util::text<L>& text,
+ group_with_several_graphes(const scribo::util::text<L>& text,
unsigned neighb_max_distance)
{
- trace::entering("scribo::text::grouping::group_with_several_multiple_links");
+ trace::entering("scribo::text::grouping::group_with_several_graphes");
mln::util::graph g(text.nbboxes().next());
- mln::util::array<mln_site(L)::vec> centers
- = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
-
for_all_ncomponents(i, text.nbboxes())
{
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
- mln_site(L) c = centers[i];
+ mln_site(L) c = text.mass_center(i);
// -------
// | X------->
@@ -96,22 +92,25 @@ namespace scribo
// | X------->
// -------
+ // FIXME: may create several times the same edge.
+ // We should use an adjacency matrix when available.
+
/// Left link from the top anchor.
mln_site(L) a1 = c;
a1.row() = text.bbox(i).pmin().row() + (c.row() - text.bbox(i).pmin().row()) / 4;
- internal::find_left_graph_link(g, text, i, dmax, a1);
+ internal::find_graph_link(g, text, i, dmax, a1);
/// First site on the right of the central site
- internal::find_left_graph_link(g, text, i, dmax, c);
+ internal::find_graph_link(g, text, i, dmax, c);
/// Left link from the bottom anchor.
mln_site(L) a2 = c;
a2.row() = text.bbox(i).pmax().row() - (c.row() - text.bbox(i).pmin().row()) / 4;
- internal::find_left_graph_link(g, text, i, dmax, a2);
+ internal::find_graph_link(g, text, i, dmax, a2);
}
- trace::exiting("scribo::text::grouping::group_with_several_multiple_links");
+ trace::exiting("scribo::text::grouping::group_with_several_graphes");
return g;
}
@@ -123,4 +122,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_MULTIPLE_LINKS_HH
+#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_SEVERAL_GRAPHES_HH
diff --git a/milena/sandbox/scribo/text/grouping/group_with_several_left_links.hh
b/milena/sandbox/scribo/text/grouping/group_with_several_left_links.hh
index 84a743d..666a283 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_several_left_links.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_several_left_links.hh
@@ -38,8 +38,6 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/labeling/compute.hh>
-# include <mln/accu/center.hh>
# include <mln/util/array.hh>
@@ -88,22 +86,17 @@ namespace scribo
internal::init_link_array(link_2);
internal::init_link_array(link_3);
- //FIXME: should be removed if this information is stored in util::text.
- mln::util::array<mln_site(L)::vec> centers
- = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
-
- std::cout << "dmax = " << neighb_max_distance << std::endl;
for_all_ncomponents(i, text.nbboxes())
{
- // -------
- // | X------->
- // | |
- // | |
- // | X------->
- // | |
- // | |
- // | X------->
- // -------
+ // -------
+ // <------X |
+ // | |
+ // | |
+ // <------X |
+ // | |
+ // | |
+ // <------X |
+ // -------
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
@@ -116,7 +109,7 @@ namespace scribo
internal::find_left_link(text, link_1, i, dmax, a1);
/// Left link from the central site
- internal::find_left_link(text, link_2, i, dmax, centers[i]);
+ internal::find_left_link(text, link_2, i, dmax, text.mass_center(i));
/// Left link from the bottom anchor.
mln_site(L) a2 = c;
diff --git a/milena/sandbox/scribo/text/grouping/group_with_several_right_links.hh
b/milena/sandbox/scribo/text/grouping/group_with_several_right_links.hh
index cc2ee2c..f7d38a7 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_several_right_links.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_several_right_links.hh
@@ -38,8 +38,6 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/labeling/compute.hh>
-# include <mln/accu/center.hh>
# include <mln/util/array.hh>
@@ -88,22 +86,17 @@ namespace scribo
internal::init_link_array(link_2);
internal::init_link_array(link_3);
- //FIXME: should be removed if this information is stored in util::text.
- mln::util::array<mln_site(L)::vec> centers
- = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
-
- std::cout << "dmax = " << neighb_max_distance << std::endl;
for_all_ncomponents(i, text.nbboxes())
{
- // -------
- // <------X |
- // | |
- // | |
- // <------X |
- // | |
- // | |
- // <------X |
- // -------
+ // -------
+ // | X------->
+ // | |
+ // | |
+ // | X------->
+ // | |
+ // | |
+ // | X------->
+ // -------
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
@@ -116,7 +109,7 @@ namespace scribo
internal::find_right_link(text, link_1, i, dmax, a1);
/// Right link from the central site
- internal::find_right_link(text, link_2, i, dmax, centers[i]);
+ internal::find_right_link(text, link_2, i, dmax, text.mass_center(i));
/// Right link from the bottom anchor.
mln_site(L) a2 = c;
diff --git a/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh
b/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh
index 1b39485..7375c93 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_single_left_link.hh
@@ -38,7 +38,6 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/labeling/compute.hh>
# include <mln/math/abs.hh>
@@ -87,15 +86,12 @@ namespace scribo
mln::util::array<unsigned> left_link(text.nbboxes().next());
internal::init_link_array(left_link);
- mln::util::array<mln_site(L)::vec> centers
- = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
-
for_all_ncomponents(i, text.nbboxes())
{
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
- mln_site(L) c = centers[i];
+ mln_site(L) c = text.mass_center(i);
/// Find a neighbor on the left
internal::find_left_link(text, left_link, i, dmax, c);
diff --git a/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh
b/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh
index 6327d9f..0ad091f 100644
--- a/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh
+++ b/milena/sandbox/scribo/text/grouping/group_with_single_right_link.hh
@@ -38,7 +38,6 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/labeling/compute.hh>
# include <mln/math/abs.hh>
@@ -89,15 +88,12 @@ namespace scribo
mln::util::array<unsigned> right_link(text.nbboxes().next());
internal::init_link_array(right_link);
- mln::util::array<mln_site(L)::vec> centers
- = labeling::compute(accu::meta::center(), text.label_image(), text.nbboxes());
-
for_all_ncomponents(i, text.nbboxes())
{
unsigned midcol = (text.bbox(i).pmax().col()
- text.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
- mln_site(L) c = centers[i];
+ mln_site(L) c = text.mass_center(i);
///
/// Find a neighbor on the right
diff --git a/milena/sandbox/scribo/text/grouping/internal/find_left_graph_link.hh
b/milena/sandbox/scribo/text/grouping/internal/find_graph_link.hh
similarity index 68%
rename from milena/sandbox/scribo/text/grouping/internal/find_left_graph_link.hh
rename to milena/sandbox/scribo/text/grouping/internal/find_graph_link.hh
index 4055ea1..95edebb 100644
--- a/milena/sandbox/scribo/text/grouping/internal/find_left_graph_link.hh
+++ b/milena/sandbox/scribo/text/grouping/internal/find_graph_link.hh
@@ -26,21 +26,22 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_GRAPH_LINK_HH
-# define SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_GRAPH_LINK_HH
+#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_FIND_GRAPH_LINK_HH
+# define SCRIBO_TEXT_GROUPING_INTERNAL_FIND_GRAPH_LINK_HH
-/// \file scribo/text/grouping/internal/find_left_graph_link.hh
+/// \file scribo/text/grouping/internal/find_graph_link.hh
///
///
# include <mln/core/concept/image.hh>
+# include <mln/core/concept/graph.hh>
# include <mln/math/abs.hh>
# include <mln/util/array.hh>
# include <scribo/util/text.hh>
-# include <scribo/text/grouping/internal/update_link_graph.hh>
+# include <scribo/text/grouping/internal/update_graph_link.hh>
//FIXME: not generic.
# include <mln/core/alias/dpoint2d.hh>
@@ -57,35 +58,43 @@ namespace scribo
namespace internal
{
- template <typename L>
+ template <typename G, typename L>
void
- find_left_graph_link(const scribo::util::text<L>& text,
- mln::util::array<unsigned>& left_link,
- unsigned current_comp,
- int dmax,
- const mln_site(L)& c);
+ find_graph_link(Graph<G>& g_,
+ const scribo::util::text<L>& text,
+ unsigned current_comp,
+ int dmax,
+ const mln_site(L)& c);
# ifndef MLN_INCLUDE_ONLY
- template <typename L>
+ template <typename G, typename L>
void
- find_left_graph_link(mln::util::graph& g,
- const scribo::util::text<L>& text,
- unsigned current_comp,
- int dmax,
- const mln_site(L)& c)
+ find_graph_link(Graph<G>& g_,
+ const scribo::util::text<L>& text,
+ unsigned current_comp,
+ int dmax,
+ const mln_site(L)& c)
{
+ trace::entering("scribo::text::grouping::internal::find_graph_link");
+
+ G& g = exact(g_);
+ mln_precondition(g.is_valid());
+ mln_precondition(text.is_valid());
+
///FIXME: the following code is not generic...
/// First site on the right of the central site
- mln_site(L) p = c + left;
+ mln_site(L) p = c + right;
const L& lbl = text.label_image();
while (lbl.domain().has(p) && (lbl(p) == literal::zero
|| lbl(p) == current_comp)
&& math::abs(p.col() - c.col()) < dmax)
- --p.col();
+ ++p.col();
+
+ update_graph_link(lbl, g, p, c, current_comp, dmax);
- update_link_graph(lbl, g, p, c, current_comp, dmax);
+ trace::exiting("scribo::text::grouping::internal::find_graph_link");
}
# endif // MLN_INCLUDE_ONLY
@@ -99,4 +108,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_FIND_LEFT_GRAPH_LINK_HH
+#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_FIND_GRAPH_LINK_HH
diff --git a/milena/sandbox/scribo/text/grouping/internal/update_link_graph.hh
b/milena/sandbox/scribo/text/grouping/internal/update_graph_link.hh
similarity index 79%
rename from milena/sandbox/scribo/text/grouping/internal/update_link_graph.hh
rename to milena/sandbox/scribo/text/grouping/internal/update_graph_link.hh
index f572a47..6373678 100644
--- a/milena/sandbox/scribo/text/grouping/internal/update_link_graph.hh
+++ b/milena/sandbox/scribo/text/grouping/internal/update_graph_link.hh
@@ -27,15 +27,15 @@
// Public License.
-#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_LINK_GRAPH_HH
-# define SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_LINK_GRAPH_HH
+#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_GRAPH_LINK_HH
+# define SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_GRAPH_LINK_HH
/// \file scribo/text/grouping/internal/update_link_array.hh
///
/// Update graph edges if a valid neighbor is found.
# include <mln/core/concept/image.hh>
-# include <mln/util/graph.hh>
+# include <mln/core/concept/graph.hh>
namespace scribo
{
@@ -50,9 +50,9 @@ namespace scribo
{
/// Update graph edges if a valid neighbor is found.
- template <typename I>
+ template <typename I, typename G>
void
- update_link_graph(const Image<I>& lbl_, mln::util::graph& g,
+ update_graph_link(const Image<I>& lbl_, Graph<G>& g_,
const mln_site(I)& p, const mln_site(I)& c,
unsigned i, int dmax);
@@ -60,21 +60,27 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
- template <typename I>
+ template <typename I, typename G>
inline
void
- update_link_graph(const Image<I>& lbl_, mln::util::graph& g,
+ update_graph_link(const Image<I>& lbl_, Graph<G>& g_,
const mln_site(I)& p, const mln_site(I)& c,
unsigned i, int dmax)
{
+ trace::entering("scribo::text::grouping::internal::update_graph_link");
+
const I& lbl = exact(lbl_);
+ G& g = exact(g_);
mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
mln_precondition(exact(lbl).is_valid());
+ mln_precondition(g.is_valid());
if (lbl.domain().has(p) && lbl(p) != literal::zero && lbl(p) != i
&& (math::abs(p.col() - c.col())) < dmax)
g.add_edge(lbl(p), i);
+
+ trace::exiting("scribo::text::grouping::internal::update_graph_link");
}
@@ -89,4 +95,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_LINK_GRAPH_HH
+#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_UPDATE_GRAPH_LINK_HH
diff --git a/milena/sandbox/scribo/util/text.hh b/milena/sandbox/scribo/util/text.hh
index 2619a79..531d735 100644
--- a/milena/sandbox/scribo/util/text.hh
+++ b/milena/sandbox/scribo/util/text.hh
@@ -36,6 +36,8 @@
# include <mln/core/image/image2d.hh>
# include <mln/core/concept/proxy.hh>
# include <mln/core/site_set/box.hh>
+# include <mln/accu/center.hh>
+# include <mln/labeling/compute.hh>
# include <mln/value/label_16.hh>
# include <mln/util/couple.hh>
# include <mln/util/array.hh>
@@ -55,14 +57,19 @@ namespace scribo
public:
typedef mln_site(L) site;
typedef mln::util::array<box<site> > boxes_t;
+ typedef mln::util::array<mln_site(L)::vec> mass_centers_t;
text();
text(const mln::util::array<box<mln_site(L)> >& bboxes,
+ const Image<L>& lbl,
+ const mln_value(L)& nbboxes,
+ const mln::util::array<mln_site(L)::vec>& mass_centers);
+ text(const mln::util::array<box<mln_site(L)> >& bboxes,
const Image<L>& lbl,
const mln_value(L)& nbboxes);
const L& label_image() const;
- L& label_image();
+ void set_label_image(const Image<L>& lbl);
const mln_value(L)& nbboxes() const;
mln_value(L)& nbboxes();
@@ -73,10 +80,16 @@ namespace scribo
const box<mln_site(L)>& bbox(unsigned i) const;
box<mln_site(L)>& bbox(unsigned i);
+ const mln::util::array<mln_site(L)::vec>& mass_centers() const;
+ mln_site(L) mass_center(unsigned i) const;
+
bool is_valid() const;
private:
+ void update();
+
boxes_t bboxes_;
+ mass_centers_t mass_centers_;
L lbl_;
mln_value(L) nbboxes_;
};
@@ -95,26 +108,31 @@ namespace scribo
inline
text<L>::text(const mln::util::array<box<mln_site(L)> >&
bboxes,
const Image<L>& lbl,
- const mln_value(L)& nbboxes)
- : bboxes_(bboxes), lbl_(exact(lbl)), nbboxes_(nbboxes)
+ const mln_value(L)& nbboxes,
+ const mln::util::array<mln_site(L)::vec>& mass_centers)
+ : bboxes_(bboxes), mass_centers_(mass_centers),
+ lbl_(exact(lbl)), nbboxes_(nbboxes)
{
mln_assertion(bboxes.nelements() == nbboxes.next());
}
template <typename L>
inline
- const L&
- text<L>::label_image() const
+ text<L>::text(const mln::util::array<box<mln_site(L)> >&
bboxes,
+ const Image<L>& lbl,
+ const mln_value(L)& nbboxes)
+ : bboxes_(bboxes), lbl_(exact(lbl)), nbboxes_(nbboxes)
{
- mln_precondition(lbl_.is_valid());
- return lbl_;
+ mln_assertion(bboxes.nelements() == nbboxes.next());
+ update();
}
template <typename L>
inline
- L&
- text<L>::label_image()
+ const L&
+ text<L>::label_image() const
{
+ mln_precondition(lbl_.is_valid());
return lbl_;
}
@@ -173,12 +191,35 @@ namespace scribo
template <typename L>
inline
+ const mln::util::array<mln_site(L)::vec>&
+ text<L>::mass_centers() const
+ {
+ return mass_centers_;
+ }
+
+ template <typename L>
+ inline
+ mln_site(L)
+ text<L>::mass_center(unsigned i) const
+ {
+ return mass_centers_[i];
+ }
+
+ template <typename L>
+ inline
bool
text<L>::is_valid() const
{
return lbl_.is_valid() && bboxes_.nelements() == nbboxes_.next();
}
+ template <typename L>
+ inline
+ void
+ text<L>::update()
+ {
+ mass_centers_ = labeling::compute(accu::meta::center(), lbl_, nbboxes_);
+ }
# endif // ! MLN_INCLUDE_ONLY
--
1.5.6.5