#123: Revamp general graph-based images (aka badly named « mesh images »)
----------------------+-----------------------------------------------------
Reporter: levill_r | Owner: levill_r
Type: task | Status: new
Priority: major | Milestone: Olena 1.0ß
Component: Milena | Version: 1.0
Keywords: |
----------------------+-----------------------------------------------------
For starters,
* Use `graph_based` prefix instead of `mesh`.
* Improve the graph structure; possibly provide a BGL-based version of
the graph-based image.
Then later:
* Create a « add_neighborhood » morpher, and adjust window-based morpho
algorithms so that they can work on images with neighborhoods.
* Rename « mesh elementary window » as « graph elementary neighborhood »
(or adjacency? Check formal definitions to choose the right term.).
* Revamp this elementary neighborhood too (currently, the graph-based
piters ignore them, and assume they always work on elementary
neighborhoods).
These latest tasks might deserve their own ticket, as their scope is
beyond graph-based images.
--
Ticket URL: <https://trac.lrde.org/olena/ticket/123>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image library.
https://svn.lrde.epita.fr/svn/oln/trunk/milena
This way we'll keep track of Boost things we depend on, and maybe should
turn into non Boost-dependent ones. We should prevent circumvent the
compilation of Boost-dependent tests is the required Boost libraries are
missing on the host.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add a memo file on Boost features used in Milena.
* README.BOOST: New.
README.BOOST | 3 +++
1 file changed, 3 insertions(+)
Index: README.BOOST
--- README.BOOST (revision 0)
+++ README.BOOST (revision 0)
@@ -0,0 +1,3 @@
+Milena components depending on one or several Boost libraries.
+
+- accu::tuple (depends on Boost Tuple and The Boost Preprocessor Library).
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Move convert::to_upper_window into its own file.
* mln/convert/to_window.hh
(convert::to_upper_window(const Neighborhood<N>&)): Move this
function...
* mln/convert/to_upper_window.hh: ...here (new file).
(convert::to_upper_window(const Windows<W>&)): New function.
* mln/canvas/labeling.hh: Adjust.
* mln/labeling/background.hh,
* mln/labeling/blobs.hh,
* mln/labeling/flat_zones.hh,
* mln/labeling/foreground.hh,
* mln/labeling/level.hh,
* mln/labeling/level.spe.hh,
* mln/labeling/regional_maxima.hh,
* mln/labeling/regional_minima.hh:
Adjust comments.
canvas/labeling.hh | 2
convert/to_upper_window.hh | 104 ++++++++++++++++++++++++++++++++++++++++++++
convert/to_window.hh | 22 ---------
labeling/background.hh | 6 --
labeling/blobs.hh | 6 --
labeling/flat_zones.hh | 6 --
labeling/foreground.hh | 6 --
labeling/level.hh | 6 --
labeling/level.spe.hh | 6 --
labeling/regional_maxima.hh | 6 --
labeling/regional_minima.hh | 6 --
11 files changed, 122 insertions(+), 54 deletions(-)
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 1697)
+++ mln/convert/to_window.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007 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
@@ -53,10 +53,6 @@
template <typename N>
window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
- /// Convert a neighborhood \p nbh into an upper window.
- template <typename N>
- window<mln_dpoint(N)> to_upper_window(const Neighborhood<N>& nbh);
-
/// Convert a binary image \p ima into a window.
template <typename I>
window<mln_dpoint(I)> to_window(const Image<I>& ima);
@@ -96,22 +92,6 @@
}
// FIXME: Same remark as for to_window(const Neighborhood<N>&)
- template <typename N>
- inline
- window<mln_dpoint(N)> to_upper_window(const Neighborhood<N>& nbh_)
- {
- const N& nbh = exact(nbh_);
- typedef mln_dpoint(N) D;
- typedef mln_point(D) P;
- window<D> win;
- mln_niter(N) n(nbh, P::origin);
- for_all(n)
- if (n > P::origin)
- win.insert(n - P::origin);
- return win;
- }
-
- // FIXME: Same remark as for to_window(const Neighborhood<N>&)
template <typename I>
inline
window<mln_dpoint(I)> to_window(const Image<I>& ima_)
Index: mln/convert/to_upper_window.hh
--- mln/convert/to_upper_window.hh (revision 0)
+++ mln/convert/to_upper_window.hh (revision 0)
@@ -0,0 +1,104 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// 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 MLN_CONVERT_TO_UPPER_WINDOW_HH
+# define MLN_CONVERT_TO_UPPER_WINDOW_HH
+
+/*! \file mln/convert/to_upper_window.hh
+ *
+ * \brief Conversions to upper mln::window.
+ */
+
+# include <mln/core/concept/delta_point_site.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/window.hh>
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// Convert a window \p nbh into an upper window.
+ template <typename W>
+ window<mln_dpoint(W)> to_upper_window(const Window<W>& win);
+
+ /// Convert a neighborhood \p nbh into an upper window.
+ template <typename N>
+ window<mln_dpoint(N)> to_upper_window(const Neighborhood<N>& nbh);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /* FIXME: According to milena/core/concepts/README, windows are
+ not necessarily based on a set of dpoints. So the current
+ algorithm won't work on non dpoint-set-based windows. In the
+ general case (of windows not being a set of dpoints), the
+ window resulting from this conversion (as well as the iterators
+ based on such windows!) should depend on the initial
+ neighborhood (i.e., delegate the actual iteration to the
+ aggregated neighborhood). When this is fixed, document this in
+ depth in milena/core/concepts/README. */
+ template <typename W>
+ inline
+ window<mln_dpoint(W)> to_upper_window(const Window<W>& win_)
+ {
+ const W& input_win = exact(win_);
+ typedef mln_dpoint(W) D;
+ typedef mln_point(D) P;
+ window<D> win;
+ mln_qiter(W) q(input_win, P::origin);
+ for_all(q)
+ if (q > P::origin)
+ win.insert(q - P::origin);
+ return win;
+ }
+
+ template <typename N>
+ inline
+ window<mln_dpoint(N)> to_upper_window(const Neighborhood<N>& nbh_)
+ {
+ const N& nbh = exact(nbh_);
+ typedef mln_dpoint(N) D;
+ typedef mln_point(D) P;
+ window<D> win;
+ mln_niter(N) n(nbh, P::origin);
+ for_all(n)
+ if (n > P::origin)
+ win.insert(n - P::origin);
+ return win;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_WINDOW_HH
Index: mln/canvas/labeling.hh
--- mln/canvas/labeling.hh (revision 1697)
+++ mln/canvas/labeling.hh (working copy)
@@ -36,7 +36,7 @@
# include <mln/core/concept/image.hh>
# include <mln/level/fill.hh>
-# include <mln/convert/to_window.hh> // FIXME: to_upper_window
+# include <mln/convert/to_upper_window.hh>
namespace mln
Index: mln/labeling/blobs.hh
--- mln/labeling/blobs.hh (revision 1697)
+++ mln/labeling/blobs.hh (working copy)
@@ -48,15 +48,13 @@
{
/* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
+ bound to the input image. */
/*! Connected component labeling of the binary objects of a binary
* image.
*
* \param[in] input The input image.
- * \param[in] nbh The neighborhood.
+ * \param[in] nbh The connexity of the objects.
* \param[out] nlabels The number of labels.
* \return The label image.
*
Index: mln/labeling/flat_zones.hh
--- mln/labeling/flat_zones.hh (revision 1697)
+++ mln/labeling/flat_zones.hh (working copy)
@@ -45,14 +45,12 @@
{
/* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
+ bound to the input image. */
/*! Connected component labeling of the flat zones of an image.
*
* \param[in] input The input image.
- * \param[in] nbh The neighborhood to consider.
+ * \param[in] nbh The connexity of the flat zones.
* \param[out] nlabels The number of labels.
* \return The label image.
*/
Index: mln/labeling/level.hh
--- mln/labeling/level.hh (revision 1697)
+++ mln/labeling/level.hh (working copy)
@@ -51,16 +51,14 @@
{
/* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
+ bound to the input image. */
/*! Connected component labeling of the image objects at a given
* level.
*
* \param[in] input The input image.
* \param[in] val The level to consider for the labeling.
- * \param[in] nbh The neighborhood.
+ * \param[in] nbh The connexity of the level components.
* \param[out] nlabels The number of labels.
* \return The label image.
*/
Index: mln/labeling/foreground.hh
--- mln/labeling/foreground.hh (revision 1697)
+++ mln/labeling/foreground.hh (working copy)
@@ -44,15 +44,13 @@
{
/* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
+ bound to the input image. */
/*! Connected component labeling of the object part in a binary
* image.
*
* \param[in] input The input image.
- * \param[in] nbh The neighborhood to consider.
+ * \param[in] nbh The connexity of the foreground.
* \param[out] nlabels The number of labels.
* \return The label image.
*
Index: mln/labeling/regional_minima.hh
--- mln/labeling/regional_minima.hh (revision 1697)
+++ mln/labeling/regional_minima.hh (working copy)
@@ -48,15 +48,13 @@
{
/* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
+ bound to the input image. */
/*! Connected component labeling of the regional minima of an
* image.
*
* \param[in] input The input image.
- * \param[in] nbh The neighborhood to consider.
+ * \param[in] nbh The connexity of the regional minima.
* \param[out] nlabels The number of labeled regions.
* \return The label image.
*
Index: mln/labeling/regional_maxima.hh
--- mln/labeling/regional_maxima.hh (revision 1697)
+++ mln/labeling/regional_maxima.hh (working copy)
@@ -48,15 +48,13 @@
{
/* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
+ bound to the input image. */
/*! Connected component labeling of the regional maxima of an
* image.
*
* \param[in] input The input image.
- * \param[in] nbh The neighborhood to consider.
+ * \param[in] nbh The connexity of the regional maxima.
* \param[out] nlabels The number of labeled regions.
* \return The label image.
*
Index: mln/labeling/level.spe.hh
--- mln/labeling/level.spe.hh (revision 1697)
+++ mln/labeling/level.spe.hh (working copy)
@@ -50,16 +50,14 @@
{
/* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
+ bound to the input image. */
/*! Connected component labeling of the image objects at a given
* level.
*
* \param[in] input The input image.
* \param[in] val The level to consider for the labeling.
- * \param[in] nbh The neighborhood.
+ * \param[in] nbh The connexity of the level components.
* \param[out] nlabels The number of labels.
* \return The label image.
*/
Index: mln/labeling/background.hh
--- mln/labeling/background.hh (revision 1697)
+++ mln/labeling/background.hh (working copy)
@@ -44,15 +44,13 @@
{
/* FIXME: The neighborhood shall not be passed as argument, but
- bound to the input image. We can also optionnaly provide a
- version of this function for regular-grid-based images where
- the neighborhood is replaced by a (user-provided) window. */
+ bound to the input image. */
/*! Connected component labeling of the background part in a
* binary image.
*
* \param[in] input The input image.
- * \param[in] nbh The neighborhood to consider.
+ * \param[in] nbh The connexity of the background.
* \param[out] nlabels The number of labels.
* \return The label image.
*
https://svn.lrde.epita.fr/svn/oln/trunk/milena
It's cool, because I'm doing two tasks in one time:
1. adding things to support my research work (at the moment, some
watershed/morphological experiments); and
2. reviewing the contents of mln/morpho/, which was one of my assignments
about two or three months ago. :-P
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add an area closing filter.
* mln/morpho/closing_attribute.hh: New.
Dual of mln/morpho/opening_attribute.hh
* mln/morpho/closing_area.hh: New.
Dual of mln/morpho/opening_area.hh
* tests/morpho/closing_area.cc: New test.
* tests/morpho/Makefile.am (check_PROGRAMS): Add closing_area.
(closing_area_SOURCES): New.
mln/morpho/closing_area.hh | 77 +++++++++++++++++++++
mln/morpho/closing_attribute.hh | 146 ++++++++++++++++++++++++++++++++++++++++
tests/morpho/Makefile.am | 2
tests/morpho/closing_area.cc | 57 +++++++++++++++
4 files changed, 282 insertions(+)
Index: mln/morpho/closing_attribute.hh
--- mln/morpho/closing_attribute.hh (revision 0)
+++ mln/morpho/closing_attribute.hh (revision 0)
@@ -0,0 +1,146 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// 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 MLN_MORPHO_CLOSING_ATTRIBUTE_HH
+# define MLN_MORPHO_CLOSING_ATTRIBUTE_HH
+
+/*! \file mln/morpho/closing_attribute.hh
+ *
+ * \brief Morphological attribute closing.
+ */
+
+# include <mln/morpho/includes.hh>
+# include <mln/canvas/morpho/algebraic_union_find.hh>
+# include <mln/level/sort_points.hh>
+# include <mln/util/pix.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ /* FIXME: The neighborhood shall not be passed as argument, but
+ bound to the input image. We can also optionnaly provide a
+ version of this function for regular-grid-based images where
+ the neighborhood is replaced by a (user-provided) window. */
+
+ /// Morphological attribute closing.
+ template <typename A,
+ typename I, typename N, typename O>
+ void closing_attribute(const Image<I>& input, const Neighborhood<N>& nbh,
+ mln_result(A) lambda, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename A_,
+ typename I_, typename N_, typename O_>
+ struct closing_attribute_t
+ {
+ typedef mln_point(I_) P;
+
+ // requirements from mln::canvas::morpho::algebraic_union_find
+
+ typedef A_ A;
+ typedef I_ I;
+ typedef N_ N;
+ typedef O_ O;
+ typedef p_array<P> S;
+ typedef util::pix<I> pix_t;
+
+ const I& input;
+ const N& nbh;
+ mln_result(A) lambda;
+ O& output;
+
+ const S s;
+
+ inline
+ void init()
+ {
+ // FIXME: border::fill(input, mln_max(mln_value(I)));
+ }
+
+ inline
+ bool is_active(const A& attr) const
+ {
+ return attr.to_result() < lambda;
+ }
+
+ inline
+ void inactivate(A& attr)
+ {
+ attr.set_value(lambda);
+ }
+
+ // end of requirements
+
+ inline
+ closing_attribute_t(const I_& input, const N_& nbh,
+ mln_result(A) lambda, O_& output)
+ : input(input), nbh(nbh), lambda(lambda), output(output),
+ s(level::sort_points_increasing(input))
+ {
+ }
+
+ };
+
+ } // end of namespace mln::morpho::impl
+
+
+ template <typename A,
+ typename I, typename N, typename O>
+ inline
+ void closing_attribute(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, mln_result(A) lambda,
+ Image<O>& output_)
+ {
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ O& output = exact(output_);
+ mln_precondition(output.domain() == input.domain());
+
+ typedef impl::closing_attribute_t<A,I,N,O> F;
+ F f(input, nbh, lambda, output);
+ canvas::morpho::algebraic_union_find<F> run(f);
+
+ mln_postcondition(output >= input);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_CLOSING_ATTRIBUTE_HH
Index: mln/morpho/closing_area.hh
--- mln/morpho/closing_area.hh (revision 0)
+++ mln/morpho/closing_area.hh (revision 0)
@@ -0,0 +1,77 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// 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 MLN_MORPHO_CLOSING_AREA_HH
+# define MLN_MORPHO_CLOSING_AREA_HH
+
+/*! \file mln/morpho/closing_area.hh
+ *
+ * \brief Morphological area closing.
+ */
+
+# include <mln/morpho/closing_attribute.hh>
+# include <mln/accu/count.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ /* FIXME: The neighborhood shall not be passed as argument, but
+ bound to the input image. We can also optionnaly provide a
+ version of this function for regular-grid-based images where
+ the neighborhood is replaced by a (user-provided) window. */
+
+ /// Morphological area closing.
+ template <typename I, typename N, typename O>
+ void closing_area(const Image<I>& input, const Neighborhood<N>& nbh,
+ std::size_t lambda, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename N, typename O>
+ inline
+ void closing_area(const Image<I>& input, const Neighborhood<N>& nbh,
+ std::size_t lambda, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() == exact(input).domain());
+ typedef util::pix<I> pix_t;
+ // FIXME: Change sig of closing_attribute!
+ closing_attribute< accu::count_<pix_t> >(input, nbh, lambda, output);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_CLOSING_AREA_HH
Index: tests/morpho/closing_area.cc
--- tests/morpho/closing_area.cc (revision 0)
+++ tests/morpho/closing_area.cc (revision 0)
@@ -0,0 +1,57 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// 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 tests/morpho/closing_area.cc
+ *
+ * \brief Test on mln::morpho::closing_area.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/core/neighb2d.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/morpho/closing_area.hh>
+
+#include "tests/data.hh"
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> lena;
+ io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
+ image2d<int_u8> out(lena.domain());
+
+ morpho::closing_area(lena, c4(), 510, out);
+ io::pgm::save(out, "out.pgm");
+}
Index: tests/morpho/Makefile.am
--- tests/morpho/Makefile.am (revision 1695)
+++ tests/morpho/Makefile.am (working copy)
@@ -3,6 +3,7 @@
include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
+ closing_area \
contrast \
dilation \
dilation_max_h \
@@ -16,6 +17,7 @@
opening_area \
thinning
+closing_area_SOURCES = closing_area.cc
contrast_SOURCES = contrast.cc
dilation_SOURCES = dilation.cc
dilation_max_h_SOURCES = dilation_max_h.cc
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add Meyer's Watershed Transform algorithm.
* mln/util/greater_point.hh: New.
A ``greater than'' functor comparing points w.r.t. the
values they refer to in an image.
* mln/morpho/meyer_wst.hh: New.
Meyer's Watershed Transform algorithm.
* tests/morpho/meyer_wst.cc: New tests.
mln/morpho/meyer_wst.hh | 169 ++++++++++++++++++++++++++++++++++++++++++++++
mln/util/greater_point.hh | 95 +++++++++++++++++++++++++
tests/morpho/meyer_wst.cc | 65 +++++++++++++++++
3 files changed, 329 insertions(+)
Index: mln/util/greater_point.hh
--- mln/util/greater_point.hh (revision 0)
+++ mln/util/greater_point.hh (revision 0)
@@ -0,0 +1,95 @@
+// Copyright (C) 2005, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// 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, 59 Temple Place - Suite 330, 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 MLN_UTIL_GREATER_POINT_HH
+# define MLN_UTIL_GREATER_POINT_HH
+
+# include <mln/core/concept/image.hh>
+
+
+namespace mln {
+
+ namespace util {
+
+ /** \brief A ``greater than'' functor comparing points w.r.t. the
+ values they refer to in an image.
+
+ This functor used in useful to implement ordered queues of
+ points. */
+ template <typename I>
+ class greater_point
+ {
+ public:
+ typedef mln_point(I) point;
+
+ greater_point(const Image<I>& ima);
+
+ /// Is \a x greater than \a y?
+ bool operator()(const point& x, const point& y);
+
+ private:
+ const I& ima_;
+ };
+
+
+ /// Helper to build a mln::util::greater_point.
+ /* FIXME: To be moved into mln/make/? */
+ template <typename I>
+ greater_point<I>
+ make_greater_point(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ greater_point<I>::greater_point(const Image<I>& ima)
+ : ima_ (exact(ima))
+ {
+ }
+
+ template <typename I>
+ bool
+ greater_point<I>::operator()(const mln_point(I)& x, const mln_point(I)& y)
+ {
+ return ima_(x) > ima_(y);
+ }
+
+
+ template <typename I>
+ greater_point<I>
+ make_greater_point(const Image<I>& ima)
+ {
+ return greater_point<I>(ima);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+#endif // ! MLN_UTIL_GREATER_POINT_HH
Index: mln/morpho/meyer_wst.hh
--- mln/morpho/meyer_wst.hh (revision 0)
+++ mln/morpho/meyer_wst.hh (revision 0)
@@ -0,0 +1,169 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// 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 MLN_MORPHO_MEYER_WST_HH
+# define MLN_MORPHO_MEYER_WST_HH
+
+/** \file mln/morpho/meyer_wst.hh
+ \brief Meyer's Watershed Transform (WST) algorithm.
+
+ The Watershed Transform algorithm from Meyer using a hierarchical
+ queue.
+
+ Reference:
+ Fernand Meyer. Un algorithme optimal de ligne de partage des
+ eaux. In: Actes du 8�me Congr�s AFCET, Lyon-Villeurbanne, France
+ (1991), pages 847--859. */
+
+# include <queue>
+
+# include <mln/trait/ch_value.hh>
+
+# include <mln/util/greater_point.hh>
+# include <mln/morpho/includes.hh>
+# include <mln/morpho/extrema_components.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+ /* FIXME: Provide also a version of the algorithm taking an image
+ of minima as input. */
+
+ /* FIXME: See also the interface of the Shortest-Path Watershed
+ Transform, which proposes to lower-complete the image before
+ processing it. Then, add a reference to
+ mln/morpho/lower_completion.hh. */
+
+ /* FIXME: More doc. */
+
+ /// Meyer's Watershed Transform (WST) algorithm.
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ meyer_wst(const Image<I>& input, const Window<W>& win, unsigned& nbasins);
+
+ /// Meyer's Watershed Transform (WST) algorithm, with no count of
+ /// basins.
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ meyer_wst(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ meyer_wst(const Image<I>& input, const Window<W>& win, unsigned& nbasins)
+ {
+ /* FIXME: Ensure the input image has scalar values. */
+
+ typedef DestValue marker;
+ const marker unmarked = mln_min(marker);
+
+ // Initialize the output with the markers (minima components).
+ mln_ch_value(I, marker) markers =
+ minima_components<marker>(input, win, nbasins);
+
+ // Ordered queue.
+ typedef mln_point(I) point;
+ typedef
+ std::priority_queue< point, std::vector<point>, util::greater_point<I> >
+ ordered_queue_type;
+ ordered_queue_type queue(util::make_greater_point(input));
+
+ // Insert every neighbor P of every marked area in a
+ // hierarchical queue, with a priority level corresponding to
+ // the grey level input(P).
+ mln_piter(I) p(markers.domain());
+ mln_qiter(W) q(win, p);
+ for_all (p)
+ if (markers(p) == unmarked)
+ for_all(q)
+ if (markers.has(q) && markers(q) != unmarked)
+ {
+ queue.push(p);
+ break;
+ }
+
+ /* Until the queue is empty, extract a point P from the
+ hierarchical queue, at the highest priority level, that is,
+ the lowest level. */
+ while (!queue.empty())
+ {
+ point p = queue.top();
+ queue.pop();
+ // Last seen marker adjacent to P.
+ marker adjacent_marker = unmarked;
+ // Has P a single adjacent marker?
+ bool single_adjacent_marker_p = true;
+ mln_qiter(W) q(win, p);
+ for_all(q)
+ if (markers.has(q) && markers(q) != unmarked)
+ if (adjacent_marker == unmarked)
+ {
+ adjacent_marker = markers(q);
+ single_adjacent_marker_p = true;
+ }
+ else
+ if (adjacent_marker != markers(q))
+ {
+ single_adjacent_marker_p = false;
+ break;
+ }
+ /* If the neighborhood of P contains only points with the
+ same label, then P is marked with this label, and its
+ neighbors that are not yet marked are put into the
+ hierarchical queue. */
+ if (single_adjacent_marker_p)
+ {
+ markers(p) = adjacent_marker;
+ for_all(q)
+ if (markers.has(q) && markers(q) == unmarked)
+ queue.push(q);
+ }
+ }
+ return markers;
+ }
+
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ meyer_wst(const Image<I>& input, const Window<W>& win)
+ {
+ unsigned nbasins;
+ return meyer_wst<DestValue>(input, nbasins);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_MEYER_WST_HH
Index: tests/morpho/meyer_wst.cc
--- tests/morpho/meyer_wst.cc (revision 0)
+++ tests/morpho/meyer_wst.cc (revision 0)
@@ -0,0 +1,65 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// 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 tests/morpho/extrema_components.cc
+// /\brief Test on mln::morpho::extrema_components
+
+#include <iostream>
+
+#include <mln/core/image2d.hh>
+#include <mln/core/window2d.hh>
+#include <mln/core/neighb2d.hh>
+
+#include <mln/convert/to_window.hh>
+
+#include <mln/value/int_u8.hh>
+
+#include <mln/morpho/meyer_wst.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include "tests/data.hh"
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> input;
+ io::pgm::load(input, MLN_IMG_DIR "/squares.pgm");
+
+ typedef int_u8 output_val;
+
+ unsigned nbasins;
+ // FIXME: Do we really need to use a neighborood to express a 4-c window?
+ image2d<int_u8> output =
+ morpho::meyer_wst<output_val>(input, convert::to_window(c4()), nbasins);
+ std::cout << "nbasins = " << nbasins << std::endl;
+ io::pgm::save(output, "out.pgm");
+}
https://svn.lrde.epita.fr/svn/oln/trunk/milena
(Same remark as my previous patch.)
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add a computation of the extrema level components.
* mln/morpho/extrema_components.hh: New.
Imported from Olena proto-1.0.
* tests/morpho/extrema_components.cc: New test.
* tests/morpho/Makefile.am (check_PROGRAMS): Add extrema_components.
(extrema_components_SOURCES): New.
* img/squares.pgm, img/squares-lc.pgm: New images.
mln/morpho/extrema_components.hh | 229 ++++++++++++++++++++++++++++---------
tests/morpho/Makefile.am | 2
tests/morpho/extrema_components.cc | 69 +++++++++++
3 files changed, 247 insertions(+), 53 deletions(-)
Index: mln/morpho/extrema_components.hh
--- mln/morpho/extrema_components.hh (revision 1680)
+++ mln/morpho/extrema_components.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2005 EPITA Research and Development Laboratory
+// Copyright (C) 2005, 2008 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,51 +25,152 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLENA_MORPHO_EXTREMA_COMPONENTS_HH
-# define OLENA_MORPHO_EXTREMA_COMPONENTS_HH
+#ifndef MLN_MORPHO_EXTREMA_COMPONENTS_HH
+# define MLN_MORPHO_EXTREMA_COMPONENTS_HH
+
+// FIXME: This file seems to contain the same algorithm as
+// mln/labeling/regional_minima.hh and
+// mln/labeling/regional_maxima.hh. Merge or remove to avoid
+// duplication.
+
+// FIXME: Provide neighborhood-aware versions of these algorithms.
# include <map>
# include <queue>
# include <functional>
-# include "oln/level/level_components.hh"
+# include <mln/trait/ch_value.hh>
+
+# include <mln/level/fill.hh>
+
+# include <mln/morpho/includes.hh>
+# include <mln/morpho/level_components.hh>
+
+
+namespace mln {
+
+ namespace morpho {
+
+ /*--------------------------.
+ | Minima level components. |
+ `--------------------------*/
+
+ /** \brief Compute the minima level components of \a input.
+
+ \p DestValue is the value type of the output.
+
+ The result is an image where each minima is given a value
+ between \c mln_value(DestValue) + 1 and \c nminima (the number
+ of minima level components). Points which do not belong to a
+ minimum are gien the value mln_value(DestValue).
+
+ \param[in] input The image whose minima are computed.
+ \param[in] win The window describing the connexity of \a input.
+ \param[out] nminima The number of minima found by the algorithm.
+ \return The image of minima.
+
+ \pre \p DestValue is large enough to hold a number of values
+ equal to \c nminima + 1, so as to tag all the minima points
+ plus the non-minima points. */
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ minima_components(const Image<I>& input, const Window<W>& win,
+ unsigned& nminima);
+
+ /// \brief Like the 3-argument version of mln::moprho::minima_components,
+ /// without the out argument \c nminima.
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ minima_components(const Image<I>& input, const Window<W>& win);
+
+
+ /*--------------------------.
+ | Maxima level components. |
+ `--------------------------*/
+
+ /** \brief Compute the maxima level components of \a input.
+
+ \p DestValue is the value type of the output.
+
+ The result is an image where each maxima is given a value
+ between \c mln_value(DestValue) + 1 and \c nmaxima (the number
+ of maxima level components). Points which do not belong to a
+ maximum are gien the value mln_value(DestValue).
+
+ \param[in] input The image whose maxima are computed.
+ \param[in] win The window describing the connexity of \a input.
+ \param[out] nmaxima The number of maxima found by the algorithm.
+ \return The image of maxima.
-namespace oln {
+ \pre \p DestValue is large enough to hold a number of values
+ equal to \c nmaxima + 1, so as to tag all the maxima points
+ plus the non-maxima points. */
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ maxima_components(const Image<I>& input, const Window<W>& win,
+ unsigned& nmaxima);
- namespace level {
+ /// \brief Like the 3-argument version of mln::moprho::maxima_components,
+ /// without the out argument \c nmaxima.
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ maxima_components(const Image<I>& input, const Window<W>& win);
- namespace internal {
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl {
/// Find the extrema level components of \a input, using \param
/// Cmp as comparison function.
- template <typename DestValue, typename Cmp, typename I>
- typename ch_value_type<I, DestValue>::ret
- extrema_components(const abstract::image_with_nbh<I>& input)
+ template <typename DestValue, typename Cmp, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ extrema_components(const Image<I>& input_, const Window<W>& win_,
+ unsigned& nextrema)
{
- mlc_is_a(I, abstract::scalar_valued_image)::ensure();
+
+ /* FIXME: Errors due to a too small DestValue type should be
+ reported more explicitely. Currently, we abort with messages
+ akin to this one:
+
+ Assertion failed:
+ (unsigned(i) <= mln::trait::value_< enc_ >::max()),
+ function operator=, file ../../../../milena/mln/value/int_u.hh,
+ line 243.
+
+ This is not user-friendly at all! */
+
+ const I& input = exact(input_);
+ const W& win = exact(win_);
+
+ // Instantiate a comparison functor.
Cmp cmp;
// Compute level components.
- typedef ntg_cumul_type(DestValue) cumul_type;
+ /* FIXME: Should we deduce cumul_type from DestValue? Or
+ stick to unsigned? */
+ typedef unsigned cumul_type;
typedef cumul_type comp_type;
- typename ch_value_type<I, comp_type>::ret comps =
- level_components<comp_type>(input);
+ mln_ch_value(I, comp_type) comps =
+ level_components<comp_type>(input, win);
+ /* FIXME: Does Milena provide better data structures to
+ store this information? */
std::set<comp_type> extrema;
std::set<comp_type> non_extrema;
// Search extrema components.
- oln_type_of(I, piter) p(input.size());
- for_all_p (p)
+ mln_piter(I) p(input.domain());
+ for_all(p)
{
- comp_type comp = comps[p];
+ comp_type comp = comps(p);
if (non_extrema.find(comp) == non_extrema.end())
{
// A new level is a (potential) extrema by default.
extrema.insert(comp);
- oln_type_of(I, niter) n(input);
- for_all_n_of_p (n, p)
- if (input.hold(n) and cmp(input[n], input[p]))
+ mln_qiter(W) q(win, p);
+ for_all(q)
+ if (input.has(q) and cmp(input(q), input(p)))
{
extrema.erase(comp);
non_extrema.insert(comp);
@@ -78,57 +179,79 @@
}
}
+ // Update nextrema.
+ nextrema = extrema.size();
+
// Re-label the extrema. label_map hold the assigned labels.
std::map<comp_type, DestValue> label_map;
{
- DestValue cur_label = ntg_min_val(DestValue) + 1;
- for (typename std::set<comp_type>::const_iterator i =
- extrema.begin(); i != extrema.end(); ++i, ++cur_label)
- {
+ DestValue cur_label = mln_min(DestValue) + 1;
+ for (typename std::set<comp_type>::const_iterator i = extrema.begin();
+ i != extrema.end();
+ ++i, ++cur_label)
label_map[*i] = cur_label;
}
- }
- typename ch_value_type<I, DestValue>::ret output (input.size(),
- input.nbh_get());
- level::fill (output, ntg_min_val(DestValue));
- for_all_p (p)
+ mln_ch_value(I, DestValue) output (input.domain());
+ level::fill (output, mln_min(DestValue));
+ for_all(p)
{
- comp_type comp = comps[p];
+ comp_type comp = comps(p);
if (label_map.find(comp) != label_map.end())
- output[p] = label_map[comp];
+ output(p) = label_map[comp];
}
return output;
}
- } // end of namespace oln::level::internal.
+ } // end of namespace mln::morpho::impl.
- /// Find the minima level components of \a input.
- template <typename DestValue, typename I>
- typename ch_value_type<I, DestValue>::ret
- minima_components(const abstract::image_with_nbh<I>& input)
+ /*----------.
+ | Facades. |
+ `----------*/
+
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ minima_components(const Image<I>& input, const Window<W>& win,
+ unsigned& nminima)
{
- mlc_is_a(I, abstract::scalar_valued_image)::ensure();
- typedef oln_type_of(I, value) input_value_type;
- return
- internal::extrema_components< DestValue,
- std::less<input_value_type> >(input);
+ /* FIXME: Ensure the input image has scalar values. */
+ typedef std::less< mln_value(I) > cmp_t;
+ return impl::extrema_components<DestValue, cmp_t>(input, win, nminima);
}
- /// Find the maxima level components of \a input.
- template <typename DestValue, typename I>
- typename ch_value_type<I, DestValue>::ret
- maxima_components(const abstract::image_with_nbh<I>& input)
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ minima_components(const Image<I>& input, const Window<W>& win)
+ {
+ // Dummy value.
+ unsigned nminima;
+ return minima_components<DestValue>(input, win, nminima);
+ }
+
+
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ maxima_components(const Image<I>& input, const Window<W>& win,
+ unsigned& nmaxima)
{
- mlc_is_a(I, abstract::scalar_valued_image)::ensure();
- typedef oln_type_of(I, value) input_value_type;
- return
- internal::extrema_components< DestValue,
- std::greater<input_value_type> >(input);
+ /* FIXME: Ensure the input image has scalar values. */
+ typedef std::greater< mln_value(I) > cmp_t;
+ return impl::extrema_components<DestValue, cmp_t>(input, win, nmaxima);
}
- } // end of namespace oln::level.
+ template <typename DestValue, typename I, typename W>
+ mln_ch_value(I, DestValue)
+ maxima_components(const Image<I>& input, const Window<W>& win)
+ {
+ // Dummy value.
+ unsigned nmaxima;
+ return maxima_components<DestValue>(input, win, nmaxima);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho.
-} // end of namespace oln.
+} // end of namespace mln.
-#endif // ! OLENA_MORPHO_EXTREMA_COMPONENTS_HH
+#endif // ! MLN_MORPHO_EXTREMA_COMPONENTS_HH
Index: tests/morpho/extrema_components.cc
--- tests/morpho/extrema_components.cc (revision 0)
+++ tests/morpho/extrema_components.cc (revision 0)
@@ -0,0 +1,69 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// 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 tests/morpho/extrema_components.cc
+// /\brief Test on mln::morpho::extrema_components
+
+#include <iostream>
+
+#include <mln/core/image2d.hh>
+#include <mln/core/window2d.hh>
+#include <mln/core/neighb2d.hh>
+
+#include <mln/convert/to_window.hh>
+
+#include <mln/value/int_u8.hh>
+
+#include <mln/morpho/extrema_components.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include "tests/data.hh"
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> input;
+ io::pgm::load(input, MLN_IMG_DIR "/squares.pgm");
+
+ unsigned nminima;
+ // FIXME: Do we really need to use a neighborood to express a 4-c window?
+ image2d<int_u8> minima =
+ morpho::minima_components<int_u8>(input, convert::to_window(c4()), nminima);
+ std::cout << "nminima = " << nminima << std::endl;
+ io::pgm::save(minima, "minima.pgm");
+
+ unsigned nmaxima;
+ image2d<int_u8> maxima =
+ morpho::maxima_components<int_u8>(input, convert::to_window(c4()), nmaxima);
+ std::cout << "nmaxima = " << nmaxima << std::endl;
+ io::pgm::save(maxima, "maxima.pgm");
+}
Index: tests/morpho/Makefile.am
--- tests/morpho/Makefile.am (revision 1693)
+++ tests/morpho/Makefile.am (working copy)
@@ -8,6 +8,7 @@
dilation_max_h \
erosion \
erosion_min_h \
+ extrema_components \
gradient \
hit_or_miss \
laplacian \
@@ -20,6 +21,7 @@
dilation_max_h_SOURCES = dilation_max_h.cc
erosion_SOURCES = erosion.cc
erosion_min_h_SOURCES = erosion_min_h.cc
+extrema_components_SOURCES = extrema_components.cc
gradient_SOURCES = gradient.cc
hit_or_miss_SOURCES = hit_or_miss.cc
laplacian_SOURCES = laplacian.cc