* extract/primitive/lines_h_thick.hh,
* debug/save_linked_bboxes_image.hh: Reindent.
* demo/Makefile.am: Use $(srcdir).
* draw/bounding_box_links.hh: Fix use of invalid sites.
* extract/primitive/lines_h_pattern.hh,
* extract/primitive/lines_v_pattern.hh: Add fixmes.
* filter/large_objects.hh,
* filter/thick_objects.hh: Set a specific value for the
background.
* text/grouping/group_from_double_link.hh: Update doc and add an
overload.
* text/grouping/group_from_single_link.hh,
* text/grouping/group_with_graph.hh: Update doc.
* text/grouping/internal/is_link_valid.hh: Add a missing test.
---
scribo/ChangeLog | 26 ++++++++++++
scribo/debug/save_linked_bboxes_image.hh | 6 +-
scribo/demo/Makefile.am | 2 +-
scribo/draw/bounding_box_links.hh | 38 ++++++++++++++----
scribo/extract/primitive/lines_h_pattern.hh | 2 +
scribo/extract/primitive/lines_h_thick.hh | 8 ++--
scribo/extract/primitive/lines_v_pattern.hh | 2 +
scribo/filter/large_objects.hh | 2 +
scribo/filter/thick_objects.hh | 2 +
scribo/text/grouping/group_from_double_link.hh | 49 ++++++++++++++++++-----
scribo/text/grouping/group_from_single_link.hh | 12 +++--
scribo/text/grouping/group_with_graph.hh | 44 ++++++++++++---------
scribo/text/grouping/internal/is_link_valid.hh | 3 +-
13 files changed, 145 insertions(+), 51 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index c9878a4..14d8305 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,31 @@
2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Various small fixes in Scribo.
+
+ * extract/primitive/lines_h_thick.hh,
+ * debug/save_linked_bboxes_image.hh: Reindent.
+
+ * demo/Makefile.am: Use $(srcdir).
+
+ * draw/bounding_box_links.hh: Fix use of invalid sites.
+
+ * extract/primitive/lines_h_pattern.hh,
+ * extract/primitive/lines_v_pattern.hh: Add fixmes.
+
+ * filter/large_objects.hh,
+ * filter/thick_objects.hh: Set a specific value for the
+ background.
+
+ * text/grouping/group_from_double_link.hh: Update doc and add an
+ overload.
+
+ * text/grouping/group_from_single_link.hh,
+ * text/grouping/group_with_graph.hh: Update doc.
+
+ * text/grouping/internal/is_link_valid.hh: Add a missing test.
+
+2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add new routines for line extraction.
* extract/primitive/lines_h_single.hh,
diff --git a/scribo/debug/save_linked_bboxes_image.hh
b/scribo/debug/save_linked_bboxes_image.hh
index f9ec7c9..ed35622 100644
--- a/scribo/debug/save_linked_bboxes_image.hh
+++ b/scribo/debug/save_linked_bboxes_image.hh
@@ -216,9 +216,9 @@ namespace scribo
mln_ch_value(I,value::rgb8) tmp = data::convert(value::rgb8(), input);
mln::util::array<mln_result(accu::center<mln_psite(L)>)>
- mass_center = labeling::compute(accu::meta::center(),
- objects,
- objects.nlabels());
+ mass_center = labeling::compute(accu::meta::center(),
+ objects,
+ objects.nlabels());
draw::bounding_boxes(tmp, objects.bboxes(), box_value);
draw::bounding_box_links(tmp, mass_center,
diff --git a/scribo/demo/Makefile.am b/scribo/demo/Makefile.am
index 19948cb..b51084e 100644
--- a/scribo/demo/Makefile.am
+++ b/scribo/demo/Makefile.am
@@ -5,7 +5,7 @@ include $(top_srcdir)/scribo/scribo.mk
.PHONY : demo
Makefile.demo:
- qmake-qt4 $(top_srcdir)/scribo/demo/demo.pro -o Makefile.demo
+ qmake-qt4 $(srcdir)/demo/demo.pro -o Makefile.demo
demo: Makefile.demo
make -f Makefile.demo all
diff --git a/scribo/draw/bounding_box_links.hh b/scribo/draw/bounding_box_links.hh
index c1dc997..908da17 100644
--- a/scribo/draw/bounding_box_links.hh
+++ b/scribo/draw/bounding_box_links.hh
@@ -142,6 +142,17 @@ namespace scribo
namespace internal
{
+
+ template <typename I>
+ mln_site(I)
+ shift_site(const I& ima,
+ const mln_site(I)& p, const mln_dpsite(mln_site_(I))& dp)
+ {
+ if (ima.has(p + dp))
+ return p + dp;
+ return p;
+ }
+
/// Draw a link graph in an image.
/// Functor to be passed to depth_first_search.
template <typename I>
@@ -288,24 +299,32 @@ namespace scribo
I& input = exact(input_);
mln_precondition(input.is_valid());
- mln_site(I)::vec dleft = literal::origin;
+ typedef mln_site(I) P;
+
+ mln_dpsite(P) dleft = literal::zero;
dleft[0] = 2;
- mln_site(I)::vec dright = literal::origin;
+ mln_dpsite(P) dright = literal::zero;
dright[0] = -2;
for_all_components(i, left_link)
{
mln::draw::line(input,
- mass_centers[i] + dleft,
- mass_centers[left_link[i]] + dleft,
+ internal::shift_site(input, mass_centers[i], dleft),
+ internal::shift_site(input,
+ mass_centers[left_link[i]],
+ dleft),
left_link_value);
mln::draw::line(input,
- mass_centers[i] + dright,
- mass_centers[right_link[i]] + dright,
+ internal::shift_site(input, mass_centers[i], dright),
+ internal::shift_site(input,
+ mass_centers[right_link[i]],
+ dright),
right_link_value);
mln::util::couple<bool, unsigned>
- nbh = text::grouping::internal::is_link_valid(left_link, right_link, i);
+ nbh = text::grouping::internal::is_link_valid(left_link,
+ right_link,
+ i);
if (nbh.first())
mln::draw::line(input,
@@ -335,6 +354,7 @@ namespace scribo
I& input = exact(input_);
mln_precondition(input.is_valid());
+ typedef mln_site(I) P;
mln_site(I)::vec dleft = literal::origin;
dleft[0] = 2;
mln_site(I)::vec dright = literal::origin;
@@ -352,7 +372,9 @@ namespace scribo
right_link_value);
mln::util::couple<bool, unsigned>
- nbh = text::grouping::internal::is_link_valid(left_link, right_link, i);
+ nbh = text::grouping::internal::is_link_valid(left_link,
+ right_link,
+ i);
if (nbh.first())
mln::draw::line(input,
diff --git a/scribo/extract/primitive/lines_h_pattern.hh
b/scribo/extract/primitive/lines_h_pattern.hh
index 10dcfe5..2aa531e 100644
--- a/scribo/extract/primitive/lines_h_pattern.hh
+++ b/scribo/extract/primitive/lines_h_pattern.hh
@@ -82,8 +82,10 @@ namespace scribo
window2d win;
convert::from_to(win_def, win);
+ //FIXME: Add reconstruction instead of this arbitrary dilation.
win::hline2d hwin(length/2 + 2);
return morpho::dilation(lines_pattern(input, length, 1, win), hwin);
+// return lines_pattern(input, length, 1, win);
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/extract/primitive/lines_h_thick.hh
b/scribo/extract/primitive/lines_h_thick.hh
index 74ea67e..cfbf1cc 100644
--- a/scribo/extract/primitive/lines_h_thick.hh
+++ b/scribo/extract/primitive/lines_h_thick.hh
@@ -77,8 +77,8 @@ namespace scribo
template <typename I, typename N, typename V>
void
lines_h_thick_tests(const Image<I>& input,
- const Neighborhood<N>& nbh, V& nlines,
- unsigned line_length)
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length)
{
mlc_equal(mln_value(I),bool)::check();
mlc_bool(mln_site_(I)::dim == 2)::check();
@@ -101,8 +101,8 @@ namespace scribo
template <typename I, typename N, typename V>
object_image(mln_ch_value(I,V))
lines_h_thick(const Image<I>& input,
- const Neighborhood<N>& nbh, V& nlines,
- unsigned line_length)
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length)
{
trace::entering("scribo::primitive::lines_h_thick");
diff --git a/scribo/extract/primitive/lines_v_pattern.hh
b/scribo/extract/primitive/lines_v_pattern.hh
index 43727d1..be920fc 100644
--- a/scribo/extract/primitive/lines_v_pattern.hh
+++ b/scribo/extract/primitive/lines_v_pattern.hh
@@ -76,8 +76,10 @@ namespace scribo
window2d win;
convert::from_to(win_def, win);
+ //FIXME: Add reconstruction instead of this arbitrary dilation.
win::vline2d vwin(length/2 + 2);
return morpho::dilation(lines_pattern(input, length, 0, win), vwin);
+// return lines_pattern(input, length, 0, win);
}
diff --git a/scribo/filter/large_objects.hh b/scribo/filter/large_objects.hh
index 336cdb7..e7e4f25 100644
--- a/scribo/filter/large_objects.hh
+++ b/scribo/filter/large_objects.hh
@@ -119,6 +119,8 @@ namespace scribo
/// \p max_size_.
bool operator()(const mln_value(L)& l) const
{
+ if (l == literal::zero)
+ return true;
return card_[l] <= max_size_;
}
diff --git a/scribo/filter/thick_objects.hh b/scribo/filter/thick_objects.hh
index 258dbed..15b4c78 100644
--- a/scribo/filter/thick_objects.hh
+++ b/scribo/filter/thick_objects.hh
@@ -109,6 +109,8 @@ namespace scribo
/// \param[in] l An image value.
bool operator()(const mln_value(L)& l) const
{
+ if (l == literal::zero)
+ return true;
return objects_.bbox(l).nrows() < max_thickness_
&& objects_.bbox(l).ncols() < max_thickness_;
}
diff --git a/scribo/text/grouping/group_from_double_link.hh
b/scribo/text/grouping/group_from_double_link.hh
index 2b1a27f..5c82cb2 100644
--- a/scribo/text/grouping/group_from_double_link.hh
+++ b/scribo/text/grouping/group_from_double_link.hh
@@ -29,7 +29,7 @@
/// \file
///
-/// Group text bounding boxes from left and right links and validate
+/// Group objects from left and right links information and validate
/// These links. A link must exist in both ways to be validated.
@@ -61,24 +61,34 @@ namespace scribo
namespace grouping
{
- /// Group text bounding boxes from left and right links and validate
- /// These links. A link must exist in both ways to be validated.
- /*!
- ** \param[in] objects The Lines of text.
- ** \param[in] left_link The left neighbor of each line of text.
- ** \param[in] right_link The right neighbor of each line of text.
- **
- ** \return New lines of text. Some of the lines of \p text may have
- ** been grouped.
+ /*! Group objects from left and right links information and
+ validate These links. A link must exist in both ways to be
+ validated.
+
+ \param[in] objects The Lines of text.
+ \param[in] left_link The left neighbor of each line of text.
+ \param[in] right_link The right neighbor of each line of text.
+ \param[in] parent_link The function used to group components.
+
+ \return An image of grouped objects.
*/
template <typename L>
object_image(L)
group_from_double_link(const object_image(L)& objects,
const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ mln::util::array<unsigned>& parent_link);
+
+ /// \overload
+ template <typename L>
+ object_image(L)
+ group_from_double_link(const object_image(L)& objects,
+ const mln::util::array<unsigned>& left_link,
const mln::util::array<unsigned>& right_link);
+
# ifndef MLN_INCLUDE_ONLY
@@ -87,7 +97,8 @@ namespace scribo
object_image(L)
group_from_double_link(const object_image(L)& objects,
const mln::util::array<unsigned>& left_link,
- const mln::util::array<unsigned>& right_link)
+ const mln::util::array<unsigned>& right_link,
+ mln::util::array<unsigned>& parent_link)
{
trace::entering("scribo::text::grouping::group_from_double_link");
@@ -116,11 +127,27 @@ namespace scribo
output.init_from_(objects);
output.relabel(parent);
+ parent_link = parent;
trace::exiting("scribo::text::grouping::group_from_double_link");
return output;
}
+ template <typename L>
+ inline
+ object_image(L)
+ group_from_double_link(const object_image(L)& objects,
+ const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link)
+ {
+ mln::util::array<unsigned> parent_link;
+ return group_from_double_link(objects,
+ left_link,
+ right_link,
+ parent_link);
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/text/grouping/group_from_single_link.hh
b/scribo/text/grouping/group_from_single_link.hh
index e70d8e1..0f4e7b3 100644
--- a/scribo/text/grouping/group_from_single_link.hh
+++ b/scribo/text/grouping/group_from_single_link.hh
@@ -55,12 +55,14 @@ namespace scribo
using namespace mln;
- /// Link text objects with their neighbor line if they have one.
/*!
- ** \param[in] objects An object image.
- ** \param[in] link_array The neighbor line of each line.
- **
- ** \return An object image with grouped objects.
+ \brief Link text objects with their neighbor line if they
+ have one.
+
+ \param[in] objects An object image.
+ \param[in] link_array The neighbor line of each line.
+
+ \return An object image with grouped objects.
*/
template <typename L>
object_image(L)
diff --git a/scribo/text/grouping/group_with_graph.hh
b/scribo/text/grouping/group_with_graph.hh
index c9af430..e13e2e9 100644
--- a/scribo/text/grouping/group_with_graph.hh
+++ b/scribo/text/grouping/group_with_graph.hh
@@ -45,7 +45,8 @@
# include <scribo/core/object_image.hh>
# include <scribo/text/grouping/internal/init_link_array.hh>
# include <scribo/text/grouping/internal/find_graph_link.hh>
-# include <scribo/util/text.hh>
+
+
namespace scribo
{
@@ -56,62 +57,69 @@ namespace scribo
namespace grouping
{
- /// Construct the links between each line of text and store
- /// it as a graph.
- /// Look up for neighbors on the right of each box.
/*!
- ** \param[in] text The lines of text.
- ** \param[in] neighb_max_distance The maximum distance allowed to
- ** look for a neighbor.
- **
- ** \return A graph of relationship.
+ Construct the links between each line of text and store
+ it as a graph.
+ Look up for neighbors on the right of each box.
+
+ \param[in] objects An object image.
+ \param[in] neighb_max_distance The maximum distance allowed to
+ look for a neighbor.
+
+ \return A graph of relationship.
*/
template <typename L>
mln::util::graph
- group_with_graph(const object_image(L)& text,
+ group_with_graph(const object_image(L)& objects,
unsigned neighb_max_distance);
+
# ifndef MLN_INCLUDE_ONLY
template <typename L>
inline
mln::util::graph
- group_with_graph(const object_image(L)& text,
+ group_with_graph(const object_image(L)& objects,
unsigned neighb_max_distance)
{
trace::entering("scribo::text::grouping::group_with_graph");
- mln::util::graph g(text.nlabels().next());
+ mln_precondition(objects.is_valid());
- for_all_ncomponents(i, text.nlabels())
+ mln::util::graph g(objects.nlabels().next());
+
+ for_all_ncomponents(i, objects.nlabels())
{
- unsigned midcol = (text.bbox(i).pmax().col()
- - text.bbox(i).pmin().col()) / 2;
+ unsigned midcol = (objects.bbox(i).pmax().col()
+ - objects.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
mln::util::array<mln_result(accu::center<mln_psite(L)>)>
mass_center = labeling::compute(accu::meta::center(),
- text,
- text.nlabels());
+ objects,
+ objects.nlabels());
// -------
// | |
// | X------->
// | |
// -------
- internal::find_graph_link(g, text, i, dmax, mass_center[i]);
+ internal::find_graph_link(g, objects, i, dmax, mass_center[i]);
}
trace::exiting("scribo::text::grouping::group_with_graph");
return g;
}
+
# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace scribo::text::grouping
} // end of namespace scribo::text
} // end of namespace scribo
+
#endif // ! SCRIBO_TEXT_GROUPING_GROUP_WITH_GRAPH_HH
diff --git a/scribo/text/grouping/internal/is_link_valid.hh
b/scribo/text/grouping/internal/is_link_valid.hh
index 4c54970..32d6747 100644
--- a/scribo/text/grouping/internal/is_link_valid.hh
+++ b/scribo/text/grouping/internal/is_link_valid.hh
@@ -66,7 +66,8 @@ namespace scribo
const mln::util::array<unsigned>& right_link,
unsigned i)
{
- return mln::make::couple(right_link[left_link[i]] == i, left_link[i]);
+ bool b = (right_link[left_link[i]] == i && left_link[i] != i);
+ return mln::make::couple(b, left_link[i]);
}
# endif // ! MLN_INCLUDE_ONLY
--
1.5.6.5