* filter/objects_h_thin.hh,
* filter/objects_v_thin.hh: New objects filters.
---
scribo/ChangeLog | 7 ++
scribo/filter/objects_h_thin.hh | 192 +++++++++++++++++++++++++++++++++++++++
scribo/filter/objects_v_thin.hh | 192 +++++++++++++++++++++++++++++++++++++++
3 files changed, 391 insertions(+), 0 deletions(-)
create mode 100644 scribo/filter/objects_h_thin.hh
create mode 100644 scribo/filter/objects_v_thin.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 226b82d..ffd15fa 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,12 @@
2009-09-28 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add new filters in Scribo.
+
+ * filter/objects_h_thin.hh,
+ * filter/objects_v_thin.hh: New objects filters.
+
+2009-09-28 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Small fixes in Scribo.
* binarization/sauvola.hh: Fix an invalid precondition.
diff --git a/scribo/filter/objects_h_thin.hh b/scribo/filter/objects_h_thin.hh
new file mode 100644
index 0000000..2b098ac
--- /dev/null
+++ b/scribo/filter/objects_h_thin.hh
@@ -0,0 +1,192 @@
+// 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_OBJECTS_H_THIN_HH
+# define SCRIBO_FILTER_OBJECTS_H_THIN_HH
+
+/// \file
+///
+/// Remove too thin objects.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+
+# include <mln/util/array.hh>
+
+# include <scribo/core/object_image.hh>
+# include <scribo/primitive/extract/objects.hh>
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+ /// Remove objects thinner or equal to \p min_thickness.
+ ///
+ /// \param[in] input_ a binary image.
+ /// \param[in] nbh_ a neighborhood used in labeling algorithms.
+ /// \param[in] label_type the label type used for labeling.
+ /// \param[in] min_thickness the minimum thickness value.
+ ///
+ /// \result A binary image without h_thin objects.
+ //
+ template <typename I, typename N, typename V>
+ inline
+ mln_concrete(I)
+ objects_h_thin(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ const V& label_type,
+ unsigned min_thickness);
+
+ /// Remove lines of text thinner or equal to \p min_thickness.
+ ///
+ /// \param[in] objects An object image.
+ /// \param[in] min_thickness the minimum thickness value.
+ ///
+ /// \result An object image without too thin vertical objects.
+ //
+ template <typename L>
+ inline
+ object_image(L)
+ objects_h_thin(const object_image(L)& text,
+ unsigned min_thickness);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+
+ /// Filter Functor.
+ /// Return false for all objects which are too large.
+ template <typename L>
+ struct objects_h_thin_filter
+ : Function_v2b< objects_h_thin_filter<L> >
+ {
+ typedef accu::shape::bbox<mln_psite(L)> box_accu_t;
+
+ /// Constructor
+ ///
+ /// \param[in] objects object bounding boxes.
+ /// \param[in] min_thickness the minimum of vertical thickness
+ /// allowed.
+ //
+ objects_h_thin_filter(const object_image(L)& objects,
+ unsigned min_thickness)
+ : objects_(objects), min_thickness_(min_thickness)
+ {
+ }
+
+
+ /// Return false if the objects is thinner than
+ /// \p min_thickness_.
+ ///
+ /// \param[in] l An image value.
+ //
+ bool operator()(const mln_value(L)& l) const
+ {
+ if (l == literal::zero)
+ return true;
+ return objects_.bbox(l).ncols() > min_thickness_;
+ }
+
+ /// Component bounding boxes.
+ object_image(L) objects_;
+
+ /// The minimum vertical thickness.
+ unsigned min_thickness_;
+ };
+
+
+ } // end of namespace scribo::filter::internal
+
+
+ template <typename I, typename N, typename V>
+ inline
+ mln_concrete(I)
+ objects_h_thin(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ const V& label_type,
+ unsigned min_thickness)
+ {
+ trace::entering("scribo::filter::objects_h_thin");
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+
+ mln_precondition(input.is_valid());
+ mln_precondition(nbh.is_valid());
+
+ V nlabels;
+ typedef mln_ch_value(I,V) lbl_t;
+ object_image(lbl_t) objects
+ = primitive::extract::objects(input, nbh, nlabels);
+
+ typedef internal::objects_h_thin_filter<lbl_t> func_t;
+ func_t fv2b(objects, min_thickness);
+ objects.relabel(fv2b);
+
+ mln_concrete(I) output = duplicate(input);
+ data::fill((output | pw::value(objects) == pw::cst(literal::zero)).rw(),
+ false);
+
+ trace::exiting("scribo::filter::objects_h_thin");
+ return output;
+ }
+
+
+ template <typename L>
+ inline
+ object_image(L)
+ objects_h_thin(const object_image(L)& objects,
+ unsigned min_thickness)
+ {
+ trace::entering("scribo::filter::objects_h_thin");
+
+ mln_precondition(objects.is_valid());
+
+ typedef internal::objects_h_thin_filter<L> func_t;
+ func_t is_not_too_h_thin(objects, min_thickness);
+
+ object_image(L) output;
+ output.init_from_(objects);
+ output.relabel(is_not_too_h_thin);
+
+ trace::exiting("scribo::filter::objects_h_thin");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_FILTER_OBJECTS_H_THIN_HH
diff --git a/scribo/filter/objects_v_thin.hh b/scribo/filter/objects_v_thin.hh
new file mode 100644
index 0000000..bcf6726
--- /dev/null
+++ b/scribo/filter/objects_v_thin.hh
@@ -0,0 +1,192 @@
+// 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_OBJECTS_V_THIN_HH
+# define SCRIBO_FILTER_OBJECTS_V_THIN_HH
+
+/// \file
+///
+/// Remove too thin objects.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+
+# include <mln/util/array.hh>
+
+# include <scribo/core/object_image.hh>
+# include <scribo/primitive/extract/objects.hh>
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+ /// Remove objects thinner or equal to \p min_thickness.
+ ///
+ /// \param[in] input_ a binary image.
+ /// \param[in] nbh_ a neighborhood used in labeling algorithms.
+ /// \param[in] label_type the label type used for labeling.
+ /// \param[in] min_thickness the minimum thickness value.
+ ///
+ /// \result A binary image without v_thin objects.
+ //
+ template <typename I, typename N, typename V>
+ inline
+ mln_concrete(I)
+ objects_v_thin(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ const V& label_type,
+ unsigned min_thickness);
+
+ /// Remove lines of text thinner or equal to \p min_thickness.
+ ///
+ /// \param[in] objects An object image.
+ /// \param[in] min_thickness the minimum thickness value.
+ ///
+ /// \result An object image without too thin vertical objects.
+ //
+ template <typename L>
+ inline
+ object_image(L)
+ objects_v_thin(const object_image(L)& text,
+ unsigned min_thickness);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+
+ /// Filter Functor.
+ /// Return false for all objects which are too large.
+ template <typename L>
+ struct objects_v_thin_filter
+ : Function_v2b< objects_v_thin_filter<L> >
+ {
+ typedef accu::shape::bbox<mln_psite(L)> box_accu_t;
+
+ /// Constructor
+ ///
+ /// \param[in] objects object bounding boxes.
+ /// \param[in] min_thickness the minimum of vertical thickness
+ /// allowed.
+ //
+ objects_v_thin_filter(const object_image(L)& objects,
+ unsigned min_thickness)
+ : objects_(objects), min_thickness_(min_thickness)
+ {
+ }
+
+
+ /// Return false if the objects is thinner than
+ /// \p min_thickness_.
+ ///
+ /// \param[in] l An image value.
+ //
+ bool operator()(const mln_value(L)& l) const
+ {
+ if (l == literal::zero)
+ return true;
+ return objects_.bbox(l).nrows() > min_thickness_;
+ }
+
+ /// Component bounding boxes.
+ object_image(L) objects_;
+
+ /// The minimum vertical thickness.
+ unsigned min_thickness_;
+ };
+
+
+ } // end of namespace scribo::filter::internal
+
+
+ template <typename I, typename N, typename V>
+ inline
+ mln_concrete(I)
+ objects_v_thin(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ const V& label_type,
+ unsigned min_thickness)
+ {
+ trace::entering("scribo::filter::objects_v_thin");
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+
+ mln_precondition(input.is_valid());
+ mln_precondition(nbh.is_valid());
+
+ V nlabels;
+ typedef mln_ch_value(I,V) lbl_t;
+ object_image(lbl_t) objects
+ = primitive::extract::objects(input, nbh, nlabels);
+
+ typedef internal::objects_v_thin_filter<lbl_t> func_t;
+ func_t fv2b(objects, min_thickness);
+ objects.relabel(fv2b);
+
+ mln_concrete(I) output = duplicate(input);
+ data::fill((output | pw::value(objects) == pw::cst(literal::zero)).rw(),
+ false);
+
+ trace::exiting("scribo::filter::objects_v_thin");
+ return output;
+ }
+
+
+ template <typename L>
+ inline
+ object_image(L)
+ objects_v_thin(const object_image(L)& objects,
+ unsigned min_thickness)
+ {
+ trace::entering("scribo::filter::objects_v_thin");
+
+ mln_precondition(objects.is_valid());
+
+ typedef internal::objects_v_thin_filter<L> func_t;
+ func_t is_not_too_v_thin(objects, min_thickness);
+
+ object_image(L) output;
+ output.init_from_(objects);
+ output.relabel(is_not_too_v_thin);
+
+ trace::exiting("scribo::filter::objects_v_thin");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_FILTER_OBJECTS_V_THIN_HH
--
1.5.6.5
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-09-25 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Add hierarchical queues for Salembier's algorithm.
* core/site_set/p_queue_fast.hh: Add empty method.
* util/all.hh: Update.
* util/hqueues.hh: New.
* value/all.hh: Update.
* value/value_array.hh: New. Create an array indexed by
a given type. (Similar to histo::array but the
values are not limited to unsigned type).
---
core/site_set/p_queue_fast.hh | 11 ++
util/all.hh | 1
util/hqueues.hh | 159 ++++++++++++++++++++++++++++++++++++
value/all.hh | 2
value/value_array.hh | 184 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 356 insertions(+), 1 deletion(-)
Index: trunk/milena/mln/core/site_set/p_queue_fast.hh
===================================================================
--- trunk/milena/mln/core/site_set/p_queue_fast.hh (revision 4551)
+++ trunk/milena/mln/core/site_set/p_queue_fast.hh (revision 4552)
@@ -111,6 +111,8 @@
/// Give the number of sites.
unsigned nsites() const;
+ /// Test if the queue is empty.
+ bool empty() const;
/// Push a site \p p in the queue.
void push(const P& p);
@@ -244,6 +246,15 @@
template <typename P>
inline
+ bool
+ p_queue_fast<P>::empty() const
+ {
+ mln_invariant(end_ >= begin_);
+ return end_ == begin_;
+ }
+
+ template <typename P>
+ inline
void
p_queue_fast<P>::push(const P& p)
{
Index: trunk/milena/mln/value/all.hh
===================================================================
--- trunk/milena/mln/value/all.hh (revision 4551)
+++ trunk/milena/mln/value/all.hh (revision 4552)
@@ -53,7 +53,7 @@
# include <mln/value/interval.hh>
# include <mln/value/label.hh>
# include <mln/value/proxy.hh>
-
+# include <mln/value/value_array.hh>
// FIXME: that includes concept/image.hh!
Index: trunk/milena/mln/value/value_array.hh
===================================================================
--- trunk/milena/mln/value/value_array.hh (revision 0)
+++ trunk/milena/mln/value/value_array.hh (revision 4552)
@@ -0,0 +1,184 @@
+// 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 MLN_VALUE_VALUE_ARRAY_HH
+# define MLN_VALUE_VALUE_ARRAY_HH
+
+/// \file
+///
+/// Define a generic array indexed by an iterable type.
+
+# include <mln/value/set.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /// Generic array class over indexed by a value set with type \c T.
+ template <typename T, typename V>
+ struct value_array
+ {
+ enum {
+ nvalues = mln_card(T)
+ };
+
+ /// Constructors.
+ /// {
+ value_array();
+ value_array(const V& v);
+ value_array(const value_array<T, V>& other);
+ value_array& operator=(const value_array<T, V>& other);
+ /// }
+
+ /// Access elements through a value of \p T.
+ /// {
+ const V& operator()(const T& v) const;
+ V& operator()(const T& v);
+ /// }
+
+ /// Access elements through array indexes.
+ /// {
+ const V& operator[](unsigned i) const;
+ V& operator[](unsigned i);
+ /// }
+
+ /// Reference to the set of \p T.
+ const mln::value::set<T>& vset() const;
+
+ protected:
+
+ const mln::value::set<T>& s_;
+ V v_[nvalues];
+ };
+
+
+ template <typename T, typename V>
+ std::ostream& operator<<(std::ostream& ostr, const value_array<T, V>& a);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename V>
+ inline
+ value_array<T,V>::value_array()
+ : s_ (mln::value::set<T>::the())
+ {
+ typedef value::internal::iterable_set< T, set<T> > U;
+ mlc_is(set<T>, U)::check();
+ }
+
+ template <typename T, typename V>
+ inline
+ value_array<T,V>::value_array(const V& v)
+ : s_(mln::value::set<T>::the())
+ {
+ typedef value::internal::iterable_set< T, set<T> > U;
+ mlc_is(set<T>, U)::check();
+
+ memset(v_, v, nvalues * sizeof(V));
+ }
+
+ template <typename T, typename V>
+ inline
+ value_array<T,V>::value_array(const value_array<T, V>& other)
+ : s_(other.s_)
+ {
+ memcpy(v_, other.v_, nvalues * sizeof(V));
+ }
+
+ template <typename T, typename V>
+ inline
+ value_array<T,V>&
+ value_array<T,V>::operator=(const value_array<T, V>& other)
+ {
+ if (&other != this)
+ memcpy(v_, other.v_, nvalues * sizeof(V));
+ return *this;
+ }
+
+ template <typename T, typename V>
+ inline
+ const V&
+ value_array<T,V>::operator()(const T& v) const
+ {
+ return v_[s_.index_of(v)];
+ }
+
+ template <typename T, typename V>
+ inline
+ V&
+ value_array<T,V>::operator()(const T& v)
+ {
+ return v_[s_.index_of(v)];
+ }
+
+ template <typename T, typename V>
+ inline
+ const mln::value::set<T>&
+ value_array<T,V>::vset() const
+ {
+ return s_;
+ }
+
+ template <typename T, typename V>
+ inline
+ const V&
+ value_array<T,V>::operator[](unsigned i) const
+ {
+ mln_precondition(i < nvalues);
+ return v_[i];
+ }
+
+ template <typename T, typename V>
+ inline
+ V&
+ value_array<T,V>::operator[](unsigned i)
+ {
+ mln_precondition(i < nvalues);
+ return v_[i];
+ }
+
+ template <typename T, typename V>
+ inline
+ std::ostream& operator<<(std::ostream& ostr, const value_array<T,V>& a)
+ {
+ mln_viter(mln::value::set<T>) v(a.vset());
+ for_all(v)
+ ostr << v << ':' << h(v) << ' ';
+ return ostr;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_VALUE_ARRAY_HH
Index: trunk/milena/mln/util/all.hh
===================================================================
--- trunk/milena/mln/util/all.hh (revision 4551)
+++ trunk/milena/mln/util/all.hh (revision 4552)
@@ -51,6 +51,7 @@
# include <mln/util/dindex.hh>
# include <mln/util/eat.hh>
# include <mln/util/edge.hh>
+# include <mln/util/hqueues.hh>
# include <mln/util/graph.hh>
# include <mln/util/greater_point.hh>
# include <mln/util/greater_psite.hh>
Index: trunk/milena/mln/util/hqueues.hh
===================================================================
--- trunk/milena/mln/util/hqueues.hh (revision 0)
+++ trunk/milena/mln/util/hqueues.hh (revision 4552)
@@ -0,0 +1,159 @@
+// Copyright (C) 2008, 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 MLN_UTIL_HQUEUES_HH
+# define MLN_UTIL_HQUEUES_HH
+
+///
+/// \brief Generic class for hierarchical queues.
+///
+/// Hierarchical queues are often used with connected operators
+/// (P. Salemebier's max tree algorithm relies on these queues). To be
+/// efficient, the hiererachy is a static array and each are
+/// preallocated using an histogram.
+///
+/// FIXME: consider hqueues as a site set ?
+
+
+# include <mln/core/site_set/p_queue_fast.hh>
+# include <mln/histo/array.hh>
+# include <mln/value/set.hh>
+
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ template <typename P, typename T>
+ struct hqueues
+ {
+ enum {
+ nvalues = mln_card(T)
+ };
+
+ hqueues(const histo::array<T>& h);
+
+ const p_queue_fast<P>& operator[](unsigned i) const;
+ p_queue_fast<P>& operator[](unsigned i);
+
+ const p_queue_fast<P>& operator()(const T& v) const;
+ p_queue_fast<P>& operator()(const T& v);
+
+ const mln::value::set<T>& vset() const;
+
+ protected:
+ void pre_allocate_(unsigned i);
+
+ const histo::array<T>& h_;
+ const mln::value::set<T>& s_;
+ std::vector<bool> allocated_;
+ std::vector< p_queue_fast<P> >queues_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P, typename T>
+ inline
+ hqueues<P,T>::hqueues(const histo::array<T>& h)
+ : h_ (h),
+ s_ (mln::value::set<T>::the()),
+ allocated_ (nvalues, false),
+ queues_ (nvalues)
+ {
+ }
+
+ template <typename P, typename T>
+ inline
+ void
+ hqueues<P,T>::pre_allocate_(unsigned i)
+ {
+ mln_precondition(i < nvalues);
+ if (!allocated_[i])
+ {
+ queues_[i].reserve(h_[i]);
+ allocated_[i] = true;
+ }
+ }
+
+
+ template <typename P, typename T>
+ inline
+ const p_queue_fast<P>&
+ hqueues<P,T>::operator[](unsigned i) const
+ {
+ mln_precondition(i < nvalues);
+ pre_allocate_(i);
+ return queues_[i];
+ }
+
+ template <typename P, typename T>
+ inline
+ p_queue_fast<P>&
+ hqueues<P,T>::operator[](unsigned i)
+ {
+ mln_precondition(i < nvalues);
+ pre_allocate_(i);
+ return queues_[i];
+ }
+
+ template <typename P, typename T>
+ inline
+ const p_queue_fast<P>&
+ hqueues<P,T>::operator()(const T& v) const
+ {
+ unsigned i = s_.index_of(v);
+ pre_allocate_(i);
+ return queues_[i];
+ }
+
+ template <typename P, typename T>
+ inline
+ p_queue_fast<P>&
+ hqueues<P,T>::operator()(const T& v)
+ {
+ unsigned i = s_.index_of(v);
+ pre_allocate_(i);
+ return queues_[i];
+ }
+
+
+ template <typename P, typename T>
+ inline
+ const mln::value::set<T>&
+ hqueues<P,T>::vset() const
+ {
+ return s_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+#endif // !MLN_UTIL_HQUEUES_HH
* src/extract/primitive/Makefile.am,
* src/preprocessing/Makefile.am: Add new examples as target.
* src/extract/primitive/find_pattern_lines.cc,
* src/preprocessing/split_bg_fg.cc: New examples.
---
scribo/ChangeLog | 10 +++
scribo/src/extract/primitive/Makefile.am | 2 +
scribo/src/extract/primitive/find_pattern_lines.cc | 75 ++++++++++++++++++++
scribo/src/preprocessing/Makefile.am | 4 +-
scribo/src/preprocessing/split_bg_fg.cc | 67 +++++++++++++++++
5 files changed, 157 insertions(+), 1 deletions(-)
create mode 100644 scribo/src/extract/primitive/find_pattern_lines.cc
create mode 100644 scribo/src/preprocessing/split_bg_fg.cc
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index fd7af50..c4e7c1f 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,15 @@
2009-09-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add new examples in Scribo.
+
+ * src/extract/primitive/Makefile.am,
+ * src/preprocessing/Makefile.am: Add new examples as target.
+
+ * src/extract/primitive/find_pattern_lines.cc,
+ * src/preprocessing/split_bg_fg.cc: New examples.
+
+2009-09-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Add new filters in Scribo.
* filter/object_groups_size_ratio.hh,
diff --git a/scribo/src/extract/primitive/Makefile.am b/scribo/src/extract/primitive/Makefile.am
index 51850f6..c4ebeaf 100644
--- a/scribo/src/extract/primitive/Makefile.am
+++ b/scribo/src/extract/primitive/Makefile.am
@@ -27,6 +27,7 @@ bin_PROGRAMS = \
extract_thick_vlines \
extract_thick_hlines \
find_discontinued_lines \
+ find_pattern_lines \
find_single_lines \
find_thick_lines \
find_thick_and_single_lines
@@ -37,6 +38,7 @@ extract_discontinued_hlines_SOURCES = extract_discontinued_hlines.cc
extract_thick_vlines_SOURCES = extract_thick_vlines.cc
extract_thick_hlines_SOURCES = extract_thick_hlines.cc
find_discontinued_lines_SOURCES = find_discontinued_lines.cc
+find_pattern_lines_SOURCES = find_pattern_lines.cc
find_single_lines_SOURCES = find_single_lines.cc
find_thick_lines_SOURCES = find_thick_lines.cc
find_thick_and_single_lines_SOURCES = find_thick_and_single_lines.cc
diff --git a/scribo/src/extract/primitive/find_pattern_lines.cc b/scribo/src/extract/primitive/find_pattern_lines.cc
new file mode 100644
index 0000000..eaf2d59
--- /dev/null
+++ b/scribo/src/extract/primitive/find_pattern_lines.cc
@@ -0,0 +1,75 @@
+// 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 <mln/core/image/image2d.hh>
+#include <mln/value/label_16.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/io/pbm/all.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/data/convert.hh>
+#include <mln/debug/superpose.hh>
+
+#include <scribo/debug/usage.hh>
+
+#include <scribo/core/object_image.hh>
+#include <scribo/primitive/extract/lines_h_pattern.hh>
+#include <scribo/primitive/extract/lines_v_pattern.hh>
+
+const char *args_desc[][2] =
+{
+ { "input.pbm", "A binary image." },
+ { "length", " Minimum line length." },
+ {0, 0}
+};
+
+
+int main(int argc, char *argv[])
+{
+ using namespace mln;
+
+ if (argc != 4)
+ return scribo::debug::usage(argv,
+ "Extract discontinued horizontal and vertical lines",
+ "input.pbm length output.ppm",
+ args_desc,
+ "A color image. Horizontal lines are in red and vertical lines in green.");
+
+ trace::entering("main");
+
+ typedef image2d<bool> I;
+ I input;
+ io::pbm::load(input, argv[1]);
+
+ I hlines = scribo::primitive::extract::lines_h_pattern(input, atoi(argv[2]));
+ I vlines = scribo::primitive::extract::lines_v_pattern(input, atoi(argv[2]));
+
+ image2d<value::rgb8> out = debug::superpose(input, hlines, literal::red);
+ out = debug::superpose(out, vlines, literal::green);
+
+ io::ppm::save(out, argv[3]);
+
+ trace::exiting("main");
+}
diff --git a/scribo/src/preprocessing/Makefile.am b/scribo/src/preprocessing/Makefile.am
index f6d877c..af6db48 100644
--- a/scribo/src/preprocessing/Makefile.am
+++ b/scribo/src/preprocessing/Makefile.am
@@ -20,6 +20,8 @@
include $(top_srcdir)/scribo/scribo.mk
bin_PROGRAMS = \
+ split_bg_fg \
unskew
-unskew_SOURCES = unskew.cc
+split_bg_fg_SOURCES = split_bg_fg.cc
+unskew_SOURCES = unskew.cc
diff --git a/scribo/src/preprocessing/split_bg_fg.cc b/scribo/src/preprocessing/split_bg_fg.cc
new file mode 100644
index 0000000..a1aab52
--- /dev/null
+++ b/scribo/src/preprocessing/split_bg_fg.cc
@@ -0,0 +1,67 @@
+// 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 <mln/core/image/image2d.hh>
+#include <mln/io/ppm/all.hh>
+
+#include <scribo/preprocessing/split_bg_fg.hh>
+#include <scribo/debug/usage.hh>
+
+
+const char *args_desc[][2] =
+{
+ { "input.pbm", "A color image." },
+ { "lambda", "Lambda value. (FIX Description)" },
+ { "delta", "Delta value. (FIX Description)" },
+ { "bg.ppm", "The background image (2nd output)." },
+ {0, 0}
+};
+
+
+
+int main(int argc, char *argv[])
+{
+ mln::trace::entering("main");
+ using namespace mln;
+
+ if (argc != 6)
+ return scribo::debug::usage(argv,
+ "Split background and foreground.",
+ "input.pbm bg.ppm fg.ppm",
+ args_desc, "The foreground image.");
+
+ typedef image2d<value::rgb8> I;
+ I input;
+ io::ppm::load(input, argv[1]);
+
+ util::couple<I,I>
+ bg_fg = scribo::preprocessing::split_bg_fg(input,
+ atoi(argv[2]),
+ atoi(argv[3]));
+ io::ppm::save(bg_fg.first(), argv[4]);
+ io::ppm::save(bg_fg.second(), argv[5]);
+
+ mln::trace::exiting("main");
+}
--
1.5.6.5
* filter/object_groups_size_ratio.hh,
* filter/objects_size_ratio.hh: New filters.
---
scribo/ChangeLog | 7 ++
scribo/filter/object_groups_size_ratio.hh | 104 +++++++++++++++++++++++++
scribo/filter/objects_size_ratio.hh | 120 +++++++++++++++++++++++++++++
3 files changed, 231 insertions(+), 0 deletions(-)
create mode 100644 scribo/filter/object_groups_size_ratio.hh
create mode 100644 scribo/filter/objects_size_ratio.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 0a7f625..fd7af50 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,12 @@
2009-09-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+ Add new filters in Scribo.
+
+ * filter/object_groups_size_ratio.hh,
+ * filter/objects_size_ratio.hh: New filters.
+
+2009-09-25 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
Small fixes in Scribo.
* demo/src/mainwindow.cc: Do not always resize pics.
diff --git a/scribo/filter/object_groups_size_ratio.hh b/scribo/filter/object_groups_size_ratio.hh
new file mode 100644
index 0000000..b52c30d
--- /dev/null
+++ b/scribo/filter/object_groups_size_ratio.hh
@@ -0,0 +1,104 @@
+// 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_OBJECT_GROUPS_SIZE_RATIO_HH
+# define SCRIBO_FILTER_OBJECT_GROUPS_SIZE_RATIO_HH
+
+/// \file
+///
+
+
+# include <mln/util/array.hh>
+
+# include <scribo/core/macros.hh>
+# include <scribo/core/object_groups.hh>
+# include <scribo/core/object_image.hh>
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+ template <typename L>
+ object_groups<L>
+ object_groups_size_ratio(const object_groups<L>& groups,
+ float max_size_ratio,
+ float max_invalid_ratio_per_group);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename L>
+ object_groups<L>
+ object_groups_size_ratio(const object_groups<L>& groups,
+ float max_size_ratio,
+ float max_invalid_ratio_per_group)
+ {
+ trace::entering("scribo::filter::object_groups_size_ratio");
+
+ mln_precondition(groups.is_valid());
+
+ const object_image(L)& objects = groups.object_image_();
+
+ // FIXME: estimating the group size should be removed once
+ // available in the object_group structure.
+ // Counting the number of objects per group with a size ratio >
+ // max_ratio.
+ mln::util::array<unsigned>
+ group_size(groups.size(), 0),
+ invalid_object_in_group(groups.size(), 0);
+
+ for_all_ncomponents(i, objects.nlabels())
+ {
+ if ((objects.bbox(i).nrows() / objects.bbox(i).ncols())
+ >= max_size_ratio)
+ ++invalid_object_in_group[groups[i]];
+
+ ++group_size[groups[i]];
+ }
+
+ object_groups<L> output(groups);
+ output(0) = 0;
+ for (unsigned i = 1; i < output.size(); ++i)
+ if ((invalid_object_in_group[groups[i]] / static_cast<float>(group_size[groups[i]])) >= max_invalid_ratio_per_group)
+ output(i) = 0;
+
+ trace::exiting("scribo::filter::object_groups_size_ratio");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_FILTER_OBJECT_GROUPS_SIZE_RATIO_HH
diff --git a/scribo/filter/objects_size_ratio.hh b/scribo/filter/objects_size_ratio.hh
new file mode 100644
index 0000000..7a68f7f
--- /dev/null
+++ b/scribo/filter/objects_size_ratio.hh
@@ -0,0 +1,120 @@
+// 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_OBJECTS_SIZE_RATIO_HH
+# define SCRIBO_FILTER_OBJECTS_SIZE_RATIO_HH
+
+/// \file
+///
+///
+
+# include <mln/core/concept/function.hh>
+# include <scribo/core/object_image.hh>
+
+
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+
+ template <typename L>
+ object_image(L)
+ objects_size_ratio(const object_image(L)& objects,
+ float size_ratio);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+
+ /// Filter Functor.
+ /// Return false for all objects which have a bad ratio.
+ template <typename L>
+ struct objects_size_ratio_filter
+ : Function_v2b< objects_size_ratio_filter<L> >
+ {
+ typedef accu::shape::bbox<mln_psite(L)> box_accu_t;
+
+ objects_size_ratio_filter(const object_image(L)& objects,
+ float ratio)
+ : objects_(objects), ratio_(ratio)
+ {
+ }
+
+ bool operator()(const mln_value(L)& l) const
+ {
+ if (l == literal::zero)
+ return true;
+ return (objects_.bbox(l).nrows() / static_cast<float>(objects_.bbox(l).ncols())) < ratio_;
+ }
+
+ /// Component bounding boxes.
+ object_image(L) objects_;
+
+ /// The maximum size ratio.
+ float ratio_;
+ };
+
+
+ } // end of namespace scribo::filter::internal
+
+
+
+ template <typename L>
+ object_image(L)
+ objects_size_ratio(const object_image(L)& objects,
+ float size_ratio)
+ {
+
+ trace::entering("scribo::primitive::objects_size_ratio");
+
+ mln_precondition(objects.is_valid());
+
+ typedef internal::objects_size_ratio_filter<L> func_t;
+ func_t has_bad_ratio(objects, size_ratio);
+
+ object_image(L) output;
+ output.init_from_(objects);
+ output.relabel(has_bad_ratio);
+
+ trace::exiting("scribo::primitive::objects_size_ratio");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+
+#endif // ! SCRIBO_FILTER_OBJECTs_SIZE_RATIO_HH
--
1.5.6.5