* text/grouping/group_with_rag.hh,
* text/grouping/internal/have_link_valid.hh: New.
* src/text/grouping/group_from_rag.cc: New related example.
---
scribo/ChangeLog | 9 +
scribo/src/text/grouping/group_from_rag.cc | 240 ++++++++++++++++++++++
scribo/text/grouping/group_with_rag.hh | 99 +++++++++
scribo/text/grouping/internal/have_link_valid.hh | 83 ++++++++
4 files changed, 431 insertions(+), 0 deletions(-)
create mode 100644 scribo/src/text/grouping/group_from_rag.cc
create mode 100644 scribo/text/grouping/group_with_rag.hh
create mode 100644 scribo/text/grouping/internal/have_link_valid.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 472640e..23c8c0d 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,14 @@
2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ New object grouping routine based on a rag.
+
+ * text/grouping/group_with_rag.hh,
+ * text/grouping/internal/have_link_valid.hh: New.
+
+ * src/text/grouping/group_from_rag.cc: New related example.
+
+2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
* src/text_in_photo.cc: Improve results quality.
2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
diff --git a/scribo/src/text/grouping/group_from_rag.cc b/scribo/src/text/grouping/group_from_rag.cc
new file mode 100644
index 0000000..944624c
--- /dev/null
+++ b/scribo/src/text/grouping/group_from_rag.cc
@@ -0,0 +1,240 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#include <iostream>
+
+#include <mln/core/var.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/core/image/edge_image.hh>
+#include <mln/core/image/vertex_image.hh>
+#include <mln/core/image/dmorph/image_if.hh>
+#include <mln/value/label_16.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/literal/colors.hh>
+#include <mln/labeling/colorize.hh>
+#include <mln/labeling/compute.hh>
+#include <mln/make/p_vertices_with_mass_centers.hh>
+#include <mln/make/edge_image.hh>
+#include <mln/make/vertex_image.hh>
+#include <mln/debug/draw_graph.hh>
+#include <mln/util/graph.hh>
+#include <mln/accu/center.hh>
+
+#include <scribo/extract/primitive/objects.hh>
+#include <scribo/text/grouping/group_with_rag.hh>
+//#include <scribo/text/grouping/group_from_rag.hh>
+
+#include <scribo/filter/small_objects.hh>
+#include <scribo/filter/thin_objects.hh>
+#include <scribo/filter/thick_objects.hh>
+
+
+#include <scribo/fun/v2b/small_objects_filter.hh>
+#include <scribo/debug/save_bboxes_image.hh>
+#include <scribo/debug/save_linked_bboxes_image.hh>
+#include <scribo/make/debug_filename.hh>
+
+int usage(const char *name)
+{
+ std::cout << "Usage: " << name << " <input.pbm> " << std::endl;
+ return 1;
+}
+
+
+
+namespace scribo
+{
+
+ using namespace mln;
+
+
+ namespace graph
+ {
+
+ template <typename A, typename G, typename I>
+ inline
+ vertex_image<void,mln_result(A),G>
+ compute_vertex(const Accumulator<A>& accu,
+ const Graph<G>& g_,
+ const Image<I>& lbl_,
+ const mln_value(I)& nlabels)
+ {
+ const G& g = exact(g_);
+ const I& lbl = exact(lbl_);
+
+ mln_precondition(g.is_valid());
+ mln_precondition(lbl.is_valid());
+
+ util::array<mln_result(A)>
+ values = labeling::compute(accu, lbl_, nlabels);
+
+ vertex_image<void, mln_result(A), G>
+ v_ima = mln::make::vertex_image(g, values);
+
+ return v_ima;
+ }
+
+ } // end of namespace scribo::graph
+
+
+ template <typename I>
+ struct edge_color : mln::Function_v2b< edge_color<I> >
+ {
+ typedef value::rgb8 result;
+
+ edge_color(const Image<I>& mask) : mask_(exact(mask)) {}
+
+ value::rgb8 operator()(const unsigned id) const
+ {
+ if (mask_(id))
+ return literal::green;
+ return literal::red;
+ }
+
+ I mask_;
+ };
+
+
+ /// Compute a distance between two rgb8 values.
+ struct dist : Function_vv2v< dist >
+ {
+
+ typedef bool result;
+
+ bool operator()(const point2d& p1, const point2d& p2) const
+ {
+ return (math::sqrt(math::sqr(p1.row() - p2.row())
+ + math::sqr(p1.col() - p2.col()))) < 5;
+ }
+
+ };
+
+
+ namespace filter
+ {
+
+ template <typename P, typename V, typename G, typename F, typename FP>
+ edge_image<void,bool,G>
+ graph_edges(const vertex_image<P,V,G>& v_ima,
+ const Function<F>& edge_values,
+ const Function<FP>& predicate)
+ {
+ typedef edge_image<void,bool,util::graph> e_filter_t;
+ e_filter_t e_filter = mln::make::edge_image(v_ima, dist());
+
+
+ }
+
+ } // end of namespace scribo::filter
+
+
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace scribo;
+ using namespace mln;
+
+ if (argc != 2)
+ return usage(argv[0]);
+
+ scribo::make::internal::debug_filename_prefix = "group_with_rag";
+
+ image2d<bool> input;
+ io::pbm::load(input, argv[1]);
+
+
+ typedef image2d<value::label_16> L;
+ value::label_16 nbboxes;
+ typedef object_image(L) objects_t;
+ objects_t objects = extract::primitive::objects(input, c8(), nbboxes);
+
+ /// First filtering.
+ objects_t filtered_objects
+ = scribo::filter::small_objects(objects, 6);
+
+ filtered_objects
+ = scribo::filter::thin_objects(filtered_objects, 3);
+
+ filtered_objects
+ = scribo::filter::thick_objects(filtered_objects,
+ math::min(input.ncols(), input.nrows()) / 6);
+
+
+ /// Getting objects links from a Region Adjacency graph.
+ mln_VAR(rag_data, text::grouping::group_with_rag(filtered_objects, c8()));
+
+
+ mln_VAR(v_ima, scribo::graph::compute_vertex(accu::center<point2d>(),
+ rag_data.first(),
+ filtered_objects,
+ filtered_objects.nlabels()));
+
+ //FOR DEBUGGING PURPOSE
+ {
+ image2d<value::rgb8>
+ before_grouping = data::convert(value::rgb8(), input);
+
+ scribo::draw::bounding_boxes(before_grouping,
+ filtered_objects.bboxes(),
+ literal::blue);
+
+ mln_VAR(pv, mln::make::p_vertices_with_mass_centers(filtered_objects, rag_data.first()));
+ mln::debug::draw_graph(before_grouping, pv, literal::green, literal::green);
+
+ io::ppm::save(before_grouping,
+ scribo::make::debug_filename("before_grouping.ppm"));
+ }
+
+
+
+ typedef edge_image<void,bool,util::graph> e_filter_t;
+ e_filter_t e_filter = mln::make::edge_image(v_ima, dist());
+
+
+
+
+ //FOR DEBUGGING PURPOSE
+// {
+// image2d<value::rgb8>
+// after_grouping = data::convert(value::rgb8(), input);
+
+
+// scribo::draw::bounding_boxes(after_grouping,
+// filtered_objects.bboxes(),
+// literal::blue);
+
+// mln::debug::draw_graph(after_grouping, v_ima.domain(),
+// pw::cst(literal::black), edge_color<e_filter_t>(e_filter));
+
+// io::ppm::save(after_grouping, "after_grouping.ppm");
+// }
+}
+
+
diff --git a/scribo/text/grouping/group_with_rag.hh b/scribo/text/grouping/group_with_rag.hh
new file mode 100644
index 0000000..c995335
--- /dev/null
+++ b/scribo/text/grouping/group_with_rag.hh
@@ -0,0 +1,99 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_TEXT_GROUPING_GROUP_WITH_RAG_HH
+# define SCRIBO_TEXT_GROUPING_GROUP_WITH_RAG_HH
+
+
+/// \file
+///
+/// Group objects with a region adjacency graph.
+
+# include <mln/core/concept/neighborhood.hh>
+
+# include <mln/util/graph.hh>
+# include <mln/util/couple.hh>
+
+# include <mln/transform/influence_zone_geodesic.hh>
+
+# include <mln/make/influence_zone_adjacency_graph.hh>
+
+
+# include <scribo/core/macros.hh>
+# include <scribo/core/object_image.hh>
+
+
+namespace scribo
+{
+
+ namespace text
+ {
+
+ namespace grouping
+ {
+
+ using namespace mln;
+
+
+ template <typename L, typename N>
+ util::couple<mln::util::graph, mln_concrete(L)>
+ group_with_rag(const object_image(L)& objects,
+ const Neighborhood<N>& nbh);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename L, typename N>
+ util::couple<mln::util::graph, mln_concrete(L)>
+ group_with_rag(const object_image(L)& objects,
+ const Neighborhood<N>& nbh)
+ {
+ trace::entering("scribo::text::grouping::group_with_rag");
+
+ mln_precondition(objects.is_valid());
+
+ mln_concrete(L)
+ iz = transform::influence_zone_geodesic(objects, nbh);
+
+ mln::util::graph
+ g = mln::make::influence_zone_adjacency_graph(iz,
+ nbh,
+ objects.nlabels());
+
+ trace::exiting("scribo::text::grouping::group_with_rag");
+ return make::couple(g, iz);
+ }
+
+
+# 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_RAG_HH
diff --git a/scribo/text/grouping/internal/have_link_valid.hh b/scribo/text/grouping/internal/have_link_valid.hh
new file mode 100644
index 0000000..bdc6f18
--- /dev/null
+++ b/scribo/text/grouping/internal/have_link_valid.hh
@@ -0,0 +1,83 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_TEXT_GROUPING_INTERNAL_HAVE_LINK_VALID_HH
+# define SCRIBO_TEXT_GROUPING_INTERNAL_HAVE_LINK_VALID_HH
+
+/// \file
+///
+/// Tells whether a component have at least one valid link
+
+
+# include <mln/util/array.hh>
+# include <mln/util/couple.hh>
+
+namespace scribo
+{
+
+ namespace text
+ {
+
+ namespace grouping
+ {
+
+ namespace internal
+ {
+
+ /// Tells whether a component have at least one valid link link.
+ ///
+ /// \param[in] left_link Left link of components.
+ /// \param[in] right_link Right link of components.
+ /// \param[in] i The component id.
+ ///
+ /// \return True if the \p i-th component has at least one
+ /// valid link.
+ bool
+ have_link_valid(const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ unsigned i);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ bool
+ have_link_valid(const mln::util::array<unsigned>& left_link,
+ const mln::util::array<unsigned>& right_link,
+ unsigned i)
+ {
+ return (right_link[left_link[i]] == i && left_link[i] != i)
+ || (left_link[right_link[i]] == i && right_link[i] != i);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::text::grouping::internal
+
+ } // end of namespace scribo::text::grouping
+
+ } // end of namespace scribo::text
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_TEXT_GROUPING_INTERNAL_HAVE_LINK_VALID_HH
--
1.5.6.5
---
scribo/ChangeLog | 4 ++
scribo/filter/small_object_groups.hh | 89 ++++++++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 0 deletions(-)
create mode 100644 scribo/filter/small_object_groups.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 14d8305..854e523 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,9 @@
2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ * filter/small_object_groups.hh: New filter.
+
+2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Various small fixes in Scribo.
* extract/primitive/lines_h_thick.hh,
diff --git a/scribo/filter/small_object_groups.hh b/scribo/filter/small_object_groups.hh
new file mode 100644
index 0000000..7f10e1d
--- /dev/null
+++ b/scribo/filter/small_object_groups.hh
@@ -0,0 +1,89 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_FILTER_SMALL_OBJECT_GROUPS_HH
+# define SCRIBO_FILTER_SMALL_OBJECT_GROUPS_HH
+
+/// \file
+///
+/// Remove small objects groups.
+
+
+# include <mln/util/array.hh>
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+
+ /*! \brief Remove objects within a group with less than \p n
+ links.
+
+ \param[in] parent_link Information about object links.
+ \param[in] n_links The minimum number of links per group.
+
+ \return A function mapping an object id to a bool. It is set to
+ true if an object is part of a group with more than \p n_links
+ links.
+ */
+ mln::util::array<bool>
+ small_object_groups(const mln::util::array<unsigned>& parent_link,
+ unsigned n_links);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ mln::util::array<bool>
+ small_object_groups(const mln::util::array<unsigned>& parent_link,
+ unsigned n_links)
+ {
+ // Counting the number of objects per group.
+ mln::util::array<unsigned> group_size(parent_link.size(), 0);
+ for (unsigned i = 1; i < group_size.size(); ++i)
+ ++group_size[parent_link[i]];
+
+ mln::util::array<bool> f(parent_link.size());
+ f(0) = true;
+ for (unsigned i = 1; i < f.size(); ++i)
+ f(i) = (group_size[parent_link[i]] >= n_links);
+
+ return f;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_FILTER_SMALL_OBJECT_GROUPS_HH
+
--
1.5.6.5
* extract/primitive/lines_h_single.hh,
* extract/primitive/lines_v_single.hh: New.
---
scribo/ChangeLog | 7 +
scribo/extract/primitive/lines_h_single.hh | 203 ++++++++++++++++++++++++++++
scribo/extract/primitive/lines_v_single.hh | 199 +++++++++++++++++++++++++++
3 files changed, 409 insertions(+), 0 deletions(-)
create mode 100644 scribo/extract/primitive/lines_h_single.hh
create mode 100644 scribo/extract/primitive/lines_v_single.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 0fd3083..c9878a4 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,12 @@
2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add new routines for line extraction.
+
+ * extract/primitive/lines_h_single.hh,
+ * extract/primitive/lines_v_single.hh: New.
+
+2009-08-24 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add/improve line extraction examples.
* src/extract/primitive/Makefile.am: Add new examples.
diff --git a/scribo/extract/primitive/lines_h_single.hh b/scribo/extract/primitive/lines_h_single.hh
new file mode 100644
index 0000000..9146483
--- /dev/null
+++ b/scribo/extract/primitive/lines_h_single.hh
@@ -0,0 +1,203 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_EXTRACT_PRIMITIVE_LINES_H_SINGLE_HH
+# define SCRIBO_EXTRACT_PRIMITIVE_LINES_H_SINGLE_HH
+
+/// \file
+///
+/// Fast Extraction of single 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>
+
+
+namespace scribo
+{
+
+ namespace extract
+ {
+
+ namespace primitive
+ {
+
+
+ using namespace mln;
+
+ /// Fast Extraction of single horizontal thick lines.
+ /*!
+ * Only single 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.
+ * \param[in] w_h_ratio The minimum ratio width/height object
+ * bounding boxes to consider an
+ * object as a single line.
+ *
+ * \return An image in which only horizontal single lines are
+ * labeled.
+ */
+ template <typename I, typename N, typename V>
+ object_image(mln_ch_value(I,V))
+ lines_v_single(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned min_line_length,
+ float w_h_ratio);
+
+
+ /// Fast Extraction of single horizontal thick lines.
+ /*!
+ * Only single non discontinued lines are correctly extracted
+ * with this routine.
+ *
+ * \param[in] objects A labeled image.
+ * \param[in] line_length The minimum line length.
+ * \param[in] w_h_ratio The minimum ratio width/height object
+ * bounding boxes to consider an
+ * object as a single line.
+ *
+ * \return An image in which only horizontal single lines are
+ * labeled.
+ */
+ template <typename L>
+ object_image(L)
+ lines_h_single(const object_image(L)& objects,
+ unsigned min_line_length,
+ float w_h_ratio);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ template <typename L>
+ struct is_line_h_single
+ : Function_v2b<is_line_h_single<L> >
+ {
+ typedef bool result;
+
+ is_line_h_single(const object_image(L)& objects,
+ float w_h_ratio, unsigned min_line_length)
+ : objects_(objects),
+ w_h_ratio_(w_h_ratio), min_line_length_(min_line_length)
+ {
+ }
+
+
+ bool operator()(const mln_value(L)& label) const
+ {
+ mln_domain(L) box = objects_.bbox(label);
+
+ unsigned
+ height = box.pmax().row() - box.pmin().row() + 1,
+ width = box.pmax().col() - box.pmin().col() + 1;
+
+ return ((width / (float)height) > w_h_ratio_
+ && width > min_line_length_);
+ }
+
+ float w_h_ratio_;
+ unsigned min_line_length_;
+
+ object_image(L) objects_;
+ };
+
+
+ } // end of namespace mln::internal
+
+
+
+
+ template <typename I, typename N, typename V>
+ object_image(mln_ch_value(I,V))
+ lines_h_single(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ unsigned min_line_length,
+ float w_h_ratio)
+ {
+ trace::entering("scribo::primitive::lines_h_single");
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ mln_precondition(input.is_valid());
+ mln_precondition(nbh.is_valid());
+
+ typedef mln_ch_value(I,V) L;
+ object_image(L)
+ output = objects(input, nbh, nlines);
+
+ internal::is_line_h_single<L>
+ is_line(output, w_h_ratio, min_line_length);
+
+ output.relabel(is_line);
+ nlines = output.nlabels();
+
+ trace::exiting("scribo::primitive::lines_h_single");
+ return output;
+ }
+
+
+
+
+ template <typename L>
+ object_image(L)
+ lines_h_single(const object_image(L)& objects,
+ unsigned min_line_length,
+ float w_h_ratio)
+ {
+ trace::entering("scribo::primitive::lines_h_single");
+
+ mln_precondition(objects.is_valid());
+
+ internal::is_line_h_single<L>
+ is_line(objects, w_h_ratio, min_line_length);
+
+ object_image(L) output;
+ output.init_from_(objects);
+ output.relabel(is_line);
+
+ trace::exiting("scribo::primitive::lines_h_single");
+ 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_SINGLE_HH
diff --git a/scribo/extract/primitive/lines_v_single.hh b/scribo/extract/primitive/lines_v_single.hh
new file mode 100644
index 0000000..ee49eb8
--- /dev/null
+++ b/scribo/extract/primitive/lines_v_single.hh
@@ -0,0 +1,199 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_EXTRACT_PRIMITIVE_LINES_V_SINGLE_HH
+# define SCRIBO_EXTRACT_PRIMITIVE_LINES_V_SINGLE_HH
+
+/// \file
+///
+/// Fast Extraction of single vertical 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>
+
+
+namespace scribo
+{
+
+ namespace extract
+ {
+
+ namespace primitive
+ {
+
+ using namespace mln;
+
+ /// Fast Extraction of single vertical thick lines.
+ /*!
+ * Only single 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.
+ * \param[in] h_w_ratio The minimum ratio height/width object
+ * bounding boxes to consider an
+ * object as a single line.
+ *
+ * \return An image in which only vertical single lines are
+ * labeled.
+ */
+ template <typename I, typename N, typename V>
+ object_image(mln_ch_value(I,V))
+ lines_v_single(const Image<I>& input,
+ const Neighborhood<N>& nbh, V& nlines,
+ unsigned min_line_length,
+ float h_w_ratio);
+
+
+ /// Fast Extraction of single vertical thick lines.
+ /*!
+ * Only single non discontinued lines are correctly extracted
+ * with this routine.
+ *
+ * \param[in] objects A labeled image.
+ * \param[in] line_length The minimum line length.
+ * \param[in] h_w_ratio The minimum ratio height/width object
+ * bounding boxes to consider an
+ * object as a single line.
+ *
+ * \return An image in which only vertical single lines are
+ * labeled.
+ */
+ template <typename L>
+ object_image(L)
+ lines_v_single(const object_image(L)& objects,
+ unsigned min_line_length,
+ float h_w_ratio);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ template <typename L>
+ struct is_line_v_single
+ : Function_v2b<is_line_v_single<L> >
+ {
+ typedef bool result;
+
+ is_line_v_single(const object_image(L)& objects,
+ float h_w_ratio, unsigned min_line_length)
+ : objects_(objects),
+ h_w_ratio_(h_w_ratio), min_line_length_(min_line_length)
+ {
+ }
+
+
+ bool operator()(const mln_value(L)& label) const
+ {
+ mln_domain(L) box = objects_.bbox(label);
+ unsigned
+ height = box.pmax().row() - box.pmin().row() + 1,
+ width = box.pmax().col() - box.pmin().col() + 1;
+
+ return ((height / (float)width) > h_w_ratio_
+ && height > min_line_length_);
+ }
+
+ float h_w_ratio_;
+ unsigned min_line_length_;
+
+ object_image(L) objects_;
+ };
+
+
+ } // end of namespace mln::internal
+
+
+
+ template <typename I, typename N, typename V>
+ object_image(mln_ch_value(I,V))
+ lines_v_single(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, V& nlines,
+ unsigned min_line_length,
+ float h_w_ratio)
+ {
+ trace::entering("scribo::primitive::lines_v_single");
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ mln_precondition(input.is_valid());
+ mln_precondition(nbh.is_valid());
+
+ typedef mln_ch_value(I,V) L;
+ object_image(L)
+ output = objects(input, nbh, nlines);
+
+ internal::is_line_v_single<L>
+ is_line(output, h_w_ratio, min_line_length);
+
+ output.relabel(is_line);
+ nlines = output.nlabels();
+
+ trace::exiting("scribo::primitive::lines_v_single");
+ return output;
+ }
+
+
+
+ template <typename L>
+ object_image(L)
+ lines_v_single(const object_image(L)& objects,
+ unsigned min_line_length,
+ float h_w_ratio)
+ {
+ trace::entering("scribo::primitive::lines_v_single");
+
+ mln_precondition(objects.is_valid());
+
+ internal::is_line_v_single<L>
+ is_line(objects, h_w_ratio, min_line_length);
+
+ object_image(L) output;
+ output.init_from_(objects);
+ output.relabel(is_line);
+
+ trace::exiting("scribo::primitive::lines_v_single");
+ 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_SINGLE_HH
--
1.5.6.5