* text/extract_bboxes.hh,
* core/component_bboxes.hh: useless so removed.
* core/object_image.hh: new. Define a macro wrapping labeled_image
type.
* table/extract_lines_with_opening.hh: removed. Replaced by
lines_*_thick.
* table/extract_lines_with_rank.hh: removed. Replaced by
lines_*_discontinued.
* extract/primitive/lines_discontinued.hh,
* extract/primitive/lines_h_discontinued.hh,
* extract/primitive/lines_h_thick.hh,
* extract/primitive/lines_thick.hh,
* extract/primitive/lines_v_discontinued.hh,
* extract/primitive/lines_v_thick.hh,
* extract/primitive/objects.hh,
* table/extract.hh,
* text/grouping/group_from_double_link.hh,
* text/grouping/group_from_graph.hh,
* text/grouping/group_with_several_left_links.hh,
* text/grouping/group_with_several_right_links.hh,
* text/grouping/internal/find_left_link.hh,
* text/grouping/internal/find_right_link.hh,
* text/recognition.hh: make use of labeled_image type.
---
scribo/ChangeLog | 32 +++++
scribo/core/component_bboxes.hh | 92 ------------
scribo/core/object_image.hh | 42 ++++++
scribo/debug/usage.hh | 49 +++++++
scribo/extract/primitive/lines_discontinued.hh | 98 ++++----------
scribo/extract/primitive/lines_h_discontinued.hh | 62 +++------
scribo/extract/primitive/lines_h_thick.hh | 133 ++++++++++++++++++
scribo/extract/primitive/lines_thick.hh | 55 +-------
scribo/extract/primitive/lines_v_discontinued.hh | 60 ++------
scribo/extract/primitive/lines_v_thick.hh | 133 ++++++++++++++++++
scribo/extract/primitive/objects.hh | 47 ++-----
scribo/table/extract.hh | 20 ++--
scribo/table/extract_lines_with_opening.hh | 141 -------------------
scribo/table/extract_lines_with_rank.hh | 146 --------------------
scribo/text/extract_bboxes.hh | 103 --------------
scribo/text/grouping/group_from_double_link.hh | 31 ++---
scribo/text/grouping/group_from_graph.hh | 64 +++------
.../text/grouping/group_with_several_left_links.hh | 34 +++--
.../grouping/group_with_several_right_links.hh | 39 +++---
scribo/text/grouping/internal/find_left_link.hh | 18 +--
scribo/text/grouping/internal/find_right_link.hh | 16 +--
scribo/text/recognition.hh | 37 +++--
22 files changed, 592 insertions(+), 860 deletions(-)
delete mode 100644 scribo/core/component_bboxes.hh
create mode 100644 scribo/core/object_image.hh
create mode 100644 scribo/debug/usage.hh
create mode 100644 scribo/extract/primitive/lines_h_thick.hh
create mode 100644 scribo/extract/primitive/lines_v_thick.hh
delete mode 100644 scribo/table/extract_lines_with_opening.hh
delete mode 100644 scribo/table/extract_lines_with_rank.hh
delete mode 100644 scribo/text/extract_bboxes.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 86d8a0f..0c8eae6 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,35 @@
+2009-05-28 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Make use of labeled_image type in Scribo.
+
+ * text/extract_bboxes.hh,
+ * core/component_bboxes.hh: useless so removed.
+
+ * core/object_image.hh: new. Define a macro wrapping labeled_image
+ type.
+
+ * table/extract_lines_with_opening.hh: removed. Replaced by
+ lines_*_thick.
+
+ * table/extract_lines_with_rank.hh: removed. Replaced by
+ lines_*_discontinued.
+
+ * extract/primitive/lines_discontinued.hh,
+ * extract/primitive/lines_h_discontinued.hh,
+ * extract/primitive/lines_h_thick.hh,
+ * extract/primitive/lines_thick.hh,
+ * extract/primitive/lines_v_discontinued.hh,
+ * extract/primitive/lines_v_thick.hh,
+ * extract/primitive/objects.hh,
+ * table/extract.hh,
+ * text/grouping/group_from_double_link.hh,
+ * text/grouping/group_from_graph.hh,
+ * text/grouping/group_with_several_left_links.hh,
+ * text/grouping/group_with_several_right_links.hh,
+ * text/grouping/internal/find_left_link.hh,
+ * text/grouping/internal/find_right_link.hh,
+ * text/recognition.hh: make use of labeled_image type.
+
2009-05-27 Roland Levillain <roland(a)lrde.epita.fr>
Add the list of SCRIBO's unit tests.
diff --git a/scribo/core/component_bboxes.hh b/scribo/core/component_bboxes.hh
deleted file mode 100644
index 16b6fa0..0000000
--- a/scribo/core/component_bboxes.hh
+++ /dev/null
@@ -1,92 +0,0 @@
-// 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.
-
-
-#ifndef SCRIBO_CORE_COMPONENT_BBOXES_HH
-# define SCRIBO_CORE_COMPONENT_BBOXES_HH
-
-/// \file scribo/core/component_bboxes.hh
-///
-/// Extract the bounding boxes of image components.
-
-# include <mln/core/concept/image.hh>
-# include <mln/core/concept/neighborhood.hh>
-# include <mln/core/site_set/box.hh>
-
-# include <mln/labeling/blobs.hh>
-# include <mln/labeling/compute.hh>
-
-# include <mln/util/array.hh>
-
-# include <mln/debug/println.hh>
-
-namespace scribo
-{
-
- using namespace mln;
-
- /// Extract the components bboxes.
- template <typename I, typename N, typename V>
- util::couple<util::array< box<mln_site(I)> >, mln_ch_value(I,V)>
- component_bboxes(const Image<I>& input,
- const Neighborhood<N>& nbh,
- V& nbboxes);
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename I, typename N, typename V>
- inline
- util::couple<util::array< box<mln_site(I)> >, mln_ch_value(I,V)>
- component_bboxes(const Image<I>& input,
- const Neighborhood<N>& nbh,
- V& nbboxes)
- {
- trace::entering("scribo::component_bboxes");
-
- mlc_equal(mln_value(I),bool)::check();
- mlc_is_a(V, mln::value::Symbolic)::check();
- mln_precondition(exact(input).is_valid());
- mln_precondition(exact(nbh).is_valid());
-
- mln_ch_value(I,V) lbl = labeling::blobs(input, nbh, nbboxes);
- mln_assertion(exact(lbl).is_valid());
-
- typedef util::array< box<mln_site(I)> > bboxes_t;
- bboxes_t bboxes = labeling::compute(accu::meta::bbox(), lbl, nbboxes);
- mln_postcondition(bboxes.nelements() == nbboxes.next());
-
- trace::exiting("scribo::component_bboxes");
- return mln::make::couple(bboxes, lbl);
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
-} // end of namespace scribo
-
-
-#endif // ! SCRIBO_CORE_COMPONENT_BBOXES_HH
diff --git a/scribo/core/object_image.hh b/scribo/core/object_image.hh
new file mode 100644
index 0000000..98c5b83
--- /dev/null
+++ b/scribo/core/object_image.hh
@@ -0,0 +1,42 @@
+// 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.
+
+
+#ifndef SCRIBO_CORE_OBJECT_IMAGE_HH
+# define SCRIBO_CORE_OBJECT_IMAGE_HH
+
+/// \file scribo/core/object_image.hh
+///
+/// FIXME.
+
+# include <mln/core/image/imorph/labeled_image.hh>
+
+# define object_image(L) \
+ labeled_image<L>
+
+#endif // ! SCRIBO_CORE_OBJECT_IMAGE_HH
diff --git a/scribo/debug/usage.hh b/scribo/debug/usage.hh
new file mode 100644
index 0000000..733083e
--- /dev/null
+++ b/scribo/debug/usage.hh
@@ -0,0 +1,49 @@
+// 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.
+
+/// \file scribo/debug/usage.hh
+///
+/// Format program usage.
+
+
+int usage(char* argv[], const char *desc, const char* args,
+ const char*args_desc[][2], const char *out_desc)
+{
+ std::cout << desc << std::endl;
+ std::cout << "-----------" << std::endl;
+ std::cout << "Usage: " << argv[0] << " " <<
args << std::endl;
+
+ for (unsigned i = 0; args_desc[i][0] != 0; ++i)
+ std::cout << " " << args_desc[i][0] << ": "
<< args_desc[i][1]
+ << std::endl;
+
+ std::cout << std::endl << "Output: " << out_desc <<
std::endl;
+ std::cout << "-----------" << std::endl;
+ std::cout << "EPITA/LRDE - Scribo 2009" << std::endl;
+ return 1;
+}
+
diff --git a/scribo/extract/primitive/lines_discontinued.hh
b/scribo/extract/primitive/lines_discontinued.hh
index 5730fcc..1218c2a 100644
--- a/scribo/extract/primitive/lines_discontinued.hh
+++ b/scribo/extract/primitive/lines_discontinued.hh
@@ -30,7 +30,7 @@
#ifndef SCRIBO_EXTRACT_PRIMITIVE_LINES_DISCONTINUED_HH
# define SCRIBO_EXTRACT_PRIMITIVE_LINES_DISCONTINUED_HH
-/// \file scribo/primitive/lines/discontinued.hh
+/// \file scribo/primitive/lines/lines_discontinued.hh
///
/// Extract discontinued lines in a binary image.
@@ -38,19 +38,15 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/window.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/core/site_set/box.hh>
# include <mln/labeling/blobs.hh>
# include <mln/morpho/rank_filter.hh>
-
-# include <mln/accu/bbox.hh>
-
-# include <mln/util/array.hh>
-# include <mln/util/couple.hh>
+# include <mln/morpho/dilation.hh>
# include <scribo/core/macros.hh>
-# include <scribo/core/component_bboxes.hh>
+# include <scribo/core/object_image.hh>
+# include <scribo/extract/primitive/objects.hh>
namespace scribo
{
@@ -70,28 +66,18 @@ namespace scribo
*
* \param[in] input_ A binary image.
* \param[in] nbh_ The neighborhood used for labeling image
- * components.
+ * the lines.
* \param[in,out] nlines The label type used for labeling.
* \param[in] win_ A Window used to extract lines.
* \param[in] rank_k Rank used for filtering.
- * \param[in,out] line_bboxes line bounding boxes.
*
* \return An image in which lines are labeled.
*/
template <typename I, typename N, typename V, typename W>
- mln_ch_value(I,V)
- discontinued(const Image<I>& input_,
- const Neighborhood<N>& nbh_, V& nlines,
- const Window<W>& win_, unsigned rank_k,
- util::array<box<mln_site(I)> >& line_bboxes);
-
-
- /// \overload
- template <typename I, typename N, typename V, typename W>
- mln_ch_value(I,V)
- discontinued(const Image<I>& input_,
- const Neighborhood<N>& nbh_, V& nlines,
- const Window<W>& win_, unsigned rank_k);
+ object_image(mln_ch_value(I,V))
+ lines_discontinued(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_, unsigned rank_k);
@@ -104,12 +90,12 @@ namespace scribo
template <typename I, typename N, typename V, typename W>
void
- discontinued_tests(const Image<I>& input_,
- const Neighborhood<N>& nbh_, V& nlines,
- const Window<W>& win_, unsigned rank_k)
+ lines_discontinued_tests(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ const Window<W>& win, unsigned rank_k)
{
mlc_equal(mln_value(I),bool)::check();
- mlc_equal(mln_site(I)::dim, 2)::check();
+ mlc_bool(mln_site_(I)::dim == 2)::check();
mlc_is_a(V, mln::value::Symbolic)::check();
mln_precondition(exact(input).is_valid());
@@ -126,61 +112,33 @@ namespace scribo
template <typename I, typename N, typename V, typename W>
inline
- mln_ch_value(I,V)
- discontinued(const Image<I>& input_,
- const Neighborhood<N>& nbh_, V& nlines,
- const Window<W>& win_, unsigned rank_k)
- {
- trace::entering("scribo::primitive::discontinued");
-
- internal::discontinued_tests(input_, nbh_, nlines, win_, rank_k);
-
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
- const W& win = exact(win_);
-
- mln_ch_value(I,bool) filter = morpho::rank_filter(input, win, vrank_k);
- mln_ch_value(I,V) output = labeling::blobs(filter, nbh, nlines);
-
- trace::exiting("scribo::primitive::discontinued");
- return output;
- }
-
-
-
-
- template <typename I, typename N, typename V, typename W>
- inline
- mln_ch_value(I,V)
- discontinued(const Image<I>& input_,
- const Neighborhood<N>& nbh_, V& nlines,
- const Window<W>& win_, unsigned rank_k,
- util::array<box<mln_site(I)> >& line_bboxes)
+ object_image(mln_ch_value(I,V))
+ lines_discontinued(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ const Window<W>& win_, unsigned rank_k)
{
- trace::entering("scribo::primitive::discontinued");
+ trace::entering("scribo::primitive::lines_discontinued");
- internal::discontinued_tests(input_, nbh_, nlines, win_, rank_k);
+ internal::lines_discontinued_tests(input_, nbh_, nlines, win_, rank_k);
const I& input = exact(input_);
const N& nbh = exact(nbh_);
const W& win = exact(win_);
- mln_ch_value(I,V)
- output = discontinued(input, nbh, nlines, win, rank_k);
+ mln_ch_value(I,bool) filter
+ = morpho::dilation(morpho::rank_filter(input, win, rank_k), W(win.length() / 2));
+ object_image(mln_ch_value(I,V)) output
+ = extract::primitive::objects(filter, nbh, nlines);
- line_bboxes = labeling::compute(accu::meta::bbox(), output, nlines);
- mln_postcondition(line_bboxes.nelements() == nlines.next());
- // for_all_components(i, line_bboxes)
- // {
- // line_bboxes[i].enlarge(0, win.length() / 2);
- // line_bboxes[i].crop_wrt(input.domain());
- // }
+ //FIXME: we would like to enlarge the component in the right direction,
+ // in order to avoid rank filter side effects (smaller components).
- trace::exiting("scribo::primitive::discontinued");
+ trace::exiting("scribo::primitive::lines_discontinued");
return output;
}
-# endif // !MLN_INCLUDE_ONLY
+
+# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::extract::primitive
diff --git a/scribo/extract/primitive/lines_h_discontinued.hh
b/scribo/extract/primitive/lines_h_discontinued.hh
index 7f31bff..c20c51d 100644
--- a/scribo/extract/primitive/lines_h_discontinued.hh
+++ b/scribo/extract/primitive/lines_h_discontinued.hh
@@ -37,6 +37,11 @@
# include <mln/core/concept/neighborhood.hh>
# include <mln/win/hline2d.hh>
+# include <scribo/core/object_image.hh>
+# include <scribo/extract/primitive/lines_discontinued.hh>
+
+
+
namespace scribo
{
@@ -46,6 +51,7 @@ namespace scribo
namespace primitive
{
+ using namespace mln;
/// Extract horizontal discontinued lines.
/*!
@@ -60,43 +66,36 @@ namespace scribo
* from 0.
*/
template <typename I, typename N, typename V>
- mln_ch_value(I,V)
+ object_image(mln_ch_value(I,V))
lines_h_discontinued(const Image<I>& input,
const Neighborhood<N>& nbh, V& nlines,
unsigned line_length, unsigned rank_k);
- /// \overload
- template <typename I, typename N, typename V>
- mln_ch_value(I,V)
- lines_h_discontinued(const Image<I>& input,
- const Neighborhood<N>& nbh, V& nlines,
- unsigned line_length, unsigned rank_k,
- util::array<box<mln_site(I)> >& line_bboxes);
-
-
# ifndef MLN_INCLUDE_ONLY
namespace internal
{
- template <typename I, typename N, typename V, typename W>
+ template <typename I, typename N, typename V>
void
- lines_h_discontinued_tests(const Image<I>& input_,
- const Neighborhood<N>& nbh_, V& nlines,
+ lines_h_discontinued_tests(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
unsigned line_length, unsigned rank_k)
{
mlc_equal(mln_value(I),bool)::check();
- mlc_equal(mln_site(I)::dim, 2)::check();
+ mlc_bool(mln_site_(I)::dim == 2)::check();
mlc_is_a(V, mln::value::Symbolic)::check();
mln_precondition(exact(input).is_valid());
mln_precondition(exact(nbh).is_valid());
- mln_precondition(exact(win).is_valid());
- mln_precondition(!(line_length % 2));
+ mln_precondition(line_length % 2);
+ (void) input;
+ (void) nbh;
(void) nlines;
+ (void) line_length;
(void) rank_k;
}
@@ -105,20 +104,20 @@ namespace scribo
template <typename I, typename N, typename V>
- mln_ch_value(I,V)
+ object_image(mln_ch_value(I,V))
lines_h_discontinued(const Image<I>& input,
const Neighborhood<N>& nbh, V& nlines,
unsigned line_length, unsigned rank_k)
{
trace::entering("scribo::primitive::lines_h_discontinued");
- internal::line_h_discontinued_tests(input, nbh, nlines,
+ internal::lines_h_discontinued_tests(input, nbh, nlines,
line_length, rank_k);
win::hline2d win(line_length);
- mln_ch_value(I,V)
- output = lines_discontinued(input, nh, nlines, win, rank_k);
+ object_image(mln_ch_value(I,V))
+ output = lines_discontinued(input, nbh, nlines, win, rank_k);
trace::exiting("scribo::primitive::lines_h_discontinued");
return output;
@@ -126,29 +125,6 @@ namespace scribo
- template <typename I, typename N, typename V>
- mln_ch_value(I,V)
- lines_h_discontinued(const Image<I>& input,
- const Neighborhood<N>& nbh, V& nlines,
- unsigned line_length, unsigned rank_k,
- util::array<box<mln_site(I)> >& line_bboxes)
- {
- trace::entering("scribo::primitive::lines_h_discontinued");
-
- internal::line_h_discontinued_tests(input, nbh, nlines,
- line_length, rank_k);
-
- win::hline2d win(line_length);
- mln_ch_value(I,V)
- output = internal::line_h_discontinued_tests(input, nbh, nlines,
- line_length, rank_k,
- line_bboxes);
-
- trace::exiting("scribo::primitive::lines_h_discontinued");
- return output;
- }
-
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::extract::primitive
diff --git a/scribo/extract/primitive/lines_h_thick.hh
b/scribo/extract/primitive/lines_h_thick.hh
new file mode 100644
index 0000000..0762bbc
--- /dev/null
+++ b/scribo/extract/primitive/lines_h_thick.hh
@@ -0,0 +1,133 @@
+// 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.
+
+#ifndef SCRIBO_EXTRACT_PRIMITIVE_LINES_H_THICK_HH
+# define SCRIBO_EXTRACT_PRIMITIVE_LINES_H_THICK_HH
+
+/// \file scribo/primitive/lines_h_thick.hh
+///
+/// Extract horizontal thick lines.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/win/hline2d.hh>
+
+# include <scribo/core/object_image.hh>
+# include <scribo/extract/primitive/lines_thick.hh>
+
+namespace scribo
+{
+
+ namespace extract
+ {
+
+ namespace primitive
+ {
+
+ using namespace mln;
+
+ /// Extract thick lines in a binary image.
+ /*!
+ * Only non discontinued lines are correctly extracted with this routine.
+ *
+ * \param[in] input_ A binary image.
+ * \param[in] nbh_ The neighborhood used for labeling image
+ * components.
+ * \param[in,out] nlines Type used for labeling.
+ * \param[in] line_length The minimum line length.
+ *
+ * \return An image in which lines are labeled.
+ */
+ template <typename I, typename N, typename V, typename W>
+ object_image(mln_ch_value(I,V))
+ lines_thick(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ unsigned line_length);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ 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)
+ {
+ mlc_equal(mln_value(I),bool)::check();
+ mlc_bool(mln_site_(I)::dim == 2)::check();
+ mlc_is_a(V, mln::value::Symbolic)::check();
+
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(exact(nbh).is_valid());
+ mln_precondition(line_length % 2);
+
+ (void) input;
+ (void) nbh;
+ (void) nlines;
+ (void) line_length;
+ }
+
+ } // end of namespace scribo::primitive::internal
+
+
+
+ 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)
+ {
+ trace::entering("scribo::primitive::lines_h_thick");
+
+ internal::lines_h_thick_tests(input, nbh, nlines,
+ line_length);
+
+ win::hline2d win(line_length);
+
+ object_image(mln_ch_value(I,V))
+ output = lines_thick(input, nbh, nlines, win);
+
+ trace::exiting("scribo::primitive::lines_h_thick");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::extract::primitive
+
+ } // end of namespace scribo::extract
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_EXTRACT_PRIMITIVE_LINES_H_THICK_HH
+
diff --git a/scribo/extract/primitive/lines_thick.hh
b/scribo/extract/primitive/lines_thick.hh
index ea5e8d1..3777822 100644
--- a/scribo/extract/primitive/lines_thick.hh
+++ b/scribo/extract/primitive/lines_thick.hh
@@ -38,17 +38,12 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/window.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/core/site_set/box.hh>
-# include <mln/morpho/erosion.hh>
-
-# include <mln/accu/bbox.hh>
-
-# include <mln/util/array.hh>
-# include <mln/util/couple.hh>
+# include <mln/morpho/opening/structural.hh>
+# include <scribo/core/object_image.hh>
# include <scribo/core/macros.hh>
-# include <scribo/core/component_bboxes.hh>
+# include <scribo/extract/primitive/objects.hh>
namespace scribo
{
@@ -71,20 +66,11 @@ namespace scribo
* components.
* \param[in,out] nlines Type used for labeling.
* \param[in] win_ Window used to extract the lines
- * \param[in,out] line_bboxes Line bounding boxes.
*
* \return An image in which lines are labeled.
*/
template <typename I, typename N, typename V, typename W>
- mln_ch_value(I,V)
- lines_thick(const Image<I>& input_,
- const Neighborhood<N>& nbh_, V& nlines,
- const Window<W>& win_,
- util::array<box<mln_site(I)>& line_bboxes);
-
- /// \overload
- template <typename I, typename N, typename V, typename W>
- mln_ch_value(I,V)
+ object_image(mln_ch_value(I,V))
lines_thick(const Image<I>& input_,
const Neighborhood<N>& nbh_, V& nlines,
const Window<W>& win_);
@@ -104,7 +90,7 @@ namespace scribo
const Window<W>& win_)
{
mlc_equal(mln_value(I),bool)::check();
- mlc_equal(mln_site(I)::dim, 2)::check();
+ mlc_bool(mln_site_(I)::dim == 2)::check();
mlc_is_a(V, mln::value::Symbolic)::check();
mln_precondition(exact(input).is_valid());
@@ -120,7 +106,7 @@ namespace scribo
template <typename I, typename N, typename V, typename W>
inline
- mln_ch_value(I,V)
+ object_image(mln_ch_value(I,V))
lines_thick(const Image<I>& input_,
const Neighborhood<N>& nbh_, V& nlines,
const Window<W>& win_)
@@ -134,39 +120,14 @@ namespace scribo
const W& win = exact(win_);
mln_ch_value(I,bool) filter = morpho::opening::structural(input, win);
- mln_ch_value(I,V) output = labeling::blobs(filter, nbh, nlines);
+ object_image(mln_ch_value(I,V)) output
+ = extract::primitive::objects(filter, nbh, nlines);
trace::exiting("scribo::primitive::lines_thick");
return output;
}
-
- template <typename I, typename N, typename V, typename W>
- inline
- mln_ch_value(I,V)
- lines_thick(const Image<I>& input_,
- const Neighborhood<N>& nbh_, V& nlines,
- const Window<W>& win_,
- util::array<box<mln_site(I)>& line_bboxes)
- {
- trace::entering("scribo::primitive::lines_thick");
-
- internal::lines_thick_tests(input_, nbh_, nlines, win_);
-
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
- const W& win = exact(win_);
-
- mln_ch_value(I,V) output = lines_thick(input, nbh, nlines, win);
-
- line_bboxes = labeling::compute(accu::meta::bbox(), output, nlines);
- mln_postcondition(line_bboxes.nelements() == nlines.next());
-
- trace::exiting("scribo::primitive::lines_thick");
- return output;
- }
-
# endif // !MLN_INCLUDE_ONLY
} // end of namespace scribo::extract::primitive
diff --git a/scribo/extract/primitive/lines_v_discontinued.hh
b/scribo/extract/primitive/lines_v_discontinued.hh
index 26edbb4..050e371 100644
--- a/scribo/extract/primitive/lines_v_discontinued.hh
+++ b/scribo/extract/primitive/lines_v_discontinued.hh
@@ -36,6 +36,10 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
+# include <scribo/core/object_image.hh>
+# include <scribo/extract/primitive/lines_discontinued.hh>
+
+
namespace scribo
{
@@ -55,21 +59,12 @@ namespace scribo
* \param[in] line_length The minimum line length expected. (must be
* odd).
* \param[in] rank_k Rank filter parameter.
- * \param[in,out] line_bboxes Will store the line bounding boxes.
*
* \result An image in which lines are labeled with a value different
* from 0.
*/
template <typename I, typename N, typename V>
- mln_ch_value(I,V)
- lines_v_discontinued(const Image<I>& input,
- const Neighborhood<N>& nbh, V& nlines,
- unsigned line_length, unsigned rank_k,
- util::array<box<mln_site(I)> >& line_bboxes);
-
- /// \overload
- template <typename I, typename N, typename V>
- mln_ch_value(I,V)
+ object_image(mln_ch_value(I,V))
lines_v_discontinued(const Image<I>& input,
const Neighborhood<N>& nbh, V& nlines,
unsigned line_length, unsigned rank_k);
@@ -81,20 +76,19 @@ namespace scribo
namespace internal
{
- template <typename I, typename N, typename V, typename W>
+ template <typename I, typename N, typename V>
void
- lines_v_discontinued_tests(const Image<I>& input_,
- const Neighborhood<N>& nbh_, V& nlines,
+ lines_v_discontinued_tests(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
unsigned line_length, unsigned rank_k)
{
mlc_equal(mln_value(I),bool)::check();
- mlc_equal(mln_site(I)::dim, 2)::check();
+ mlc_bool(mln_site_(I)::dim == 2)::check();
mlc_is_a(V, mln::value::Symbolic)::check();
mln_precondition(exact(input).is_valid());
mln_precondition(exact(nbh).is_valid());
- mln_precondition(exact(win).is_valid());
- mln_precondition(!(line_length % 2));
+ mln_precondition(line_length % 2);
(void) nlines;
(void) rank_k;
@@ -105,44 +99,20 @@ namespace scribo
template <typename I, typename N, typename V>
- mln_ch_value(I,V)
+ object_image(mln_ch_value(I,V))
lines_v_discontinued(const Image<I>& input,
const Neighborhood<N>& nbh, V& nlines,
unsigned line_length, unsigned rank_k)
{
trace::entering("scribo::primitive::lines_v_discontinued");
- internal::line_v_discontinued_tests(input, nbh, nlines,
- line_length, rank_k);
-
- win::hline2d win(line_length);
-
- mln_ch_value(I,V)
- output = lines_discontinued(input, nh, nlines, win, rank_k);
-
- trace::exiting("scribo::primitive::lines_v_discontinued");
- return output;
- }
-
-
-
- template <typename I, typename N, typename V>
- mln_ch_value(I,V)
- lines_v_discontinued(const Image<I>& input,
- const Neighborhood<N>& nbh, V& nlines,
- unsigned line_length, unsigned rank_k,
- util::array<box<mln_site(I)> >& line_bboxes)
- {
- trace::entering("scribo::primitive::lines_v_discontinued");
-
- internal::line_v_discontinued_tests(input, nbh, nlines,
+ internal::lines_v_discontinued_tests(input, nbh, nlines,
line_length, rank_k);
win::vline2d win(line_length);
- mln_ch_value(I,V)
- output = internal::line_v_discontinued_tests(input, nbh, nlines,
- line_length, rank_k,
- line_bboxes);
+
+ object_image(mln_ch_value(I,V))
+ output = lines_discontinued(input, nbh, nlines, win, rank_k);
trace::exiting("scribo::primitive::lines_v_discontinued");
return output;
diff --git a/scribo/extract/primitive/lines_v_thick.hh
b/scribo/extract/primitive/lines_v_thick.hh
new file mode 100644
index 0000000..6cdecb7
--- /dev/null
+++ b/scribo/extract/primitive/lines_v_thick.hh
@@ -0,0 +1,133 @@
+// 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.
+
+#ifndef SCRIBO_EXTRACT_PRIMITIVE_LINES_V_THICK_HH
+# define SCRIBO_EXTRACT_PRIMITIVE_LINES_V_THICK_HH
+
+/// \file scribo/primitive/lines_v_thick.hh
+///
+/// Extract vertical thick lines.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/win/vline2d.hh>
+
+# include <scribo/core/object_image.hh>
+# include <scribo/extract/primitive/lines_thick.hh>
+
+namespace scribo
+{
+
+ namespace extract
+ {
+
+ namespace primitive
+ {
+
+ using namespace mln;
+
+ /// Extract thick lines in a binary image.
+ /*!
+ * Only non discontinued lines are correctly extracted with this routine.
+ *
+ * \param[in] input_ A binary image.
+ * \param[in] nbh_ The neighborhood used for labeling image
+ * components.
+ * \param[in,out] nlines Type used for labeling.
+ * \param[in] line_length The minimum line length.
+ *
+ * \return An image in which lines are labeled.
+ */
+ template <typename I, typename N, typename V, typename W>
+ object_image(mln_ch_value(I,V))
+ lines_thick(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ unsigned line_length);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ template <typename I, typename N, typename V>
+ void
+ lines_v_thick_tests(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length)
+ {
+ mlc_equal(mln_value(I),bool)::check();
+ mlc_bool(mln_site_(I)::dim == 2)::check();
+ mlc_is_a(V, mln::value::Symbolic)::check();
+
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(exact(nbh).is_valid());
+ mln_precondition(line_length % 2);
+
+ (void) input;
+ (void) nbh;
+ (void) nlines;
+ (void) line_length;
+ }
+
+ } // end of namespace scribo::primitive::internal
+
+
+
+ template <typename I, typename N, typename V>
+ object_image(mln_ch_value(I,V))
+ lines_v_thick(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned line_length)
+ {
+ trace::entering("scribo::primitive::lines_v_thick");
+
+ internal::lines_v_thick_tests(input, nbh, nlines,
+ line_length);
+
+ win::vline2d win(line_length);
+
+ object_image(mln_ch_value(I,V))
+ output = lines_thick(input, nbh, nlines, win);
+
+ trace::exiting("scribo::primitive::lines_v_thick");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::extract::primitive
+
+ } // end of namespace scribo::extract
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_EXTRACT_PRIMITIVE_LINES_V_THICK_HH
+
diff --git a/scribo/extract/primitive/objects.hh b/scribo/extract/primitive/objects.hh
index cc55d72..4ac0bed 100644
--- a/scribo/extract/primitive/objects.hh
+++ b/scribo/extract/primitive/objects.hh
@@ -35,7 +35,6 @@
/// Extract objects in a binary image.
-# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/site_set/box.hh>
@@ -46,6 +45,12 @@
# include <mln/debug/println.hh>
+# include <scribo/core/object_image.hh>
+
+#include <mln/accu/bbox.hh>
+#include <mln/accu/center.hh>
+
+
namespace scribo
{
@@ -63,24 +68,12 @@ namespace scribo
/// and background to 'false'.
/// \param[in] nbh A neighborhood to be used for labeling.
/// \param[in,out] nobjects Will store the numbers of objects found.
- /// \param[in,out] bboxes Will store the objects bounding boxes.
///
/// \return An image of labeled objects.
//
template <typename I, typename N, typename V>
inline
- mln_ch_value(I,V)
- objects(const Image<I>& input,
- const Neighborhood<N>& nbh, V& nobjects,
- util::array< box<mln_site(I)> >& bboxes);
-
-
- /// Extract objects in a binary image.
- /// \overload
- //
- template <typename I, typename N, typename V>
- inline
- mln_ch_value(I,V)
+ object_image(mln_ch_value(I,V))
objects(const Image<I>& input,
const Neighborhood<N>& nbh, V& nobjects);
@@ -112,27 +105,7 @@ namespace scribo
template <typename I, typename N, typename V>
inline
- mln_ch_value(I,V)
- objects(const Image<I>& input,
- const Neighborhood<N>& nbh, V& nobjects,
- util::array< box<mln_site(I)> >& bboxes)
- {
- trace::entering("scribo::objects");
-
- internal::objects_tests(input, nbh, nobjects);
-
- mln_ch_value(I,V) object = objects(input, nbh, nobjects);
-
- bboxes = labeling::compute(accu::meta::bbox(), lbl, nobjects);
-
- trace::exiting("scribo::objects");
- return output;
- }
-
-
- template <typename I, typename N, typename V>
- inline
- mln_ch_value(I,V)
+ object_image(mln_ch_value(I,V))
objects(const Image<I>& input,
const Neighborhood<N>& nbh, V& nobjects)
{
@@ -140,7 +113,9 @@ namespace scribo
internal::objects_tests(input, nbh, nobjects);
- mln_ch_value(I,V) object = labeling::blobs(input, nbh, nobjects);
+ mln_ch_value(I,V) objects = labeling::blobs(input, nbh, nobjects);
+
+ object_image(mln_ch_value(I,V)) output(objects, nobjects);
trace::exiting("scribo::objects");
return output;
diff --git a/scribo/table/extract.hh b/scribo/table/extract.hh
index ebe4955..32f8965 100644
--- a/scribo/table/extract.hh
+++ b/scribo/table/extract.hh
@@ -40,7 +40,8 @@
# include <scribo/table/rebuild.hh>
# include <scribo/table/erase.hh>
-# include <scribo/table/extract_lines_with_rank.hh>
+# include <scribo/extract/primitive/lines_h_discontinued.hh>
+# include <scribo/extract/primitive/lines_v_discontinued.hh>
# include <scribo/make/debug_filename.hh>
@@ -83,20 +84,19 @@ namespace scribo
mln_precondition(input.is_valid());
mlc_equal(mln_value(I), bool)::check();
- typedef util::array< box<mln_site(I)> > boxarray_t;
- typedef util::couple<boxarray_t, boxarray_t> tblboxes_t;
-
- win::line<mln_grid(I::site), 0, mln_coord(I::site)> vline(51);
- win::line<mln_grid(I::site), 1, mln_coord(I::site)> hline(51);
- tblboxes_t lineboxes
- = table::extract_lines_with_rank(input, c8(), ncells,
- vline, hline, 6, 6);
+ V nhlines, nvlines;
+ object_image(mln_ch_value(I,V))
+ hlines = extract::primitive::lines_h_discontinued(input, c8(), nhlines, 51, 6),
+ vlines = extract::primitive::lines_v_discontinued(input, c8(), nvlines, 51, 6);
typedef mln::util::couple<mln_ch_value(I,V),
util::couple<util::array<box<mln_site(I)> >,
util::array<box<mln_site(I)> > > >
tables_t;
- tables_t tables = scribo::table::rebuild(input, lineboxes, 30, ncells);
+ tables_t tables
+ = scribo::table::rebuild(input,
+ mln::make::couple(vlines.bboxes(), hlines.bboxes()),
+ 30, ncells);
trace::exiting("scribo::table::extract");
return tables;
diff --git a/scribo/table/extract_lines_with_opening.hh
b/scribo/table/extract_lines_with_opening.hh
deleted file mode 100644
index c3454db..0000000
--- a/scribo/table/extract_lines_with_opening.hh
+++ /dev/null
@@ -1,141 +0,0 @@
-// 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.
-
-
-#ifndef SCRIBO_TABLE_EXTRACT_LINES_WITH_OPENING_HH
-# define SCRIBO_TABLE_EXTRACT_LINES_WITH_OPENING_HH
-
-/// \file scribo/table/extract_lines_with_opening.hh
-///
-/// Extract table lines using a morphological opening filter.
-
-
-# include <mln/core/concept/image.hh>
-# include <mln/core/concept/window.hh>
-# include <mln/core/concept/neighborhood.hh>
-# include <mln/core/site_set/box.hh>
-
-# include <mln/morpho/erosion.hh>
-
-# include <mln/accu/bbox.hh>
-
-# include <mln/util/array.hh>
-# include <mln/util/couple.hh>
-
-# include <scribo/core/macros.hh>
-# include <scribo/core/component_bboxes.hh>
-
-namespace scribo
-{
-
- namespace table
- {
-
- using namespace mln;
-
- /// Find table bboxes thanks to a opening filter.
- /*!
- *
- * \param[in] input_ A binary image.
- * \param[in] nbh_ The neighborhood used for labeling image components.
- * \param[in] label_type Type used for labeling.
- * \param[in] vwin_ Window used to extract the vertical lines in a morphological
- * opening
- * \param[in] hwin_ Window used to extract the horizontal lines in a morphological
- * opening
- *
- * \return pair of array of bounding boxes. The first array holds the
- * vertical lines bounding boxes and the second one the
- * horizontal lines bounding boxes.
- */
- template <typename I, typename N, typename V, typename VW, typename HW>
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >
- extract_lines_with_opening(const Image<I>& input_,
- const Neighborhood<N>& nbh_, const V& label_type,
- const Window<VW>& vwin_, const Window<HW>& hwin_);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename I, typename N, typename V, typename VW, typename HW>
- inline
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >
- extract_lines_with_opening(const Image<I>& input_,
- const Neighborhood<N>& nbh_, const V& label_type,
- const Window<VW>& vwin_, const Window<HW>& hwin_)
- {
- trace::entering("scribo::table::extract_lines_with_opening");
-
- mlc_equal(mln_value(I),bool)::check();
- mlc_is_a(V, mln::value::Symbolic)::check();
-
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
- const VW& vwin = exact(vwin_);
- const HW& hwin = exact(hwin_);
-
- mln_precondition(input.is_valid());
- mln_precondition(nbh.is_valid());
- mln_precondition(vwin.is_valid());
- mln_precondition(hwin.is_valid());
-
- typedef util::array<box<mln_site(I)> > boxes_t;
-
- V ncomps;
-
- // Vertical lines
- mln_ch_value(I,bool) vfilter = morpho::erosion(input, vwin);
- boxes_t vboxes = component_bboxes(vfilter, nbh, ncomps).first();
- for_all_components(i, vboxes)
- {
- vboxes[i].enlarge(0, vwin.length() / 2);
- vboxes[i].crop_wrt(input.domain());
- }
-
- // Horizontal lines.
- mln_ch_value(I,bool) hfilter = morpho::erosion(input, hwin);
- boxes_t hboxes = component_bboxes(hfilter, nbh, ncomps).first();
- for_all_components(i, hboxes)
- {
- hboxes[i].enlarge(1, hwin.length() / 2);
- hboxes[i].crop_wrt(input.domain());
- }
-
- trace::exiting("scribo::table::extract_lines_with_opening");
- return mln::make::couple(vboxes, hboxes);
- }
-
-# endif // !MLN_INCLUDE_ONLY
-
- } // end of namespace scribo::table
-
-} // end of namespace scribo
-
-#endif // ! SCRIBO_TABLE_EXTRACT_LINES_WITH_OPENING_HH
diff --git a/scribo/table/extract_lines_with_rank.hh
b/scribo/table/extract_lines_with_rank.hh
deleted file mode 100644
index c6eb1fa..0000000
--- a/scribo/table/extract_lines_with_rank.hh
+++ /dev/null
@@ -1,146 +0,0 @@
-// 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.
-
-
-#ifndef SCRIBO_TABLE_EXTRACT_LINES_WITH_RANK_HH
-# define SCRIBO_TABLE_EXTRACT_LINES_WITH_RANK_HH
-
-/// \file scribo/table/extract_lines_with_rank.hh
-///
-/// Extract table lines using a rank filter.
-
-
-# include <mln/core/concept/image.hh>
-# include <mln/core/concept/window.hh>
-# include <mln/core/concept/neighborhood.hh>
-# include <mln/core/site_set/box.hh>
-
-# include <mln/morpho/rank_filter.hh>
-
-# include <mln/accu/bbox.hh>
-
-# include <mln/util/array.hh>
-# include <mln/util/couple.hh>
-
-# include <scribo/core/macros.hh>
-# include <scribo/core/component_bboxes.hh>
-
-namespace scribo
-{
-
- namespace table
- {
-
- using namespace mln;
-
- /// Find table bboxes thanks to a rank filter.
- /*!
- *
- * \param[in] input_ A binary image.
- * \param[in] nbh_ The neighborhood used for labeling image components.
- * \param[in] label_type The label type used for labeling.
- * \param[in] vwin_ Window used to extract the vertical lines in the rank
- * filter.
- * \param[in] hwin_ Window used to extract the horizontal lines in the rank
- * filter.
- * \param[in] vrank_k Rank used for vertical lines filtering.
- * \param[in] hrank_k Rank used for horizontal lines filtering.
- *
- * \return pair of array of bounding boxes. The first array holds the
- * vertical lines bounding boxes and the second one the
- * horizontal lines bounding boxes.
- */
- template <typename I, typename N, typename V, typename VW, typename HW>
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >
- extract_lines_with_rank(const Image<I>& input_,
- const Neighborhood<N>& nbh_, const V& label_type,
- const Window<VW>& vwin_, const Window<HW>& hwin_,
- unsigned vrank_k, unsigned hrank_k);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename I, typename N, typename V, typename VW, typename HW>
- inline
- util::couple<util::array<box<mln_site(I)> >,
- util::array<box<mln_site(I)> > >
- extract_lines_with_rank(const Image<I>& input_,
- const Neighborhood<N>& nbh_, const V& label_type,
- const Window<VW>& vwin_, const Window<HW>& hwin_,
- unsigned vrank_k, unsigned hrank_k)
- {
- trace::entering("scribo::table::extract_lines_with_rank");
-
- mlc_equal(mln_value(I),bool)::check();
- mlc_is_a(V, mln::value::Symbolic)::check();
-
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
- const VW& vwin = exact(vwin_);
- const HW& hwin = exact(hwin_);
- (void) label_type;
-
- mln_precondition(input.is_valid());
- mln_precondition(nbh.is_valid());
- mln_precondition(vwin.is_valid());
- mln_precondition(hwin.is_valid());
-
- typedef util::array<box<mln_site(I)> > boxes_t;
-
- V nbboxes;
-
- // Vertical lines
- mln_ch_value(I,bool) vfilter = morpho::rank_filter(input, vwin, vrank_k);
- boxes_t vboxes = component_bboxes(vfilter, nbh, nbboxes).first();
- for_all_components(i, vboxes)
- {
- vboxes[i].enlarge(0, vwin.length() / 2);
- vboxes[i].crop_wrt(input.domain());
- }
-
- // Horizontal lines.
- mln_ch_value(I,bool) hfilter = morpho::rank_filter(input, hwin, hrank_k);
- boxes_t hboxes = component_bboxes(hfilter, nbh, nbboxes).first();
- for_all_components(i, hboxes)
- {
- hboxes[i].enlarge(1, hwin.length() / 2);
- hboxes[i].crop_wrt(input.domain());
- }
-
- trace::exiting("scribo::table::extract_lines_with_rank");
- return mln::make::couple(vboxes, hboxes);
- }
-
-# endif // !MLN_INCLUDE_ONLY
-
- } // end of namespace scribo::table
-
-} // end of namespace scribo
-
-#endif // ! SCRIBO_TABLE_EXTRACT_LINES_WITH_RANK_HH
diff --git a/scribo/text/extract_bboxes.hh b/scribo/text/extract_bboxes.hh
deleted file mode 100644
index 8908677..0000000
--- a/scribo/text/extract_bboxes.hh
+++ /dev/null
@@ -1,103 +0,0 @@
-// 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.
-
-
-#ifndef SCRIBO_TEXT_GROUPING_EXTRACT_BBOXES_HH
-# define SCRIBO_TEXT_GROUPING_EXTRACT_BBOXES_HH
-
-/// \file scribo/text/extract_bboxes.hh
-///
-/// Extract text bounding boxes from a binary image.
-
-# include <mln/core/concept/image.hh>
-# include <mln/core/concept/neighborhood.hh>
-# include <mln/core/site_set/box.hh>
-# include <mln/labeling/blobs.hh>
-# include <mln/labeling/compute.hh>
-# include <mln/util/array.hh>
-
-# include <scribo/core/component_bboxes.hh>
-# include <scribo/util/text.hh>
-# include <scribo/make/text.hh>
-
-namespace scribo
-{
-
- namespace text
- {
-
- using namespace mln;
-
- /// Extract text bounding boxes from a binary image.
- ///
- /// \param[in] input_ A binary imag.
- /// \param[in] nbh_ The neighborhood used for labeling.
- /// \param[in,out] nbboxes Will hold the number of bounding boxes at
- /// the end of the routine.
- ///
- /// \return an array of bounding boxes. The first bounding box is
- /// the background's.
- template <typename I, typename N, typename V>
- scribo::util::text<mln_ch_value(I,V)>
- extract_bboxes(const Image<I>& input_,
- const Neighborhood<N>& nbh_, V& nbboxes);
-
-# ifndef MLN_INCLUDE_ONLY
-
-
- template <typename I, typename N, typename V>
- inline
- scribo::util::text<mln_ch_value(I,V)>
- extract_bboxes(const Image<I>& input_,
- const Neighborhood<N>& nbh_, V& nbboxes)
- {
- trace::entering("scribo::text::extract_bboxes");
-
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
-
- mlc_equal(mln_value(I), bool)::check();
- mln_precondition(input.is_valid());
- mln_precondition(nbh.is_valid());
-
- typedef mln::util::array< box<mln_site(I)> > bboxes_t;
- typedef mln::util::couple<bboxes_t, mln_ch_value(I,V)> bboxes_and_lbl_t;
- bboxes_and_lbl_t bboxes_and_lbl = component_bboxes(input, nbh, nbboxes);
-
- trace::exiting("scribo::text::extract_bboxes");
- return scribo::make::text(bboxes_and_lbl.first(),
- bboxes_and_lbl.second(), nbboxes);
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace scribo::text
-
-} // end of namespace scribo
-
-#endif // ! SCRIBO_TEXT_GROUPING_EXTRACT_BBOXES_HH
diff --git a/scribo/text/grouping/group_from_double_link.hh
b/scribo/text/grouping/group_from_double_link.hh
index 7caac87..4ed5d74 100644
--- a/scribo/text/grouping/group_from_double_link.hh
+++ b/scribo/text/grouping/group_from_double_link.hh
@@ -66,16 +66,16 @@ namespace scribo
/// 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] text The Lines of text.
+ ** \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.
*/
- template <typename I>
- scribo::util::text<I>
- group_from_double_link(const scribo::util::text<I>& text,
+ 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);
@@ -84,10 +84,10 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
- template <typename I>
+ template <typename L>
inline
- scribo::util::text<I>
- group_from_double_link(const scribo::util::text<I>& text,
+ 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)
{
@@ -95,12 +95,9 @@ namespace scribo
mln_precondition(left_link.nelements() == right_link.nelements());
- mln::util::array< accu::bbox<mln_site(I)> > tboxes;
- tboxes.resize(text.bboxes().nelements());
-
mln::util::array<unsigned> parent(left_link.nelements());
internal::init_link_array(parent);
- for_all_components(i, text.bboxes())
+ for_all_ncomponents(i, objects.nlabels())
{
mln::util::couple<bool, unsigned>
nbh = internal::is_link_valid(left_link, right_link, i);
@@ -114,19 +111,15 @@ namespace scribo
}
}
- for_all_elements(i, parent)
for (unsigned i = parent.nelements() - 1; i < parent.nelements(); --i)
- {
parent[i] = parent[parent[i]];
- tboxes[parent[i]].take(text.bbox(i));
- }
- fun::i2v::array<unsigned> f;
- convert::from_to(parent, f);
+ object_image(L) output;
+ output.init_from_(objects);
+ output.relabel(parent);
- scribo::util::text<I> result = make::text(text, f);
trace::exiting("scribo::text::grouping::group_from_double_link");
- return result;
+ return output;
}
diff --git a/scribo/text/grouping/group_from_graph.hh
b/scribo/text/grouping/group_from_graph.hh
index 3c6ac3a..d28e047 100644
--- a/scribo/text/grouping/group_from_graph.hh
+++ b/scribo/text/grouping/group_from_graph.hh
@@ -46,6 +46,7 @@
# include <mln/fun/i2v/array.hh>
# include <mln/util/array.hh>
+# include <mln/util/graph_ids.hh>
# include <scribo/core/macros.hh>
# include <scribo/util/text.hh>
@@ -83,15 +84,14 @@ namespace scribo
/// Functor to be passed to depth_first_search.
/// Map each component vertex with its representative vertex id.
template <typename V>
- struct map_vertex_to_component_id_functor
+ struct map_vertex_to_representative_id_functor
{
/// Initialize the functor.
template <typename G>
void init(const Graph<G>& g)
{
- vertextocomp.resize(exact(g).v_nmax(), mln_max(V));
- ncomp = 0;
+ vertextorep.resize(exact(g).v_nmax(), mln_max(V));
}
/// All components have been processed.
@@ -100,35 +100,40 @@ namespace scribo
/// Starting to treat a new component.
void next_component()
- { ++ncomp; }
+ {}
/// A vertex with id \p id has been found in the current
/// component.
- void new_component_from_vertex(unsigned id)
- { vertextocomp(id) = ncomp; }
+ void new_component_from_vertex(const mln::util::vertex_id_t& id)
+ {
+ current_ = id;
+ vertextorep(id) = id;
+ }
/// A new neighbor with id \p id have been found for the
/// current vertex.
- void added_to_queue(unsigned id)
- { new_component_from_vertex(id); }
+ void added_to_queue(const mln::util::vertex_id_t&)
+ {}
/// Starting to process a new vertex.
- void process_vertex(unsigned)
- {}
+ void process_vertex(const mln::util::vertex_id_t& id)
+ {
+ vertextorep(id) = current_;
+ }
/// Does the vertex with id \p id have been already treated?
- bool to_be_treated(unsigned id)
- { return vertextocomp(id) == mln_max(V); }
+ bool to_be_treated(const mln::util::vertex_id_t& id)
+ { return vertextorep(id) == mln_max(V); }
/// Does the neighbor vertex \p id have been already treated?
- bool to_be_queued(unsigned id)
+ bool to_be_queued(const mln::util::vertex_id_t& id)
{ return to_be_treated(id); }
/// The number of components found.
- unsigned ncomp;
+ mln::util::vertex_id_t current_;
/// Map a verted id to its component id.
- fun::i2v::array<V> vertextocomp;
+ fun::i2v::array<V> vertextorep;
};
} // end of namespace scribo::text::grouping::internal
@@ -147,36 +152,13 @@ namespace scribo
mln_assertion(g.is_valid());
- internal::map_vertex_to_component_id_functor<mln_value(I)> f;
+ internal::map_vertex_to_representative_id_functor<mln_value(I)> f;
canvas::browsing::depth_first_search(g, f);
-// mln::util::array< accu::bbox<mln_site(I)> > tboxes;
-// tboxes.resize(text.nbboxes().next());
-// for_all_components(i, text.bboxes())
-// tboxes[f.vertextocomp(i)].take(text.bbox(i));
-//
-// // Update bounding boxes.
-// mln::util::array<box<mln_site(I)> > bresult;
-// // Component 0 - the background has not valid bboxes.
-// bresult.append(box<mln_site(I)>());
-// for_all_components(i, text.bboxes())
-// if (tboxes[i].is_valid())
-// bresult.append(tboxes[i].to_result());
-//
-// mln_assertion(bresult.nelements() == f.ncomp);
-//
-// // Update label image.
-// mln_value(I) new_nbboxes;
-// I new_lbl = labeling::relabel(text.label_image(),
-// text.nbboxes(),
-// f.vertextocomp);
-//
-// mln_assertion(new_nbboxes.next() == bresult.nelements());
+ scribo::util::text<I> output = scribo::make::text(text, f.vertextorep);
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);
- return scribo::make::text(text, f.vertextocomp);
+ return output;
}
diff --git a/scribo/text/grouping/group_with_several_left_links.hh
b/scribo/text/grouping/group_with_several_left_links.hh
index 666a283..ce113b2 100644
--- a/scribo/text/grouping/group_with_several_left_links.hh
+++ b/scribo/text/grouping/group_with_several_left_links.hh
@@ -64,7 +64,7 @@ namespace scribo
template <typename L>
inline
mln::util::array<unsigned>
- group_with_several_left_links(const scribo::util::text<L>& text,
+ group_with_several_left_links(const object_image(L)& objects,
unsigned neighb_max_distance);
# ifndef MLN_INCLUDE_ONLY
@@ -72,21 +72,25 @@ namespace scribo
template <typename L>
inline
mln::util::array<unsigned>
- group_with_several_left_links(const scribo::util::text<L>& text,
+ group_with_several_left_links(const object_image(L)& objects,
unsigned neighb_max_distance)
{
trace::entering("scribo::text::grouping::group_with_several_left_links");
- mln_precondition(text.is_valid());
+ mln_precondition(objects.is_valid());
mln::util::array<unsigned>
- link_1(text.nbboxes().next()), link_2(text.nbboxes().next()),
- link_3(text.nbboxes().next()), final_link(text.nbboxes().next());
+ link_1(objects.nlabels().next()), link_2(objects.nlabels().next()),
+ link_3(objects.nlabels().next()), final_link(objects.nlabels().next());
internal::init_link_array(link_1);
internal::init_link_array(link_2);
internal::init_link_array(link_3);
- for_all_ncomponents(i, text.nbboxes())
+ mln::util::array<mln_result(accu::center<mln_psite(L)>)>
+ mass_centers = labeling::compute(accu::meta::center(),
+ objects, objects.nlabels());
+
+ for_all_ncomponents(i, objects.nlabels())
{
// -------
// <------X |
@@ -97,27 +101,27 @@ namespace scribo
// | |
// <------X |
// -------
- unsigned midcol = (text.bbox(i).pmax().col()
- - text.bbox(i).pmin().col()) / 2;
+ unsigned midcol = (objects.bbox(i).pmax().col()
+ - objects.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
- mln_site(L) c = text.bbox(i).center();
+ mln_site(L) c = objects.bbox(i).center();
/// Left link from the top anchor.
mln_site(L) a1 = c;
- a1.row() = text.bbox(i).pmin().row() + (c.row() - text.bbox(i).pmin().row()) / 4;
- internal::find_left_link(text, link_1, i, dmax, a1);
+ a1.row() = objects.bbox(i).pmin().row() + (c.row() - objects.bbox(i).pmin().row()) /
4;
+ internal::find_left_link(objects, link_1, i, dmax, a1);
/// Left link from the central site
- internal::find_left_link(text, link_2, i, dmax, text.mass_center(i));
+ internal::find_left_link(objects, link_2, i, dmax, mass_centers[i]);
/// Left link from the bottom anchor.
mln_site(L) a2 = c;
- a2.row() = text.bbox(i).pmax().row() - (c.row() - text.bbox(i).pmin().row()) / 4;
- internal::find_left_link(text, link_3, i, dmax, a2);
+ a2.row() = objects.bbox(i).pmax().row() - (c.row() - objects.bbox(i).pmin().row()) /
4;
+ internal::find_left_link(objects, link_3, i, dmax, a2);
}
- for_all_ncomponents(i, text.nbboxes())
+ for_all_ncomponents(i, objects.nlabels())
{
if (link_2[i] != i)
final_link[i] = link_2[i];
diff --git a/scribo/text/grouping/group_with_several_right_links.hh
b/scribo/text/grouping/group_with_several_right_links.hh
index f7d38a7..05c6e52 100644
--- a/scribo/text/grouping/group_with_several_right_links.hh
+++ b/scribo/text/grouping/group_with_several_right_links.hh
@@ -64,29 +64,34 @@ namespace scribo
template <typename L>
inline
mln::util::array<unsigned>
- group_with_several_right_links(const scribo::util::text<L>& text,
- unsigned neighb_max_distance);
+ group_with_several_right_links(const object_image(L)& objects,
+ unsigned neighb_max_distance);
# ifndef MLN_INCLUDE_ONLY
template <typename L>
inline
mln::util::array<unsigned>
- group_with_several_right_links(const scribo::util::text<L>& text,
- unsigned neighb_max_distance)
+ group_with_several_right_links(const object_image(L)& objects,
+ unsigned neighb_max_distance)
{
trace::entering("scribo::text::grouping::group_with_several_right_links");
- mln_precondition(text.is_valid());
+ mln_precondition(objects.is_valid());
mln::util::array<unsigned>
- link_1(text.nbboxes().next()), link_2(text.nbboxes().next()),
- link_3(text.nbboxes().next()), final_link(text.nbboxes().next());
+ link_1(objects.nlabels().next()), link_2(objects.nlabels().next()),
+ link_3(objects.nlabels().next()), final_link(objects.nlabels().next());
internal::init_link_array(link_1);
internal::init_link_array(link_2);
internal::init_link_array(link_3);
- for_all_ncomponents(i, text.nbboxes())
+ mln::util::array<mln_result(accu::center<mln_psite(L)>)>
+ mass_centers = labeling::compute(accu::meta::center(),
+ objects, objects.nlabels());
+
+
+ for_all_ncomponents(i, objects.nlabels())
{
// -------
// | X------->
@@ -97,27 +102,27 @@ namespace scribo
// | |
// | X------->
// -------
- unsigned midcol = (text.bbox(i).pmax().col()
- - text.bbox(i).pmin().col()) / 2;
+ unsigned midcol = (objects.bbox(i).pmax().col()
+ - objects.bbox(i).pmin().col()) / 2;
int dmax = midcol + neighb_max_distance;
- mln_site(L) c = text.bbox(i).center();
+ mln_site(L) c = objects.bbox(i).center();
/// Right link from the top anchor.
mln_site(L) a1 = c;
- a1.row() = text.bbox(i).pmin().row() + (c.row() - text.bbox(i).pmin().row()) / 4;
- internal::find_right_link(text, link_1, i, dmax, a1);
+ a1.row() = objects.bbox(i).pmin().row() + (c.row() - objects.bbox(i).pmin().row()) /
4;
+ internal::find_right_link(objects, link_1, i, dmax, a1);
/// Right link from the central site
- internal::find_right_link(text, link_2, i, dmax, text.mass_center(i));
+ internal::find_right_link(objects, link_2, i, dmax, mass_centers[i]);
/// Right link from the bottom anchor.
mln_site(L) a2 = c;
- a2.row() = text.bbox(i).pmax().row() - (c.row() - text.bbox(i).pmin().row()) / 4;
- internal::find_right_link(text, link_3, i, dmax, a2);
+ a2.row() = objects.bbox(i).pmax().row() - (c.row() - objects.bbox(i).pmin().row()) /
4;
+ internal::find_right_link(objects, link_3, i, dmax, a2);
}
- for_all_ncomponents(i, text.nbboxes())
+ for_all_ncomponents(i, objects.nlabels())
{
if (link_2[i] != i)
final_link[i] = link_2[i];
diff --git a/scribo/text/grouping/internal/find_left_link.hh
b/scribo/text/grouping/internal/find_left_link.hh
index e4fed4f..f598115 100644
--- a/scribo/text/grouping/internal/find_left_link.hh
+++ b/scribo/text/grouping/internal/find_left_link.hh
@@ -59,14 +59,14 @@ namespace scribo
/// Find the left neighbor of a line of text if exists.
///
- /// \param text The lines of text.
+ /// \param objects An image of objects.
/// \param left_link The left neighbors.
/// \param current_comp A text line id.
/// \param dmax The maximum lookup distance.
/// \param c The lookup start point.
template <typename L>
void
- find_left_link(const scribo::util::text<L>& text,
+ find_left_link(const object_image(L)& objects,
mln::util::array<unsigned>& left_link,
unsigned current_comp,
int dmax,
@@ -76,7 +76,7 @@ namespace scribo
template <typename L>
void
- find_left_link(const scribo::util::text<L>& text,
+ find_left_link(const object_image(L)& objects,
mln::util::array<unsigned>& left_link,
unsigned current_comp,
int dmax,
@@ -86,16 +86,14 @@ namespace scribo
/// First site on the right of the central site
mln_site(L) p = c + left;
- const L& lbl = text.label_image();
-
- while (lbl.domain().has(p) // Not outside image domain
- && (lbl(p) == literal::zero // Is the background
- || lbl(p) == current_comp // Is the current component
- || left_link[lbl(p)] == current_comp) // Creates a loop
+ while (objects.domain().has(p) // Not outside image domain
+ && (objects(p) == literal::zero // Is the background
+ || objects(p) == current_comp // Is the current component
+ || left_link[objects(p)] == current_comp) // Creates a loop
&& math::abs(p.col() - c.col()) < dmax) // Not to far
--p.col();
- update_link_array(lbl, left_link, p, c, current_comp, dmax);
+ update_link_array(objects, left_link, p, c, current_comp, dmax);
}
# endif // MLN_INCLUDE_ONLY
diff --git a/scribo/text/grouping/internal/find_right_link.hh
b/scribo/text/grouping/internal/find_right_link.hh
index 768861b..3f137c5 100644
--- a/scribo/text/grouping/internal/find_right_link.hh
+++ b/scribo/text/grouping/internal/find_right_link.hh
@@ -66,7 +66,7 @@ namespace scribo
/// \param c The lookup start point.
template <typename L>
void
- find_right_link(const scribo::util::text<L>& text,
+ find_right_link(const object_image(L)& text,
mln::util::array<unsigned>& right_link,
unsigned current_comp,
int dmax,
@@ -76,7 +76,7 @@ namespace scribo
template <typename L>
void
- find_right_link(const scribo::util::text<L>& text,
+ find_right_link(const object_image(L)& objects,
mln::util::array<unsigned>& right_link,
unsigned current_comp,
int dmax,
@@ -86,16 +86,14 @@ namespace scribo
/// First site on the right of the central site
mln_site(L) p = c + right;
- const L& lbl = text.label_image();
-
- while (lbl.domain().has(p) // Not outside image domain
- && (lbl(p) == literal::zero // Is the background
- || lbl(p) == current_comp // Is the current component
- || right_link[lbl(p)] == current_comp) // Creates a loop
+ while (objects.domain().has(p) // Not outside image domain
+ && (objects(p) == literal::zero // Is the background
+ || objects(p) == current_comp // Is the current component
+ || right_link[objects(p)] == current_comp) // Creates a loop
&& math::abs(p.col() - c.col()) < dmax) // Not too far
++p.col();
- update_link_array(lbl, right_link, p, c, current_comp, dmax);
+ update_link_array(objects, right_link, p, c, current_comp, dmax);
}
# endif // MLN_INCLUDE_ONLY
diff --git a/scribo/text/recognition.hh b/scribo/text/recognition.hh
index 287be34..8cfd20e 100644
--- a/scribo/text/recognition.hh
+++ b/scribo/text/recognition.hh
@@ -86,7 +86,7 @@ namespace scribo
/// \return An image of characters.
template <typename L>
mln_ch_value(L,char)
- recognition(const scribo::util::text<L>& text,
+ recognition(const object_image(L)& objects,
const char *language);
@@ -96,17 +96,17 @@ namespace scribo
template <typename L>
mln_ch_value(L,char)
- recognition(const scribo::util::text<L>& text,
+ recognition(const object_image(L)& objects,
const char *language)
{
trace::entering("scribo::text::recognition");
- mln_precondition(text.is_valid());
+ mln_precondition(objects.is_valid());
// Initialize Tesseract.
TessBaseAPI::InitWithLanguage(NULL, NULL, language, NULL, false, 0, NULL);
- mln_ch_value(L,char) txt(text.label_image().domain());
+ mln_ch_value(L,char) txt(objects.domain());
data::fill(txt, ' ');
typedef mln_ch_value(L,bool) I;
@@ -118,35 +118,40 @@ namespace scribo
w_window2d_int dmap_win = mln::make::w_window2d_int(vals);
/// Use text bboxes with Tesseract
- for_all_components(i, text.bboxes())
+ for_all_ncomponents(i, objects.nlabels())
{
- I text_ima(text.bbox(i));
+ I text_ima(objects.bbox(i));
data::fill(text_ima, false);
- data::fill((text_ima | (pw::value(text.label_image()) == pw::cst(i))).rw(),
+ data::fill((text_ima | (pw::value(objects) == pw::cst(i))).rw(),
true);
/// Improve text quality.
+
+ /// text_ima_cleand domain is larger than text_ima's.
I text_ima_cleaned = text::clean(text_ima, dmap_win);
border::resize(text_ima_cleaned, 0); // Make sure there is no border.
// Recognize characters.
char* s = TessBaseAPI::TesseractRect(
(unsigned char*) text_ima_cleaned.buffer(),
- sizeof (bool), // Pixel size.
- text_ima.ncols() * sizeof (bool), // Row_offset
- 0, // Left
- 0, // Top
- text_ima.ncols(), // n cols
- text_ima.nrows()); // n rows
+ sizeof (bool), // Pixel size.
+ text_ima_cleaned.ncols() * sizeof (bool), // Row_offset
+ 0, // Left
+ 0, // Top
+ text_ima_cleaned.ncols(), // n cols
+ text_ima_cleaned.nrows()); // n rows
- mln_site(L) p = text.bbox(i).center();
- p.col() -= (text.bbox(i).pmax().col()
- - text.bbox(i).pmin().col()) / 2;
+ mln_site(L) p = objects.bbox(i).center();
+ p.col() -= (objects.bbox(i).pmax().col()
+ - objects.bbox(i).pmin().col()) / 2;
if (s != 0)
+ {
+ std::cout << s << std::endl;
mln::debug::put_word(txt, p, s);
+ }
// The string has been allocated by Tesseract. We must free it.
free(s);
--
1.5.6.5