#133: Naming convention on accumulators
--------------------------------------------+-------------------------------
Reporter: nivault | Owner: Olena Team
Type: task | Status: new
Priority: major | Milestone: Olena 1.1
Component: Milena | Version: 1.0
Keywords: accumulator naming conventions |
--------------------------------------------+-------------------------------
In the file source:/trunk/milena/mln/accu/median.hh the class does not
have any underscore.
--
Ticket URL: <https://trac.lrde.org/olena/ticket/133>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image library.
#7: Miscellaneous tasks related to the Olena 1.0ß release process
-----------------------+----------------------------------------------------
Reporter: levill_r | Owner: levill_r
Type: task | Status: new
Priority: trivial | Milestone: Olena 1.0ß
Component: other | Version: 1.0
Resolution: | Keywords: release NEWS dates copyright headers
-----------------------+----------------------------------------------------
Old description:
> * Update NEWS (see the similar task for Olena 0.10a/0.11: #8)
> * ... (to be completed)
>
> Split this ticket in several parts if the tasks are either too big or too
> numerous.
New description:
To do before the release
* update `NEWS` (see the similar task for Olena 0.10a/0.11: #8);
* update `AUTHORS`;
* ensure all copyright headers are sound (using Benoît Sigoure's
`gplize.sh` script, or a variant of it).
Split this ticket in several parts if the tasks are either too big or too
numerous.
Comment (by levill_r):
Update the to-do list.
--
Ticket URL: <https://trac.lrde.org/olena/ticket/7#comment:5>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image library.
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Start to mark out and clean up bad usages of neighborhoods.
* mln/trait/neighborhood.hh: New.
Traits for neighborhoods.
* mln/core/macros.hh (mln_neighb, mln_neighb_): New macros.
* mln/convert/to_window.hh,
* mln/geom/seeds2tiling_roundness.hh,
* 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,
* mln/make/voronoi.hh,
* mln/morpho/Rd.hh,
* mln/morpho/opening_area.hh,
* mln/morpho/opening_attribute.hh:
Add a few remarks and FIXMEs.
Fix some typos.
* mln/morpho/includes.hh: Include mln/convert/to_window.hh.
* mln/morpho/dilation.hh: Add more documentation.
Wrap long lines.
(dilation(const Image<I>& input))
(dilation(const Image<I>&, Image<O>&))
(impl::dilation_wrt_nbh(const Image<I>&, const Neighborhood<N>&,
Image<O>&)): New functions.
(dilation(const Image<I>&, const Window<W>&, Image<O>&)): Add
tracing guards.
* tests/morpho/dilation.cc: Re-enable more test cases.
Use a smaller octagon structuring element to speed up the test.
mln/convert/to_window.hh | 11 +
mln/core/macros.hh | 10 +
mln/geom/seeds2tiling_roundness.hh | 26 ++--
mln/labeling/background.hh | 13 +-
mln/labeling/blobs.hh | 17 ++
mln/labeling/flat_zones.hh | 16 +-
mln/labeling/foreground.hh | 13 +-
mln/labeling/level.hh | 19 ++-
mln/labeling/level.spe.hh | 14 +-
mln/labeling/regional_maxima.hh | 22 ++-
mln/labeling/regional_minima.hh | 23 ++-
mln/make/voronoi.hh | 7 +
mln/morpho/Rd.hh | 8 +
mln/morpho/dilation.hh | 213 +++++++++++++++++++++++++++++++------
mln/morpho/includes.hh | 1
mln/morpho/opening_area.hh | 18 +--
mln/morpho/opening_attribute.hh | 17 +-
mln/trait/neighborhood.hh | 110 +++++++++++++++++++
tests/morpho/dilation.cc | 24 ++--
19 files changed, 479 insertions(+), 103 deletions(-)
Index: tests/morpho/dilation.cc
--- tests/morpho/dilation.cc (revision 1679)
+++ tests/morpho/dilation.cc (working copy)
@@ -59,25 +59,35 @@
using namespace mln;
using value::int_u8;
- win::rectangle2d rec(21, 21);
border::thickness = 66;
+ // FIXME: Maybe we should split all these tests cases into severals
+ // files. Sure it's a pain to create, but we want to be able to
+ // choose the granularity of the executed test suite (fast,
+ // comprehensive, etc.).
+
image2d<int_u8> lena;
io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
-// {
-// image2d<int_u8> out(lena.domain());
-// morpho::dilation(lena, rec, out);
-// io::pgm::save(out, "out1.pgm");
-// }
+ {
+ // FIXME: This struct. elt. is far too big for a routinely run
+ // test; either use a smaller one or qualify this test as
+ // ``long''.
+ win::rectangle2d rec(21, 21);
+ image2d<int_u8> out(lena.domain());
+ morpho::dilation(lena, rec, out);
+ io::pgm::save(out, "out1.pgm");
+ }
{
- win::octagon2d oct(31);
+ win::octagon2d oct(6);
image2d<int_u8> out(lena.domain());
morpho::dilation(lena, oct, out);
io::pgm::save(out, "out2.pgm");
}
+ // FIXME: Add tests using neighborhoods, too.
+
// {
// p_array<point2d> vec = convert::to_p_array(rec, point2d::zero);
// window2d win = convert::to_window(vec);
Index: mln/trait/neighborhood.hh
--- mln/trait/neighborhood.hh (revision 0)
+++ mln/trait/neighborhood.hh (revision 0)
@@ -0,0 +1,110 @@
+// 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_TRAIT_NEIGHBORHOOD_HH
+# define MLN_TRAIT_NEIGHBORHOOD_HH
+
+/// \file mln/trait/neighborhood.hh
+/// \brief Some base trait types for neighborhood types.
+
+# include <string>
+
+
+/// Shortcuts.
+/// \{
+# define mln_trait_neighborhood_kind(N) \
+ typename mln::trait::neighborhood< N >::nature
+# define mln_trait_neighborhood_kind_(N) \
+ mln::trait::neighborhood< N >::nature
+/// \}
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ struct undefined_neighborhood
+ {
+ typedef undef kind;
+ };
+
+
+ struct default_neighborhood : undefined_neighborhood
+ {
+ typedef trait::neighborhood::kind::generic kind;
+ };
+
+
+ template <typename V>
+ struct neighborhood : default_neighborhood
+ {
+ };
+
+
+ /*----------------.
+ | Traits values. |
+ `----------------*/
+
+ // FIXME: Might be moved to another file, as it's the case for
+ // images and values.
+
+ /// Traits related to neighborhoods.
+ namespace neighborhood
+ {
+
+ /// Kind of neighborhood.
+ struct kind
+ {
+ /// The base class of the hierarchy of neighborhood traits.
+ struct any
+ {
+ std::string name() const { return "kind::any"; }
+ };
+
+ /// A generic neighborhood, with no particular feature.
+ struct generic : any
+ {
+ std::string name() const { return "kind::generic"; }
+ };
+
+ /// A neighborhood on a regular grid, i.e.
+ /// holding/convertible to a window.
+ struct regular : any
+ {
+ std::string name() const { return "kind::regular"; }
+ };
+ };
+ }
+
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+#endif // ! MLN_TRAIT_NEIGHBORHOOD_HH
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1679)
+++ mln/core/macros.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -128,12 +128,18 @@
// m
-
/// Shortcut to access the mesh type associated to T.
# define mln_mesh(T) typename T::mesh
# define mln_mesh_(T) T::mesh
+// n
+
+/// Shortcut to access the neighborhood type associated to T.
+# define mln_neighb(T) typename T::neighb
+# define mln_neighb_(T) T::neighb
+
+
// p
/// Shortcut to access the type of point iterator (piter) associated to T.
Index: mln/make/voronoi.hh
--- mln/make/voronoi.hh (revision 1679)
+++ mln/make/voronoi.hh (working copy)
@@ -47,8 +47,13 @@
namespace make
{
+ /* 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. */
+
/*!
- * \brief Apply Voronoi algorithm on \p ima_ with the original
+ * \brief Apply the Voronoi algorithm on \p ima_ with the original
* image \p orig_ for node computing with neighborhood \p nbh.
*
* \param[in] ima_ The labeling image.
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 1679)
+++ mln/convert/to_window.hh (working copy)
@@ -72,6 +72,15 @@
# 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 N>
inline
window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh_)
@@ -86,6 +95,7 @@
return win;
}
+ // 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_)
@@ -101,6 +111,7 @@
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/geom/seeds2tiling_roundness.hh
--- mln/geom/seeds2tiling_roundness.hh (revision 1679)
+++ mln/geom/seeds2tiling_roundness.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -50,13 +50,19 @@
namespace geom
{
+ /* 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. */
/*! Take a labeled image \p ima_ with seeds and extend them until
- * creating tiles nore roundness that the primary version.
+ * creating tiles rounder than the primary version.
*
* \param[in,out] ima_ The labeled image with seed.
- * \param[in] win_w The weight window using by geom::chamfer to compute distance.
- * \param[in] max Unsigned using by geom::chamfer to compute distance.
+ * \param[in] win_w The weight window using by geom::chamfer to
+ * compute distance.
+ * \param[in] max Unsigned using by geom::chamfer to compute
+ * the distance.
* \param[in] nbh The neighborhood to use on this algorithm.
*
* \pre \p ima_ has to be initialized.
@@ -64,8 +70,8 @@
*/
template <typename I, typename N>
I
- seeds2tiling_roundness (Image<I>& ima_, const w_window2d_int& w_win, unsigned max,
- const Neighborhood<N>& nbh);
+ seeds2tiling_roundness (Image<I>& ima_, const w_window2d_int& w_win,
+ unsigned max, const Neighborhood<N>& nbh);
@@ -77,8 +83,8 @@
template <typename I, typename N>
inline
I
- seeds2tiling_roundness(Image<I>& ima_, const w_window2d_int& w_win, unsigned max,
- const Neighborhood<N>& nbh)
+ seeds2tiling_roundness(Image<I>& ima_, const w_window2d_int& w_win,
+ unsigned max, const Neighborhood<N>& nbh)
{
trace::entering("geom::impl::seed2tiling_roundness");
@@ -123,8 +129,8 @@
template <typename I, typename N>
inline
I
- seeds2tiling_roundness(Image<I>& ima_, const w_window2d_int& w_win, unsigned max,
- const Neighborhood<N>& nbh)
+ seeds2tiling_roundness(Image<I>& ima_, const w_window2d_int& w_win,
+ unsigned max, const Neighborhood<N>& nbh)
{
trace::entering("geom::seed2tiling_roundness");
Index: mln/morpho/opening_attribute.hh
--- mln/morpho/opening_attribute.hh (revision 1679)
+++ mln/morpho/opening_attribute.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -45,12 +45,16 @@
namespace morpho
{
- /*! Morphological area opening.
- */
+ /* 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 opening.
template <typename A,
typename I, typename N, typename O>
- void opening_attribute(const Image<I>& input, const Neighborhood<N>& nbh, mln_result(A) lambda,
- Image<O>& output);
+ void opening_attribute(const Image<I>& input, const Neighborhood<N>& nbh,
+ mln_result(A) lambda, Image<O>& output);
# ifndef MLN_INCLUDE_ONLY
@@ -101,7 +105,8 @@
// end of requirements
inline
- opening_attribute_t(const I_& input, const N_& nbh, mln_result(A) lambda, O_& output)
+ opening_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_decreasing(input))
{
Index: mln/morpho/opening_area.hh
--- mln/morpho/opening_area.hh (revision 1679)
+++ mln/morpho/opening_area.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -43,19 +43,23 @@
namespace morpho
{
- /*! Morphological area opening.
- */
+ /* 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 opening.
template <typename I, typename N, typename O>
- void opening_area(const Image<I>& input, const Neighborhood<N>& nbh, std::size_t lambda,
- Image<O>& output);
+ void opening_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 opening_area(const Image<I>& input, const Neighborhood<N>& nbh, std::size_t lambda,
- Image<O>& output)
+ void opening_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;
Index: mln/morpho/dilation.hh
--- mln/morpho/dilation.hh (revision 1679)
+++ mln/morpho/dilation.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// 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
@@ -43,16 +43,47 @@
namespace morpho
{
- /*! Morphological dilation.
- *
- * \todo Overload dilation_wrt_win for hline and vline and for fast
- * images.
- */
+ /// Morphological dilation using the neighborhood bound to an image.
+ ///
+ /// \{
+
+ /// Perform a morphological dilation of \a input using its
+ /// neighborhood and store the result into \a output.
+ ///
+ /// \pre \a input must be an image with a neighborhood.
+ /* FIXME: Do we want to keep this version? */
+ template <typename I, typename O>
+ void
+ dilation(const Image<I>& input, Image<O>& output);
+
+ /// Perform a morphological dilation of \a input using its
+ /// neighborhood and return the result.
+ ///
+ /// \pre \a input must be an image with a neighborhood.
+ template <typename I>
+ mln_concrete(I)
+ dilation(const Image<I>& input);
+ /// \}
+
+ /// Morphological dilation using windows.
+ ///
+ /// \todo Overload dilation_wrt_win for hline and vline and for fast
+ /// images.
+ ///
+ /// \{
+ /// Perform a morphological dilation of \a input using \a win and
+ /// store the result into \a output.
+ /* FIXME: Do we want to keep this version? */
template <typename I, typename W, typename O>
- void dilation(const Image<I>& input, const Window<W>& win, Image<O>& output);
+ void
+ dilation(const Image<I>& input, const Window<W>& win, Image<O>& output);
+ /// Perform a morphological dilation of \a input using \a win and
+ /// return the result.
template <typename I, typename W>
- mln_concrete(I) dilation(const Image<I>& input, const Window<W>& win);
+ mln_concrete(I)
+ dilation(const Image<I>& input, const Window<W>& win);
+ /// \}
@@ -61,11 +92,42 @@
namespace impl
{
+ /*---------------------.
+ | Neighborhood-based. |
+ `---------------------*/
+
+ /* FIXME: We might want to move this function into the body of
+ the facade (see at the bottom of the file. */
+ // Sole case. Convert the neighborhood into a window, and
+ // delegate to the window-based implementation.
+ template <typename I, typename N, typename O>
+ inline
+ void dilation_wrt_nbh(const Image<I>& input,
+ const Neighborhood<N>& nbh,
+ Image<O>& output)
+ {
+ /* FIXME: The following comment applies to every algorithm
+ having a neighborhood and a window flavor: move it
+ elsewhere.
+
+ We solely depend on the neighborhood-to-window conversion
+ here. This means the conversion should be smart enough to
+ produce a working window, even in the case of a non
+ dpoint-set-based neighborhood. */
+ dilation_wrt_win(input, to_window(nbh), output);
+ }
+
+
+ /*---------------.
+ | Window-based. |
+ `---------------*/
+
// On function.
template <typename I, typename W, typename O>
inline
- void dilation_on_function(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
+ void dilation_on_function(const Image<I>& input_, const Window<W>& win_,
+ Image<O>& output_)
{
const I& input = exact(input_);
const W& win = exact(win_);
@@ -88,7 +150,8 @@
template <typename I, typename W, typename O>
inline
- void dilation_on_set(const Image<I>& input_, const Window<W>& win_, Image<O>& output_)
+ void dilation_on_set(const Image<I>& input_, const Window<W>& win_,
+ Image<O>& output_)
{
const I& input = exact(input_);
const W& win = exact(win_);
@@ -108,51 +171,83 @@
}
}
+ // FIXME: Seems to be duplicate code!
+
+// /// Stage 1: dispatch w.r.t. the window type.
+// /// \{
+
+// /// Default case.
+// template <typename I, typename W, typename O>
+// inline
+// void dilation_wrt_win(const Image<I>& input, const Window<W>& win,
+// Image<O>& output)
+// {
+// // Perform stage 2: dispatch w.r.t. the value kind.
+// dilation_wrt_value(mln_trait_image_kind(I)(), exact(input),
+// exact(win), output);
+// }
// ...
- // FIXME: Stage 3: dispatch w.r.t. fast property
+ // ------------- //
+ // Dispatchers. //
+ // ------------- //
+
+ // FIXME: Stage 3: dispatch w.r.t. speed property.
+ // ...
- // Stage 2: dispatch w.r.t. the value kind.
+ /// Stage 2: dispatch w.r.t. the value kind.
+ /// \{
+ /// Binary => morphology on sets.
template <typename I, typename W, typename O>
inline
- void dilation_wrt_value(trait::image::kind::logic, // binary => morphology on sets
- const Image<I>& input, const Window<W>& win, Image<O>& output)
+ void dilation_wrt_value(trait::image::kind::logic,
+ const Image<I>& input, const Window<W>& win,
+ Image<O>& output)
{
return impl::dilation_on_set(exact(input), exact(win), output);
}
+ /// Otherwise => morphology on functions.
template <typename I, typename W, typename O>
inline
- void dilation_wrt_value(trait::image::kind::any, // otherwise => morphology on functions
- const Image<I>& input, const Window<W>& win, Image<O>& output)
+ void dilation_wrt_value(trait::image::kind::any,
+ const Image<I>& input, const Window<W>& win,
+ Image<O>& output)
{
return impl::dilation_on_function(exact(input), exact(win), output);
}
+ // End of stage 2.
+ /// \}
- // Stage 1: dispatch w.r.t. the window type.
- // |
- // V
+
+ /// Stage 1: dispatch w.r.t. the window type.
+ /// \{
+
+ /// Default case.
template <typename I, typename W, typename O>
inline
- void dilation_wrt_win(const Image<I>& input, const Window<W>& win, Image<O>& output)
+ void dilation_wrt_win(const Image<I>& input, const Window<W>& win,
+ Image<O>& output)
{
- dilation_wrt_value(mln_trait_image_kind(I)(), exact(input), exact(win), output);
- // |
- // --> call stage 2: dispatch w.r.t. the value kind
+ // Perform stage 2: dispatch w.r.t. the value kind.
+ dilation_wrt_value(mln_trait_image_kind(I)(), exact(input),
+ exact(win), output);
}
# ifdef MLN_CORE_WIN_RECTANGLE2D_HH
+ /// Rectangle window.
template <typename I, typename O>
inline
- void dilation_wrt_win(const Image<I>& input, const win::rectangle2d& win, Image<O>& output)
+ void dilation_wrt_win(const Image<I>& input, const win::rectangle2d& win,
+ Image<O>& output)
{
O temp(exact(output).domain());
morpho::dilation(input, win::hline2d(win.width()), temp);
@@ -166,8 +261,10 @@
# ifdef MLN_CORE_WIN_DIAG2D_HH
# ifdef MLN_CORE_WIN_BACKDIAG2D_HH
+ /// Octagon window.
template <typename I, typename O>
- void dilation_wrt_win(const Image<I>& input, const win::octagon2d& win, Image<O>& output)
+ void dilation_wrt_win(const Image<I>& input, const win::octagon2d& win,
+ Image<O>& output)
{
const unsigned len = win.length() / 3 + 1;
@@ -183,18 +280,72 @@
# endif // MLN_CORE_WIN_DIAG2D_HH
# endif // MLN_CORE_WIN_OCTAGON2D_HH
- // ^
- // |
- // end of stage1 (dispatch w.r.t. the window type)
+ // End of stage 1.
+
+ /// \}
} // end of namespace mln::morpho::impl
- // Facade.
+ /*----------.
+ | Facades. |
+ `----------*/
+
+ // ------------------------------------------------ //
+ // Facades for neighborhood-based implementations. //
+ // ------------------------------------------------ //
+
+ template <typename I, typename O>
+ void
+ dilation(const Image<I>& input, Image<O>& output)
+ {
+ trace::entering("morpho::dilation");
+
+ mln_precondition(exact(output).domain() == exact(input).domain());
+
+ // Ensure the image has a `neighb' typedef.
+ typedef mln_neighb(I) neighb;
+
+ // FIXME: Encapsulate this in a class + a macro.
+ // FIXME: Do we have better concept checking tools?
+ {
+ // Ensure the image has a `neighb' method.
+ neighb (I::*m)() const = &I::neighb;
+ m = 0;
+
+ // FIXME: Do we need to check for more?
+ }
+
+ impl::dilation_wrt_nbh(input, output);
+
+ trace::exiting("morpho::dilation");
+ }
+
+ template <typename I>
+ mln_concrete(I)
+ dilation(const Image<I>& input)
+ {
+ trace::entering("morpho::dilation");
+
+ mln_concrete(I) output;
+ initialize(output, input);
+ dilation(input, output);
+
+ trace::exiting("morpho::dilation");
+ return output;
+ }
+
+
+ // ------------------------------------------ //
+ // Facades for window-based implementations. //
+ // ------------------------------------------ //
template <typename I, typename W, typename O>
- void dilation(const Image<I>& input, const Window<W>& win, Image<O>& output)
+ void
+ dilation(const Image<I>& input, const Window<W>& win, Image<O>& output)
{
+ trace::entering("morpho::dilation");
+
mln_precondition(exact(output).domain() == exact(input).domain());
mln_precondition(! exact(win).is_empty());
@@ -202,6 +353,8 @@
if (exact(win).is_centered())
mln_postcondition(output >= input);
+
+ trace::exiting("morpho::dilation");
}
template <typename I, typename W>
Index: mln/morpho/Rd.hh
--- mln/morpho/Rd.hh (revision 1679)
+++ mln/morpho/Rd.hh (working copy)
@@ -28,6 +28,9 @@
#ifndef MLN_MORPHO_RD_HH
# define MLN_MORPHO_RD_HH
+// FIXME: This file, as well its functions and classes, shall not
+// contain capital letters.
+
/*!
* \file mln/morpho/Rd.hh
*
@@ -52,6 +55,11 @@
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. */
+
template <typename I, typename N>
I Rd(const Image<I>& f, const Image<I>& g, const Neighborhood<N>& nbh);
Index: mln/morpho/includes.hh
--- mln/morpho/includes.hh (revision 1679)
+++ mln/morpho/includes.hh (working copy)
@@ -65,5 +65,6 @@
# include <mln/morpho/minus.hh>
# include <mln/morpho/plus.hh>
+# include <mln/convert/to_window.hh>
#endif // ! MLN_MORPHO_INCLUDES_HH
Index: mln/labeling/blobs.hh
--- mln/labeling/blobs.hh (revision 1679)
+++ mln/labeling/blobs.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -47,6 +47,11 @@
namespace labeling
{
+ /* 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. */
+
/*! Connected component labeling of the binary objects of a binary
* image.
*
@@ -62,8 +67,8 @@
*/
template <typename I, typename N>
mln_ch_value(I, unsigned)
- blobs(const Image<I>& input, const Neighborhood<N>& nbh, unsigned& nlabels);
-
+ blobs(const Image<I>& input, const Neighborhood<N>& nbh,
+ unsigned& nlabels);
# ifndef MLN_INCLUDE_ONLY
@@ -137,10 +142,12 @@
template <typename I, typename N>
inline
mln_ch_value(I, unsigned)
- blobs(const Image<I>& input_, const Neighborhood<N>& nbh_, unsigned& nlabels)
+ blobs(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ unsigned& nlabels)
{
trace::entering("labeling::blobs");
- mlc_equal(mln_trait_image_kind(I), mln::trait::image::kind::binary)::check();
+ mlc_equal(mln_trait_image_kind(I),
+ mln::trait::image::kind::binary)::check();
const I& input = exact(input_);
const N& nbh = exact(nbh_);
mln_precondition(input.has_data());
Index: mln/labeling/flat_zones.hh
--- mln/labeling/flat_zones.hh (revision 1679)
+++ mln/labeling/flat_zones.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -44,6 +44,11 @@
namespace labeling
{
+ /* 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. */
+
/*! Connected component labeling of the flat zones of an image.
*
* \param[in] input The input image.
@@ -53,8 +58,7 @@
*/
template <typename I, typename N, typename L>
mln_ch_value(I, L)
- flat_zones(const Image<I>& input, const Neighborhood<N>& nbh,
- L& nlabels);
+ flat_zones(const Image<I>& input, const Neighborhood<N>& nbh, L& nlabels);
@@ -82,7 +86,8 @@
const S& s;
bool handles(const P&) const { return true; }
- bool equiv(const P& n, const P& p) const { return input(n) == input(p); }
+ bool equiv(const P& n, const P& p) const { return input(n) ==
+ input(p); }
void init() {}
bool labels(const P&) const { return true; }
@@ -140,7 +145,8 @@
mln_precondition(input.has_data());
// Calls the only (generic) impl.
- mln_ch_value(I, L) output = impl::generic::flat_zones_(input, nbh, nlabels);
+ mln_ch_value(I, L) output =
+ impl::generic::flat_zones_(input, nbh, nlabels);
trace::exiting("labeling::flat_zones");
return output;
Index: mln/labeling/level.hh
--- mln/labeling/level.hh (revision 1679)
+++ mln/labeling/level.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -50,6 +50,11 @@
namespace labeling
{
+ /* 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. */
+
/*! Connected component labeling of the image objects at a given
* level.
*
@@ -61,9 +66,8 @@
*/
template <typename I, typename N, typename L>
mln_ch_value(I, L)
- level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
- L& nlabels);
-
+ level(const Image<I>& input, const mln_value(I)& val,
+ const Neighborhood<N>& nbh, L& nlabels);
# ifndef MLN_INCLUDE_ONLY
@@ -145,13 +149,14 @@
template <typename I, typename N, typename L>
mln_ch_value(I, L)
- level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
- L& nlabels)
+ level(const Image<I>& input, const mln_value(I)& val,
+ const Neighborhood<N>& nbh, L& nlabels)
{
trace::entering("labeling::level");
mln_precondition(exact(input).has_data());
- mln_ch_value(I, L) output = impl::level_(mln_trait_image_speed(I)(),
+ mln_ch_value(I, L) output =
+ impl::level_(mln_trait_image_speed(I)(),
exact(input), val, exact(nbh), nlabels);
trace::exiting("labeling::level");
Index: mln/labeling/foreground.hh
--- mln/labeling/foreground.hh (revision 1679)
+++ mln/labeling/foreground.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -43,6 +43,11 @@
namespace labeling
{
+ /* 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. */
+
/*! Connected component labeling of the object part in a binary
* image.
*
@@ -73,10 +78,12 @@
unsigned& nlabels)
{
trace::entering("labeling::foreground");
- mlc_equal(mln_trait_image_kind(I), mln::trait::image::kind::binary)::check();
+ mlc_equal(mln_trait_image_kind(I),
+ mln::trait::image::kind::binary)::check();
mln_precondition(exact(input).has_data());
- mln_ch_value(I, unsigned) output = labeling::level(input, true, nbh, nlabels);
+ mln_ch_value(I, unsigned) output =
+ labeling::level(input, true, nbh, nlabels);
trace::exiting("labeling::foreground");
return output;
Index: mln/labeling/regional_minima.hh
--- mln/labeling/regional_minima.hh (revision 1679)
+++ mln/labeling/regional_minima.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -47,6 +47,11 @@
namespace labeling
{
+ /* 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. */
+
/*! Connected component labeling of the regional minima of an
* image.
*
@@ -62,7 +67,6 @@
L& nlabels);
-
# ifndef MLN_INCLUDE_ONLY
namespace impl
@@ -89,11 +93,14 @@
void init() { level::fill(attr, true); }
bool handles(const P&) const { return true; }
bool labels(const P& p) const { return attr(p); }
- bool equiv(const P& n, const P& p) const { return input(n) == input(p); }
- void do_no_union(const P& n, const P& p) { mln_invariant(input(n) < input(p));
+ bool equiv(const P& n, const P& p) const { return input(n) ==
+ input(p); }
+ void do_no_union(const P& n, const P& p) { mln_invariant(input(n) <
+ input(p));
attr(p) = false; }
void init_attr(const P&) {}
- void merge_attr(const P& r, const P& p) { attr(p) = attr(p) && attr(r); }
+ void merge_attr(const P& r, const P& p) { attr(p) = attr(p) &&
+ attr(r); }
// end of requirements
@@ -102,7 +109,8 @@
regional_minima_functor(const I_& input, const N_& nbh)
: input(input),
nbh(nbh),
- s(level::sort_points_increasing(input)), // FIXME: sort_psites_increasing
+ s(level::sort_points_increasing(input)), // FIXME:
+ // sort_psites_increasing
attr(input.domain())
{
}
@@ -150,7 +158,8 @@
mln_precondition(input.has_data());
// Calls the only (generic) impl.
- mln_ch_value(I, L) output = impl::generic::regional_minima_(input, nbh, nlabels);
+ mln_ch_value(I, L) output =
+ impl::generic::regional_minima_(input, nbh, nlabels);
trace::exiting("labeling::regional_minima");
return output;
Index: mln/labeling/regional_maxima.hh
--- mln/labeling/regional_maxima.hh (revision 1679)
+++ mln/labeling/regional_maxima.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -47,6 +47,11 @@
namespace labeling
{
+ /* 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. */
+
/*! Connected component labeling of the regional maxima of an
* image.
*
@@ -89,11 +94,14 @@
void init() { level::fill(attr, true); }
bool handles(const P&) const { return true; }
bool labels(const P& p) const { return attr(p); }
- bool equiv(const P& n, const P& p) const { return input(n) == input(p); }
- void do_no_union(const P& n, const P& p) { mln_invariant(input(n) > input(p));
+ bool equiv(const P& n, const P& p) const { return input(n) ==
+ input(p); }
+ void do_no_union(const P& n, const P& p) { mln_invariant(input(n) >
+ input(p));
attr(p) = false; }
void init_attr(const P&) {}
- void merge_attr(const P& r, const P& p) { attr(p) = attr(p) && attr(r); }
+ void merge_attr(const P& r, const P& p) { attr(p) = attr(p) &&
+ attr(r); }
// end of requirements
@@ -102,7 +110,8 @@
regional_maxima_functor(const I_& input, const N_& nbh)
: input(input),
nbh(nbh),
- s(level::sort_points_decreasing(input)), // FIXME: sort_psites_decreasing
+ s(level::sort_points_decreasing(input)), // FIXME:
+ // sort_psites_decreasing
attr(input.domain())
{
}
@@ -150,7 +159,8 @@
mln_precondition(input.has_data());
// Calls the only (generic) impl.
- mln_ch_value(I, L) output = impl::generic::regional_maxima_(input, nbh, nlabels);
+ mln_ch_value(I, L) output =
+ impl::generic::regional_maxima_(input, nbh, nlabels);
trace::exiting("labeling::regional_maxima");
return output;
Index: mln/labeling/level.spe.hh
--- mln/labeling/level.spe.hh (revision 1679)
+++ mln/labeling/level.spe.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -49,6 +49,11 @@
namespace labeling
{
+ /* 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. */
+
/*! Connected component labeling of the image objects at a given
* level.
*
@@ -60,8 +65,8 @@
*/
template <typename I, typename N, typename L>
mln_ch_value(I, L)
- level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
- L& nlabels);
+ level(const Image<I>& input, const mln_value(I)& val,
+ const Neighborhood<N>& nbh, L& nlabels);
# ifndef MLN_INCLUDE_ONLY
@@ -112,7 +117,8 @@
const mln_value(I_)& val;
- level_fastest_functor(const I_& input, const mln_value(I_)& val, const N_& nbh)
+ level_fastest_functor(const I_& input, const mln_value(I_)& val,
+ const N_& nbh)
: input(input),
nbh(nbh),
s(input.domain()),
Index: mln/labeling/background.hh
--- mln/labeling/background.hh (revision 1679)
+++ mln/labeling/background.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -43,6 +43,11 @@
namespace labeling
{
+ /* 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. */
+
/*! Connected component labeling of the background part in a
* binary image.
*
@@ -73,10 +78,12 @@
unsigned& nlabels)
{
trace::entering("labeling::background");
- mlc_equal(mln_trait_image_kind(I), mln::trait::image::kind::binary)::check();
+ mlc_equal(mln_trait_image_kind(I),
+ mln::trait::image::kind::binary)::check();
mln_precondition(exact(input).has_data());
- mln_ch_value(I, unsigned) output = labeling::level(input, false, nbh, nlabels);
+ mln_ch_value(I, unsigned) output =
+ labeling::level(input, false, nbh, nlabels);
trace::exiting("labeling::background");
return output;
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Start a small documentation/reminder on Milena's concepts.
* mln/core/concept/README: New.
README | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
Index: mln/core/concept/README
--- mln/core/concept/README (revision 0)
+++ mln/core/concept/README (revision 0)
@@ -0,0 +1,67 @@
+Milena Concepts
+
+FIXME: It'd be better to turn this file into a Doxygen documentation.
+In fact, the best place where to put this documentation is in the
+concept files themselves, but we'd like a kind of centralized summary
+too. An index would be nice.
+
+* Image
+Images are functions mapping point sites from a given domain (point
+site set) to a value.
+
+* Point Site
+[...]
+The most general point site is linked to a domain, and cannot be used
+with another domain.
+
+* Point
+A point is a point site, belonging to a domain (point set) compatible
+with several images. Thus, points can be used with different images.
+
+* Point Site Set
+FIXME: Is there a difference between a point site set and a point set?
+
+* Point Set
+Also called psite.
+
+* Point Site Iterator
+Also called psite iterator.
+
+* Point Iterator
+Also called piter.
+
+* Grid
+
+* Graph
+
+* Window
+A function mapping a point site to a set of point sites. The term
+``window'' is both used to name the function and the (mapped) set of
+point site (image in the mathematical sense). There are no additionnal
+requirement on the structure of set of the mapped point sites.
+
+* Neighborhood
+A function mapping a point site to a set of point sites. The term
+``neighborhood'' is both used to name the function and the (mapped)
+set of point site (image in the mathematical sense). The neighborhood
+relationship must be symmetric: if B is in the neighborhood of A, then
+A must be in the neighborhood of B. Neighborhoods are attached to
+images: an algorithm working on the neighborhood of an image shall get
+the neighborhood from the input image(s), not from an extra argument
+passed to the algorithm.
+
+* Window Iterator
+Also called qiter.
+
+* Neighborhood Iterator
+Also called niter.
+(FIXME: Do they actually exist in Milena? The current trend in Milena
+is to convert neighborhoods to windows in implementations, hence only
+window iterators are used.)
+
+
+
+Local Variables:
+mode: outline
+ispell-local-dictionary: "american"
+End:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Don't forget to read warnings from the compiler! A good habit is to
use `-Werror' from time to time, e.g.:
make check CXXFLAGS='-Werror'
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Miscellaneous fixes.
* mln/accu/rank_bool.hh (mln::accu::rank_<bool>::rank_): Reorder
the elements of the initialization list to match the order of the
members.
* mln/core/mesh_window_piter.hh: Typo in comment.
accu/rank_bool.hh | 6 +++---
core/mesh_window_piter.hh | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
Index: mln/accu/rank_bool.hh
--- mln/accu/rank_bool.hh (revision 1677)
+++ mln/accu/rank_bool.hh (working copy)
@@ -77,9 +77,9 @@
inline
rank_<bool>::rank_(unsigned k, unsigned n)
- : k_(k),
- n_(n),
- nfalse_(0)
+ : nfalse_(0),
+ k_(k),
+ n_(n)
{
mln_assertion(k_ < n_);
init();
Index: mln/core/mesh_window_piter.hh
--- mln/core/mesh_window_piter.hh (revision 1677)
+++ mln/core/mesh_window_piter.hh (working copy)
@@ -139,7 +139,7 @@
{
// FIXME: This is inefficient. The graph structure should be able
// to produce the set of adjacent nodes fast. Boost Graphs
- // probably provides adequates structures to get fecth these
+ // probably provides adequates structures to fetch these
// neighbors in constant time.
do
++i_;
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-01-21 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add rank filter.
* mln/morpho/rank_filter.hh: New, the rank filter.
* mln/accu/rank.hh: clear the accu in init(), do a ratio to get the
result when the accumulator is not full.
* mln/morpho/includes.hh: Add rank.hh include.
* tests/morpho/rank_filter.cc: New, tests, compare with erosion and
dilatation.
---
mln/accu/rank.hh | 8 ++
mln/morpho/includes.hh | 1
mln/morpho/rank_filter.hh | 120 ++++++++++++++++++++++++++++++++++++++++++++
tests/morpho/rank_filter.cc | 93 ++++++++++++++++++++++++++++++++++
4 files changed, 221 insertions(+), 1 deletion(-)
Index: trunk/milena/tests/morpho/rank_filter.cc
===================================================================
--- trunk/milena/tests/morpho/rank_filter.cc (revision 0)
+++ trunk/milena/tests/morpho/rank_filter.cc (revision 1676)
@@ -0,0 +1,93 @@
+// 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/rank_filter.cc
+ *
+ * \brief Test on mln::morpho::rank_filter.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/win/rectangle2d.hh>
+#include <mln/win/octagon2d.hh>
+#include <mln/win/diag2d.hh>
+#include <mln/win/backdiag2d.hh>
+#include <mln/core/window2d.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/level/fill.hh>
+#include <mln/level/compare.hh>
+#include <mln/level/median.hh>
+#include <mln/morpho/rank_filter.hh>
+#include <mln/morpho/dilation.hh>
+
+
+#include <mln/pw/value.hh>
+#include <mln/pw/cst.hh>
+#include <mln/fun/ops.hh>
+
+#include <mln/convert/to_p_array.hh>
+#include <mln/convert/to_window.hh>
+
+#include "tests/data.hh"
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ win::rectangle2d rec(21, 21);
+ border::thickness = 66;
+
+ image2d<int_u8> lena;
+ io::pgm::load(lena, MLN_IMG_DIR "/small.pgm");
+
+ {
+ win::octagon2d oct(31);
+ image2d<int_u8> out;
+ out = morpho::rank_filter(lena, rec, 0);
+
+ image2d<int_u8> ref(lena.domain());
+ ref = morpho::erosion(lena, rec);
+ mln_assertion(ref == out);
+ }
+
+
+ {
+ win::octagon2d oct(31);
+ image2d<int_u8> out;
+ out = morpho::rank_filter(lena, rec, 21 * 21 - 1);
+
+ image2d<int_u8> ref(lena.domain());
+ ref = morpho::dilation(lena, rec);
+ mln_assertion(ref == out);
+ }
+
+}
Index: trunk/milena/mln/accu/rank.hh
===================================================================
--- trunk/milena/mln/accu/rank.hh (revision 1675)
+++ trunk/milena/mln/accu/rank.hh (revision 1676)
@@ -114,6 +114,7 @@
void
rank_<T>::init()
{
+ elts_.clear();
}
template <typename T>
@@ -148,9 +149,14 @@
T
rank_<T>::to_result() const
{
- mln_assertion(n_ == elts_.size());
+ // Fixme : Call to inplace to unconst (*this).
inplace(*this).sort();
+
+ if (n_ == elts_.size())
return elts_[k_];
+ else
+ // FIXME : This alternative is used to handle images edges.
+ return elts_[(elts_.size() * k_) / n_];
}
template <typename T>
Index: trunk/milena/mln/morpho/rank_filter.hh
===================================================================
--- trunk/milena/mln/morpho/rank_filter.hh (revision 0)
+++ trunk/milena/mln/morpho/rank_filter.hh (revision 1676)
@@ -0,0 +1,120 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// 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_RANK_FILTER_HH
+# define MLN_MORPHO_RANK_FILTER_HH
+
+/*! \file mln/morpho/rank_filter.hh
+ *
+ * \brief Morphological rank_filter.
+ */
+
+# include <mln/morpho/includes.hh>
+# include <mln/convert/to_p_array.hh>
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ /*! Morphological rank_filter.
+ */
+ template <typename I, typename W>
+ mln_concrete(I)
+ rank_filter(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ namespace generic
+ {
+
+ // On function.
+
+ template <typename I, typename W>
+ inline
+ mln_concrete(I)
+ rank_filter_(const I& input, const W& win, unsigned k)
+ {
+ trace::entering("morpho::impl::generic::rank_filter_");
+
+ mln_concrete(I) output;
+ initialize(output, input);
+
+ accu::rank_<mln_value(I)> accu(k, convert::to_p_array(win, mln_point(I)()).npoints());
+ mln_piter(I) p(input.domain());
+ mln_qiter(W) q(win, p);
+ for_all(p)
+ {
+ accu.init();
+ for_all(q)
+ if (input.has(q))
+ accu.take(input(q));
+// else
+// accu.take(mln_value(I)(literal::zero));
+ output(p) = accu;
+ }
+
+ trace::exiting("morpho::impl::generic::rank_filter_");
+ return output;
+ }
+
+ } // end of namespace mln::morpho::impl::generic
+
+ } // end of namespace mln::morpho::impl
+
+
+
+ // Facades.
+
+ template <typename I, typename W>
+ inline
+ mln_concrete(I)
+ rank_filter(const Image<I>& input, const Window<W>& win, unsigned k)
+ {
+ trace::entering("morpho::rank_filter");
+ mln_precondition(exact(input).has_data());
+ mln_precondition(! exact(win).is_empty());
+
+ mln_concrete(I) output = impl::generic::rank_filter_(exact(input), exact(win), k);
+
+ trace::exiting("morpho::rank_filter");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_RANK_FILTER_HH
Index: trunk/milena/mln/morpho/includes.hh
===================================================================
--- trunk/milena/mln/morpho/includes.hh (revision 1675)
+++ trunk/milena/mln/morpho/includes.hh (revision 1676)
@@ -44,6 +44,7 @@
# include <mln/accu/max.hh>
# include <mln/accu/min_h.hh>
# include <mln/accu/max_h.hh>
+# include <mln/accu/rank.hh>
# include <mln/fun/v2v/saturate.hh>
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-01-21 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add accu::rank.
* mln/accu/rank.hh: New, accumulator for the rank filters.
* mln/accu/rank_bool.hh: New. Specialisation of accu::rank<bool>.
* tests/accu/rank.cc: New.
---
mln/accu/rank.hh | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++
mln/accu/rank_bool.hh | 133 +++++++++++++++++++++++++++++++++++++
tests/accu/rank.cc | 55 +++++++++++++++
3 files changed, 364 insertions(+)
Index: trunk/milena/tests/accu/rank.cc
===================================================================
--- trunk/milena/tests/accu/rank.cc (revision 0)
+++ trunk/milena/tests/accu/rank.cc (revision 1675)
@@ -0,0 +1,55 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// 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/accu/rank.cc
+ *
+ * \brief Tests on mln::accu::rank.
+ */
+
+#include <mln/accu/rank.hh>
+
+int main()
+{
+ using namespace mln;
+
+ accu::rank_<int> accu(3, 5);
+
+ accu.take(3);
+ accu.take(1);
+ accu.take(4);
+ accu.take(5);
+ accu.take(2);
+ mln_assertion(accu.to_result() == 4);
+
+ accu::rank_<bool> accu_bool(1, 5);
+ accu_bool.take(true);
+ accu_bool.take(true);
+ accu_bool.take(true);
+ accu_bool.take(true);
+ accu_bool.take(false);
+ mln_assertion(accu_bool == true);
+}
Index: trunk/milena/mln/accu/rank.hh
===================================================================
--- trunk/milena/mln/accu/rank.hh (revision 0)
+++ trunk/milena/mln/accu/rank.hh (revision 1675)
@@ -0,0 +1,176 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// 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_ACCU_RANK_HH
+# define MLN_ACCU_RANK_HH
+
+/*! \file mln/accu/rank.hh
+ *
+ * \brief Define an rank accumulator.
+ */
+
+# include <vector>
+# include <mln/accu/internal/base.hh>
+# include <mln/core/concept/meta_accumulator.hh>
+# include <mln/trait/value_.hh>
+# include <mln/util/pix.hh>
+# include <mln/core/inplace.hh>
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+
+ /*! \brief Generic rank accumulator class.
+ *
+ * The parameter \c T is the type of values.
+ */
+ template <typename T>
+ struct rank_ : public mln::accu::internal::base_< T, rank_<T> >
+ {
+ typedef T argument;
+ typedef T result;
+
+ rank_(unsigned k, unsigned n);
+
+ void init();
+ void take_as_init(const argument& t);
+ void take(const argument& t);
+ void take(const rank_<T>& other);
+ void sort();
+
+ T to_result() const;
+
+ protected:
+
+ std::vector<T> elts_;
+ bool is_sorted_;
+ unsigned k_; // 0 <= k_ < n
+ unsigned n_;
+ };
+
+
+ template <typename I> struct rank_< util::pix<I> >;
+
+
+ /*!
+ * \brief Meta accumulator for rank.
+ */
+ struct rank : public Meta_Accumulator< rank >
+ {
+ template <typename T>
+ struct with
+ {
+ typedef rank_<T> ret;
+ };
+ };
+
+
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ inline
+ rank_<T>::rank_(unsigned k, unsigned n)
+ : k_(k),
+ n_(n),
+ is_sorted_(false)
+ {
+ mln_assertion(k_ < n_);
+ init();
+ }
+
+ template <typename T>
+ inline
+ void
+ rank_<T>::init()
+ {
+ }
+
+ template <typename T>
+ inline
+ void rank_<T>::take_as_init(const argument& t)
+ {
+ elts_.push_back(t);
+ is_sorted_ = false;
+ }
+
+ template <typename T>
+ inline
+ void rank_<T>::take(const argument& t)
+ {
+ elts_.push_back(t);
+ is_sorted_ = false;
+ }
+
+ template <typename T>
+ inline
+ void
+ rank_<T>::take(const rank_<T>& other)
+ {
+ elts_.insert(elts_.end(),
+ other.elts_.begin(),
+ other.elts_.end());
+ is_sorted_ = false;
+ }
+
+ template <typename T>
+ inline
+ T
+ rank_<T>::to_result() const
+ {
+ mln_assertion(n_ == elts_.size());
+ inplace(*this).sort();
+ return elts_[k_];
+ }
+
+ template <typename T>
+ inline
+ void
+ rank_<T>::sort()
+ {
+ if (!is_sorted_)
+ {
+ is_sorted_ = true;
+ std::sort(elts_.begin(), elts_.end());
+ }
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+#include <mln/accu/rank_bool.hh>
+
+#endif // ! MLN_ACCU_RANK_HH
Index: trunk/milena/mln/accu/rank_bool.hh
===================================================================
--- trunk/milena/mln/accu/rank_bool.hh (revision 0)
+++ trunk/milena/mln/accu/rank_bool.hh (revision 1675)
@@ -0,0 +1,133 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// 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_ACCU_RANK_BOOL_HH
+# define MLN_ACCU_RANK_BOOL_HH
+
+/*! \file mln/accu/rank_bool.hh
+ *
+ * \brief Define an rank accumulator.
+ */
+
+# include <vector>
+# include <mln/accu/internal/base.hh>
+# include <mln/core/concept/meta_accumulator.hh>
+# include <mln/trait/value_.hh>
+# include <mln/util/pix.hh>
+# include <mln/core/inplace.hh>
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+ // Fwd declaration.
+ template <typename T> struct rank_;
+
+ /*! \brief rank accumulator class for boolean.
+ *
+ */
+ template <>
+ struct rank_<bool> : public mln::accu::internal::base_< bool, rank_<bool> >
+ {
+ typedef bool argument;
+ typedef bool result;
+
+ rank_(unsigned k, unsigned n);
+
+ void init();
+ void take_as_init(const argument& t);
+ void take(const argument& t);
+ void take(const rank_<bool>& other);
+
+ bool to_result() const;
+
+ protected:
+ unsigned nfalse_;
+ unsigned k_; // 0 <= k_ < n
+ unsigned n_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ inline
+ rank_<bool>::rank_(unsigned k, unsigned n)
+ : k_(k),
+ n_(n),
+ nfalse_(0)
+ {
+ mln_assertion(k_ < n_);
+ init();
+ }
+
+
+ inline
+ void
+ rank_<bool>::init()
+ {
+ }
+
+
+ inline
+ void rank_<bool>::take_as_init(const argument& t)
+ {
+ nfalse_ += !t;
+ }
+
+
+ inline
+ void rank_<bool>::take(const argument& t)
+ {
+ nfalse_ += !t;
+ }
+
+
+ inline
+ void
+ rank_<bool>::take(const rank_<bool>& other)
+ {
+ nfalse_ += other.nfalse_;
+ }
+
+
+ inline
+ bool
+ rank_<bool>::to_result() const
+ {
+ mln_assertion(nfalse_ <= n_);
+ return k_ >= nfalse_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_RANK_BOOL_HH
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-01-18 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add tools for display in random color a labeled image.
* mln/draw/label.hh: New function which creates a color image from
a labeled image.
* tests/draw/label.cc: New test for that.
---
mln/draw/label.hh | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/draw/label.cc | 59 +++++++++++++++++++++++++
2 files changed, 180 insertions(+)
Index: trunk/milena/tests/draw/label.cc
===================================================================
--- trunk/milena/tests/draw/label.cc (revision 0)
+++ trunk/milena/tests/draw/label.cc (revision 1674)
@@ -0,0 +1,59 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// 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/draw/label.cc
+ *
+ * \brief Tests on mln::draw::label.
+ */
+
+
+#include <mln/core/image2d.hh>
+#include <mln/debug/iota.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/draw/label.hh>
+#include <mln/literal/all.hh>
+
+#include <mln/core/image2d.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/labeling/blobs.hh>
+#include <mln/display/save_and_show.hh>
+
+#include "tests/data.hh"
+
+
+int
+main()
+{
+ using namespace mln;
+ image2d<bool> input = io::pbm::load(MLN_IMG_DIR "/picasso.pbm");
+ unsigned n;
+ image2d<unsigned> ima = labeling::blobs(input, c4(), n);
+ image2d<value::rgb8> out = draw::label (ima, literal::black);
+ display::save_and_show(out, "display", 1);
+}
Index: trunk/milena/mln/draw/label.hh
===================================================================
--- trunk/milena/mln/draw/label.hh (revision 0)
+++ trunk/milena/mln/draw/label.hh (revision 1674)
@@ -0,0 +1,121 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// 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_DRAW_LABEL_HH
+# define MLN_DRAW_LABEL_HH
+
+/*! \file mln/draw/label.hh
+ *
+ * \brief Draw a random color image from a label image.
+ */
+
+# include <mln/core/clone.hh>
+# include <mln/core/concept/image.hh>
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
+
+# include <mln/trait/image_from_mesh.hh>
+# include <mln/core/image_if_value.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/level/fill.hh>
+# include <mln/level/paste.hh>
+# include <mln/core/p_set.hh>
+# include <mln/metal/is_not.hh>
+# include <mln/core/image_if_value.hh>
+# include <mln/debug/println.hh>
+
+namespace mln
+{
+
+ namespace draw
+ {
+
+ /*! Draw a new image from a data (int, unsigned, int_u8, etc...) label image.
+ *
+ * \param[in] input The input image.
+ * \param[in] background The value to fill background output.
+ *
+ * \return A rgb8 image.
+ *
+ * \pre \p input has to be initialized.
+ *
+ */
+ template <typename I>
+ typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret
+ label(Image<I>& input, const value::rgb8& background);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret
+ label(Image<I>& input, const value::rgb8& background)
+ {
+ typedef mln_value(I) V;
+ typedef mln_ch_value(I, value::rgb8) O;
+ typedef const mln::pset_if<mln_pset(I), mln::fun::eq_p2b_expr_<mln::pw::value_<I>, mln::pw::cst_<V> > > F;
+
+ I in = exact(input);
+ mln_precondition(in.has_data());
+ I ref = clone(in);
+ O out (in.domain ());
+
+ level::fill(out, background);
+ mln_piter(I) p (out.domain());
+ for_all (p)
+ {
+ if (ref(p) == 0)
+ continue;
+ value::rgb8 color;
+ while (1)
+ {
+ int r = rand() % 256;
+ int g = rand() % 256;
+ int b = rand() % 256;
+ if (r + g + b < 50)
+ continue;
+ color = value::rgb8(r, g, b);
+ break;
+ }
+ V val = ref(p);
+ image_if_value<I> ima_if = ref | val;
+ mln_piter(F) l (ima_if.domain());
+ for_all (l)
+ out(l) = color;
+ level::fill(ima_if, 0);
+ }
+ return out;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::draw
+
+} // end of namespace mln
+
+
+#endif // ! MLN_DRAW_LINE_HH