Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
January 2008
- 6 participants
- 89 discussions
[Olena] #123: Revamp general graph-based images (aka badly named « mesh images »)
by Olena 09 Apr '08
by Olena 09 Apr '08
09 Apr '08
#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.
1
7
1701: Remove morpho::level_components and morpho::extrema_components.
by Roland Levillain 30 Jan '08
by Roland Levillain 30 Jan '08
30 Jan '08
https://svn.lrde.epita.fr/svn/oln/trunk/milena
labeling::flat_zones and labeling::regional_minima /
labeling::regional_maxima provide the same services.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Remove morpho::level_components and morpho::extrema_components.
* mln/morpho/extrema_components.hh,
* mln/morpho/level_components.hh:
Remove.
* tests/morpho/extrema_components.cc,
* tests/morpho/level_components.cc:
Remove test.
* tests/morpho/Makefile.am (check_PROGRAMS): Remove
extrema_components and level_components_SOURCES.
(extrema_components_SOURCES, level_components_SOURCES): Remove.
Makefile.am | 5 -----
1 file changed, 5 deletions(-)
Index: tests/morpho/Makefile.am
--- tests/morpho/Makefile.am (revision 1700)
+++ tests/morpho/Makefile.am (working copy)
@@ -9,11 +9,9 @@
dilation_max_h \
erosion \
erosion_min_h \
- extrema_components \
gradient \
hit_or_miss \
laplacian \
- level_components \
meyer_wst \
meyer_wst_long \
opening_area \
@@ -28,9 +26,6 @@
opening_area_SOURCES = opening_area.cc
closing_area_SOURCES = closing_area.cc
-level_components_SOURCES = level_components.cc
-extrema_components_SOURCES = extrema_components.cc
-
contrast_SOURCES = contrast.cc
gradient_SOURCES = gradient.cc
hit_or_miss_SOURCES = hit_or_miss.cc
1
0
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).
1
0
29 Jan '08
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Convert Meyer's WST implementation to neighborhood-based.
* mln/morpho/meyer_wst.hh: Use neighborhoods instead of windows to
express the connexity of the markers.
Use mln::labeling::regional_minima instead of
mln::morpho::minima_components.
* tests/morpho/meyer_wst.cc,
* tests/morpho/meyer_wst_long.cc:
Adjust tests.
mln/morpho/meyer_wst.hh | 91 ++++++++++++++++++++++++++---------------
tests/morpho/meyer_wst.cc | 10 +---
tests/morpho/meyer_wst_long.cc | 15 ++++--
3 files changed, 70 insertions(+), 46 deletions(-)
Index: mln/morpho/meyer_wst.hh
--- mln/morpho/meyer_wst.hh (revision 1698)
+++ mln/morpho/meyer_wst.hh (working copy)
@@ -45,7 +45,8 @@
# include <mln/util/greater_point.hh>
# include <mln/morpho/includes.hh>
-# include <mln/morpho/extrema_components.hh>
+# include <mln/labeling/regional_minima.hh>
+
namespace mln
@@ -61,34 +62,58 @@
processing it. Then, add a reference to
mln/morpho/lower_completion.hh. */
- /* FIXME: More doc. */
+ /** \brief Meyer's Watershed Transform (WST) algorithm.
- /// 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);
+ \param[in] input The input image.
+ \param[in] nbh The connexity of markers.
+ \param[out] nbasins The number of basins.
+
+ \li \p L is the type of labels, used to number the watershed
+ itself (with the minimal value), and the basins.
+ \li \p I is the exact type of the input image.
+ \li \p N is the exact type of the neighborhood used to express
+ \a input's connexity. */
+ template <typename L, typename I, typename N>
+ mln_ch_value(I, L)
+ meyer_wst(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nbasins);
+
+ /** \brief Meyer's Watershed Transform (WST) algorithm, with no
+ count of basins.
+
+ \param[in] input The input image.
+ \param[in] nbh The connexity of markers.
+
+ \li \p L is the type of labels, used to number the watershed
+ itself (with the minimal value), and the basins.
+ \li \p I is the exact type of the input image.
+ \li \p N is the exact type of the neighborhood used to express
+ \a input's connexity.
+
+ Note that the first parameter, \p L, is not automatically
+ valued from the type of the actual argument during implicit
+ instantiation: you have to explicitly pass this parameter at
+ call sites. */
+ template <typename L, typename I, typename N>
+ mln_ch_value(I, L)
+ meyer_wst(const Image<I>& input, const Neighborhood<N>& nbh);
# 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)
+ template <typename L, typename I, typename N>
+ mln_ch_value(I, L)
+ meyer_wst(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nbasins)
{
/* FIXME: Ensure the input image has scalar values. */
- typedef DestValue marker;
+ typedef L 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);
+ labeling::regional_minima (input, nbh, nbasins);
// Ordered queue.
typedef mln_point(I) point;
@@ -101,11 +126,11 @@
// 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);
+ mln_niter(N) n(nbh, p);
for_all (p)
if (markers(p) == unmarked)
- for_all(q)
- if (markers.has(q) && markers(q) != unmarked)
+ for_all(n)
+ if (markers.has(n) && markers(n) != unmarked)
{
queue.push(p);
break;
@@ -122,16 +147,16 @@
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)
+ mln_niter(N) n(nbh, p);
+ for_all(n)
+ if (markers.has(n) && markers(n) != unmarked)
if (adjacent_marker == unmarked)
{
- adjacent_marker = markers(q);
+ adjacent_marker = markers(n);
single_adjacent_marker_p = true;
}
else
- if (adjacent_marker != markers(q))
+ if (adjacent_marker != markers(n))
{
single_adjacent_marker_p = false;
break;
@@ -143,20 +168,20 @@
if (single_adjacent_marker_p)
{
markers(p) = adjacent_marker;
- for_all(q)
- if (markers.has(q) && markers(q) == unmarked)
- queue.push(q);
+ for_all(n)
+ if (markers.has(n) && markers(n) == unmarked)
+ queue.push(n);
}
}
return markers;
}
- template <typename DestValue, typename I, typename W>
- mln_ch_value(I, DestValue)
- meyer_wst(const Image<I>& input, const Window<W>& win)
+ template <typename L, typename I, typename N>
+ mln_ch_value(I, L)
+ meyer_wst(const Image<I>& input, const Neighborhood<N>& nbh)
{
- unsigned nbasins;
- return meyer_wst<DestValue>(input, nbasins);
+ L nbasins;
+ return meyer_wst<L>(input, nbh, nbasins);
}
# endif // ! MLN_INCLUDE_ONLY
Index: tests/morpho/meyer_wst.cc
--- tests/morpho/meyer_wst.cc (revision 1698)
+++ tests/morpho/meyer_wst.cc (working copy)
@@ -34,8 +34,6 @@
#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>
@@ -54,11 +52,9 @@
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);
+ typedef int_u8 wst_val;
+ wst_val nbasins;
+ image2d<int_u8> output = morpho::meyer_wst(input, c4(), nbasins);
std::cout << "nbasins = " << nbasins << std::endl;
io::pgm::save(output, "out.pgm");
}
Index: tests/morpho/meyer_wst_long.cc
--- tests/morpho/meyer_wst_long.cc (revision 1698)
+++ tests/morpho/meyer_wst_long.cc (working copy)
@@ -35,15 +35,17 @@
#include <mln/core/window2d.hh>
#include <mln/core/neighb2d.hh>
-#include <mln/convert/to_window.hh>
#include <mln/level/stretch.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/int_u16.hh>
+#include <mln/morpho/gradient.hh>
#include <mln/morpho/closing_area.hh>
#include <mln/morpho/meyer_wst.hh>
+#include <mln/convert/to_window.hh>
+
#include <mln/pw/cst.hh>
#include <mln/pw/value.hh>
@@ -63,16 +65,17 @@
image2d<int_u8> input;
io::pgm::load(input, MLN_IMG_DIR "/lena.pgm");
+ image2d<int_u8> gradient =
+ morpho::gradient (input, convert::to_window(c4()));
+
// Simplify the input image.
image2d<int_u8> work(input.domain());
- morpho::closing_area(input, c4(), 200, work);
+ morpho::closing_area(gradient, c4(), 200, work);
// Perform a Watershed Transform.
typedef int_u16 wst_val;
- unsigned nbasins;
- // FIXME: Do we really need to use a neighborood to express a 4-c window?
- image2d<wst_val> ws =
- morpho::meyer_wst<wst_val>(work, convert::to_window(c4()), nbasins);
+ wst_val nbasins;
+ image2d<wst_val> ws = morpho::meyer_wst(work, c4(), nbasins);
std::cout << "nbasins = " << nbasins << std::endl;
// Save the image in color.
1
0
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.
*
1
0
Patch (non) proposal (Convert mln/labelling/ from neighborhoods to windows)
by Roland Levillain 29 Jan '08
by Roland Levillain 29 Jan '08
29 Jan '08
As the time of checking in, I realized this patch might be reverted very
soon, since labeling algorithms actually *do* need neighborhoods to
express a connexity, not windows (which lack the symmetry property).
So, instead of checking in this patch now, I just leave it here (in
olena-patches) so that we can possibly use it later, if needed (but I
doubt so).
ChangeLog:
Convert mln/labelling/ from neighborhoods to windows.
* mln/canvas/labeling.hh: Use windows instead of neighborhoods.
* mln/labeling/blobs.hh,
* mln/labeling/flat_zones.hh,
* mln/labeling/level.hh,
* mln/labeling/foreground.hh,
* mln/labeling/regional_minima.hh,
* mln/labeling/regional_maxima.hh,
* mln/labeling/level.spe.hh,
* mln/labeling/background.hh:
Convert routine calls using neighborhoods to windows.
canvas/labeling.hh | 24 +++++++++++++---------
labeling/background.hh | 18 +++++++----------
labeling/blobs.hh | 46 +++++++++++++++++++
+------------------------
labeling/flat_zones.hh | 40 +++++++++++++++++
+--------------------
labeling/foreground.hh | 18 +++++++----------
labeling/level.hh | 35 ++++++++++++++++++---------------
labeling/level.spe.hh | 42 +++++++++++++++++++
+--------------------
labeling/regional_maxima.hh | 40 +++++++++++++++++
+--------------------
labeling/regional_minima.hh | 40 +++++++++++++++++
+--------------------
9 files changed, 148 insertions(+), 155 deletions(-)
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
@@ -53,9 +53,13 @@
// Functor.
F& f;
+ // Image type.
typedef typename F::I I;
- typedef typename F::N N;
+ // Window type.
+ typedef typename F::W W;
+ // Label type.
typedef typename F::L L;
+ // Point set.
typedef typename F::S S;
// Local type.
@@ -100,7 +104,7 @@
F& f;
typedef typename F::I I;
- typedef typename F::N N;
+ typedef typename F::W W;
typedef typename F::L L;
// Auxiliary data.
@@ -163,16 +167,16 @@
labeling<F>::pass_1()
{
mln_fwd_piter(S) p(f.s);
- mln_niter(N) n(f.nbh, p);
+ mln_qiter(W) q(f.win, p);
for_all(p) if (f.handles(p))
{
make_set(p);
- for_all(n)
- if (f.input.has(n) && deja_vu(n))
- if (f.equiv(n, p))
- do_union(n, p);
+ for_all(q)
+ if (f.input.has(q) && deja_vu(q))
+ if (f.equiv(q, p))
+ do_union(q, p);
else
- f.do_no_union(n, p);
+ f.do_no_union(q, p);
deja_vu(p) = true;
}
}
@@ -272,7 +276,7 @@
mln_bkd_pixter(const I) p(f.input);
typedef window<mln_dpoint(I)> W;
- W win = mln::convert::to_upper_window(f.nbh);
+ W win = mln::convert::to_upper_window(f.win);
mln_qixter(const I, W) n(p, win);
for_all(p) if (f.handles(p))
Index: mln/labeling/blobs.hh
--- mln/labeling/blobs.hh (revision 1697)
+++ mln/labeling/blobs.hh (working copy)
@@ -35,7 +35,7 @@
*/
# include <mln/core/concept/image.hh>
-# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/window.hh>
# include <mln/level/fill.hh>
# include <mln/core/p_queue_fast.hh>
@@ -47,16 +47,14 @@
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. */
+ // FIXME: Provide a neighborhood-aware version of these
+ // algorithms.
/*! Connected component labeling of the binary objects of a binary
* image.
*
* \param[in] input The input image.
- * \param[in] nbh The neighborhood.
+ * \param[in] win The connexity of the objects.
* \param[out] nlabels The number of labels.
* \return The label image.
*
@@ -65,10 +63,9 @@
* A fast queue is used so that the algorithm is not recursive and
* can handle large binary objects (blobs).
*/
- template <typename I, typename N>
+ template <typename I, typename W>
mln_ch_value(I, unsigned)
- blobs(const Image<I>& input, const Neighborhood<N>& nbh,
- unsigned& nlabels);
+ blobs(const Image<I>& input, const Window<W>& win, unsigned&
nlabels);
# ifndef MLN_INCLUDE_ONLY
@@ -79,14 +76,14 @@
namespace generic
{
- template <typename I, typename N>
+ template <typename I, typename W>
mln_ch_value(I, unsigned)
- blobs_(const I& input, const N& nbh, unsigned& nlabels)
+ blobs_(const I& input, const W& win, unsigned& nlabels)
{
typedef mln_psite(I) P;
P cur;
- mln_niter(N) n(nbh, cur);
+ mln_qiter(W) q(win, cur);
p_queue_fast<P> qu;
// Initialization.
@@ -109,12 +106,12 @@
{
cur = qu.front();
qu.pop();
- for_all(n) if (input.has(n))
- if (input(n) && ! output(n))
+ for_all(q) if (input.has(q))
+ if (input(q) && ! output(q))
{
- mln_invariant(! qu.has(n));
- qu.push(n);
- output(n) = nlabels;
+ mln_invariant(! qu.has(q));
+ qu.push(q);
+ output(q) = nlabels;
}
}
while (! qu.is_empty());
@@ -126,12 +123,12 @@
} // end of namespace mln::labeling::impl::generic
- template <typename I, typename N>
+ template <typename I, typename W>
mln_ch_value(I, unsigned)
- blobs_(const I& input, const N& nbh, unsigned& nlabels)
+ blobs_(const I& input, const W& win, unsigned& nlabels)
{
// The only implementation is the generic one.
- return generic::blobs_(input, nbh, nlabels);
+ return generic::blobs_(input, win, nlabels);
}
} // end of namespace mln::labeling::impl
@@ -139,20 +136,19 @@
// Facade.
- template <typename I, typename N>
+ template <typename I, typename W>
inline
mln_ch_value(I, unsigned)
- blobs(const Image<I>& input_, const Neighborhood<N>& nbh_,
- unsigned& nlabels)
+ blobs(const Image<I>& input_, const Window<W>& win_, unsigned&
nlabels)
{
trace::entering("labeling::blobs");
mlc_equal(mln_trait_image_kind(I),
mln::trait::image::kind::binary)::check();
const I& input = exact(input_);
- const N& nbh = exact(nbh_);
+ const W& win = exact(win_);
mln_precondition(input.has_data());
- mln_ch_value(I, unsigned) output = impl::blobs_(input, nbh,
nlabels);
+ mln_ch_value(I, unsigned) output = impl::blobs_(input, win,
nlabels);
trace::exiting("labeling::blobs");
return output;
Index: mln/labeling/flat_zones.hh
--- mln/labeling/flat_zones.hh (revision 1697)
+++ mln/labeling/flat_zones.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/image.hh>
-# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/window.hh>
# include <mln/canvas/labeling.hh>
@@ -44,21 +44,19 @@
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. */
+ // FIXME: Provide a neighborhood-aware version of these
+ // algorithms.
/*! 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] win The connexity of the flat zones.
* \param[out] nlabels The number of labels.
* \return The label image.
*/
- template <typename I, typename N, typename L>
+ template <typename I, typename W, 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 Window<W>& win, L&
nlabels);
@@ -69,7 +67,7 @@
// Flat zone functor for the labeling canvas.
- template <typename I_, typename N_, typename L_>
+ template <typename I_, typename W_, typename L_>
struct flat_zones_functor
{
typedef mln_psite(I_) P;
@@ -77,12 +75,12 @@
// requirements from mln::canvas::labeling:
typedef I_ I;
- typedef N_ N;
+ typedef W_ W;
typedef L_ L;
typedef mln_pset(I) S;
const I& input;
- const N& nbh;
+ const W& win;
const S& s;
bool handles(const P&) const { return true; }
@@ -97,9 +95,9 @@
// end of requirements
- flat_zones_functor(const I_& input, const N_& nbh)
+ flat_zones_functor(const I_& input, const W_& win)
: input(input),
- nbh(nbh),
+ win(win),
s(input.domain())
{}
};
@@ -110,14 +108,14 @@
namespace generic
{
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
- flat_zones_(const I& input, const N& nbh, L& nlabels)
+ flat_zones_(const I& input, const W& win, L& nlabels)
{
trace::entering("labeling::impl::generic::flat_zones_");
- typedef flat_zones_functor<I,N,L> F;
- F f(input, nbh);
+ typedef flat_zones_functor<I,W,L> F;
+ F f(input, win);
canvas::labeling<F> run(f);
nlabels = run.nlabels;
@@ -134,19 +132,19 @@
// Facade.
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
- flat_zones(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ flat_zones(const Image<I>& input_, const Window<W>& win_,
L& nlabels)
{
trace::entering("labeling::flat_zones");
const I& input = exact(input_);
- const N& nbh = exact(nbh_);
+ const W& win = exact(win_);
mln_precondition(input.has_data());
// Calls the only (generic) impl.
mln_ch_value(I, L) output =
- impl::generic::flat_zones_(input, nbh, nlabels);
+ impl::generic::flat_zones_(input, win, nlabels);
trace::exiting("labeling::flat_zones");
return output;
Index: mln/labeling/level.hh
--- mln/labeling/level.hh (revision 1697)
+++ mln/labeling/level.hh (working copy)
@@ -35,7 +35,7 @@
*/
# include <mln/core/concept/image.hh>
-# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/window.hh>
# include <mln/canvas/labeling.hh>
# include <mln/level/fill.hh>
@@ -50,6 +50,9 @@
namespace labeling
{
+ // FIXME: Provide a neighborhood-aware version of these
+ // algorithms.
+
/* 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
@@ -60,14 +63,14 @@
*
* \param[in] input The input image.
* \param[in] val The level to consider for the labeling.
- * \param[in] nbh The neighborhood.
+ * \param[in] win The connexity of the components.
* \param[out] nlabels The number of labels.
* \return The label image.
*/
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
level(const Image<I>& input, const mln_value(I)& val,
- const Neighborhood<N>& nbh, L& nlabels);
+ const Window<W>& win, L& nlabels);
# ifndef MLN_INCLUDE_ONLY
@@ -77,7 +80,7 @@
// Generic functor.
- template <typename I_, typename N_, typename L_>
+ template <typename I_, typename W_, typename L_>
struct level_functor
{
typedef mln_psite(I_) P;
@@ -85,12 +88,12 @@
// requirements from mln::canvas::labeling:
typedef I_ I;
- typedef N_ N;
+ typedef W_ W;
typedef L_ L;
typedef mln_pset(I) S;
const I& input;
- const N& nbh;
+ const W& win;
const S& s;
bool handles(const P& p) const { return input(p) == val; }
@@ -106,9 +109,9 @@
const mln_value(I_)& val;
- level_functor(const I_& input, const mln_value(I_)& val, const N_&
nbh)
+ level_functor(const I_& input, const mln_value(I_)& val, const W_&
win)
: input(input),
- nbh(nbh),
+ win(win),
s(input.domain()),
val(val)
{}
@@ -120,15 +123,15 @@
namespace generic
{
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
- level_(const I& input, const mln_value(I)& val, const N& nbh,
+ level_(const I& input, const mln_value(I)& val, const W& win,
L& nlabels)
{
trace::entering("labeling::impl::generic::level_");
- typedef level_functor<I,N,L> F;
- F f(input, val, nbh);
+ typedef level_functor<I,W,L> F;
+ F f(input, val, win);
canvas::labeling<F> run(f);
nlabels = run.nlabels;
@@ -147,17 +150,17 @@
// Facade.
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
level(const Image<I>& input, const mln_value(I)& val,
- const Neighborhood<N>& nbh, L& nlabels)
+ const Window<W>& win, 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)(),
- exact(input), val, exact(nbh), nlabels);
+ exact(input), val, exact(win), nlabels);
trace::exiting("labeling::level");
return output;
Index: mln/labeling/foreground.hh
--- mln/labeling/foreground.hh (revision 1697)
+++ mln/labeling/foreground.hh (working copy)
@@ -43,16 +43,14 @@
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. */
+ // FIXME: Provide a neighborhood-aware version of these
+ // algorithms.
/*! 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] win The connexity of the foreground.
* \param[out] nlabels The number of labels.
* \return The label image.
*
@@ -63,18 +61,18 @@
*
* \see mln::labeling::level
*/
- template <typename I, typename N>
+ template <typename I, typename W>
mln_ch_value(I, unsigned)
- foreground(const Image<I>& input, const Neighborhood<N>& nbh,
+ foreground(const Image<I>& input, const Window<W>& win,
unsigned& nlabels);
# ifndef MLN_INCLUDE_ONLY
- template <typename I, typename N>
+ template <typename I, typename W>
inline
mln_ch_value(I, unsigned)
- foreground(const Image<I>& input, const Neighborhood<N>& nbh,
+ foreground(const Image<I>& input, const Window<W>& win,
unsigned& nlabels)
{
trace::entering("labeling::foreground");
@@ -83,7 +81,7 @@
mln_precondition(exact(input).has_data());
mln_ch_value(I, unsigned) output =
- labeling::level(input, true, nbh, nlabels);
+ labeling::level(input, true, win, nlabels);
trace::exiting("labeling::foreground");
return output;
Index: mln/labeling/regional_minima.hh
--- mln/labeling/regional_minima.hh (revision 1697)
+++ mln/labeling/regional_minima.hh (working copy)
@@ -35,7 +35,7 @@
*/
# include <mln/core/concept/image.hh>
-# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/window.hh>
# include <mln/canvas/labeling.hh>
# include <mln/level/fill.hh>
# include <mln/level/sort_points.hh>
@@ -47,23 +47,21 @@
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. */
+ // FIXME: Provide a neighborhood-aware version of these
+ // algorithms.
/*! 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] win The connexity of the minima.
* \param[out] nlabels The number of labeled regions.
* \return The label image.
*
*/
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
- regional_minima(const Image<I>& input, const Neighborhood<N>& nbh,
+ regional_minima(const Image<I>& input, const Window<W>& win,
L& nlabels);
@@ -74,7 +72,7 @@
// Generic functor.
- template <typename I_, typename N_, typename L_>
+ template <typename I_, typename W_, typename L_>
struct regional_minima_functor
{
typedef mln_psite(I_) P;
@@ -82,12 +80,12 @@
// requirements from mln::canvas::labeling:
typedef I_ I;
- typedef N_ N;
+ typedef W_ W;
typedef L_ L;
typedef p_array<P> S;
const I& input;
- const N& nbh;
+ const W& win;
S s;
void init() { level::fill(attr,
true); }
@@ -106,9 +104,9 @@
mln_ch_value(I, bool) attr;
- regional_minima_functor(const I_& input, const N_& nbh)
+ regional_minima_functor(const I_& input, const W_& win)
: input(input),
- nbh(nbh),
+ win(win),
s(level::sort_points_increasing(input)), // FIXME:
//
sort_psites_increasing
attr(input.domain())
@@ -122,15 +120,15 @@
namespace generic
{
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
- regional_minima_(const I& input, const N& nbh,
+ regional_minima_(const I& input, const W& win,
L& nlabels)
{
trace::entering("labeling::impl::generic::regional_minima_");
- typedef impl::regional_minima_functor<I,N,L> F;
- F f(input, nbh);
+ typedef impl::regional_minima_functor<I,W,L> F;
+ F f(input, win);
canvas::labeling<F> run(f);
nlabels = run.nlabels;
@@ -147,19 +145,19 @@
// Facade.
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
- regional_minima(const Image<I>& input_, const Neighborhood<N>&
nbh_,
+ regional_minima(const Image<I>& input_, const Window<W>& win_,
L& nlabels)
{
trace::entering("labeling::regional_minima");
const I& input = exact(input_);
- const N& nbh = exact(nbh_);
+ const W& win = exact(win_);
mln_precondition(input.has_data());
// Calls the only (generic) impl.
mln_ch_value(I, L) output =
- impl::generic::regional_minima_(input, nbh, nlabels);
+ impl::generic::regional_minima_(input, win, nlabels);
trace::exiting("labeling::regional_minima");
return output;
Index: mln/labeling/regional_maxima.hh
--- mln/labeling/regional_maxima.hh (revision 1697)
+++ mln/labeling/regional_maxima.hh (working copy)
@@ -35,7 +35,7 @@
*/
# include <mln/core/concept/image.hh>
-# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/window.hh>
# include <mln/canvas/labeling.hh>
# include <mln/level/fill.hh>
# include <mln/level/sort_points.hh>
@@ -47,23 +47,21 @@
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. */
+ // FIXME: Provide a neighborhood-aware version of these
+ // algorithms.
/*! 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 maxima.
* \param[out] nlabels The number of labeled regions.
* \return The label image.
*
*/
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
- regional_maxima(const Image<I>& input, const Neighborhood<N>&
nbh,
+ regional_maxima(const Image<I>& input, const Window<W>& win,
L& nlabels);
@@ -75,7 +73,7 @@
// Generic functor.
- template <typename I_, typename N_, typename L_>
+ template <typename I_, typename W_, typename L_>
struct regional_maxima_functor
{
typedef mln_psite(I_) P;
@@ -83,12 +81,12 @@
// requirements from mln::canvas::labeling:
typedef I_ I;
- typedef N_ N;
+ typedef W_ W;
typedef L_ L;
typedef p_array<P> S;
const I& input;
- const N& nbh;
+ const W& win;
S s;
void init() { level::fill(attr,
true); }
@@ -107,9 +105,9 @@
mln_ch_value(I, bool) attr;
- regional_maxima_functor(const I_& input, const N_& nbh)
+ regional_maxima_functor(const I_& input, const W_& win)
: input(input),
- nbh(nbh),
+ win(win),
s(level::sort_points_decreasing(input)), // FIXME:
//
sort_psites_decreasing
attr(input.domain())
@@ -123,15 +121,15 @@
namespace generic
{
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
- regional_maxima_(const I& input, const N& nbh,
+ regional_maxima_(const I& input, const W& win,
L& nlabels)
{
trace::entering("labeling::impl::generic::regional_maxima_");
- typedef impl::regional_maxima_functor<I,N,L> F;
- F f(input, nbh);
+ typedef impl::regional_maxima_functor<I,W,L> F;
+ F f(input, win);
canvas::labeling<F> run(f);
nlabels = run.nlabels;
@@ -148,19 +146,19 @@
// Facade.
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
- regional_maxima(const Image<I>& input_, const Neighborhood<N>&
nbh_,
+ regional_maxima(const Image<I>& input_, const Window<W>& win_,
L& nlabels)
{
trace::entering("labeling::regional_maxima");
const I& input = exact(input_);
- const N& nbh = exact(nbh_);
+ const W& win = exact(win_);
mln_precondition(input.has_data());
// Calls the only (generic) impl.
mln_ch_value(I, L) output =
- impl::generic::regional_maxima_(input, nbh, nlabels);
+ impl::generic::regional_maxima_(input, win, nlabels);
trace::exiting("labeling::regional_maxima");
return output;
Index: mln/labeling/level.spe.hh
--- mln/labeling/level.spe.hh (revision 1697)
+++ mln/labeling/level.spe.hh (working copy)
@@ -59,14 +59,14 @@
*
* \param[in] input The input image.
* \param[in] val The level to consider for the labeling.
- * \param[in] nbh The neighborhood.
+ * \param[in] win The connexity of the components.
* \param[out] nlabels The number of labels.
* \return The label image.
*/
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
level(const Image<I>& input, const mln_value(I)& val,
- const Neighborhood<N>& nbh, L& nlabels);
+ const Window<W>& win, L& nlabels);
# ifndef MLN_INCLUDE_ONLY
@@ -79,9 +79,9 @@
namespace generic
{
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
- level_(const I& input, const mln_value(I)& val, const N& nbh,
+ level_(const I& input, const mln_value(I)& val, const W& win,
L& nlabels);
} // end of namespace mln::labeling::impl::generic
@@ -90,18 +90,18 @@
// Fastest functor.
- template <typename I_, typename N_, typename L_>
+ template <typename I_, typename W_, typename L_>
struct level_fastest_functor
{
// requirements from mln::canvas::labeling:
typedef I_ I;
- typedef N_ N;
+ typedef W_ W;
typedef L_ L;
typedef mln_pset(I) S;
const I& input;
- const N& nbh;
+ const W& win;
const S& s;
bool handles(unsigned p) const { return input[p] == val; }
@@ -118,9 +118,9 @@
const mln_value(I_)& val;
level_fastest_functor(const I_& input, const mln_value(I_)& val,
- const N_& nbh)
+ const W_& win)
: input(input),
- nbh(nbh),
+ win(win),
s(input.domain()),
val(val)
{}
@@ -129,18 +129,18 @@
// Fastest routine.
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
- level_fastest_(const I& input, const mln_value(I)& val, const N& nbh,
+ level_fastest_(const I& input, const mln_value(I)& val, const W& win,
L& nlabels)
{
trace::entering("labeling::impl::level_fastest_");
- border::adjust(input, nbh.delta());
+ border::adjust(input, win.delta());
border::fill(input, value::other(val));
- typedef level_fastest_functor<I,N,L> F;
- F f(input, val, nbh);
+ typedef level_fastest_functor<I,W,L> F;
+ F f(input, val, win);
canvas::labeling_fastest<F> run(f);
nlabels = run.nlabels;
@@ -153,22 +153,22 @@
// Disjunction between "fastest" and "not fastest".
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
level_(trait::image::speed::any,
- const I& input, const mln_value(I)& val, const N& nbh,
+ const I& input, const mln_value(I)& val, const W& win,
L& nlabels)
{
- return generic::level_(input, val, nbh, nlabels);
+ return generic::level_(input, val, win, nlabels);
}
- template <typename I, typename N, typename L>
+ template <typename I, typename W, typename L>
mln_ch_value(I, L)
level_(trait::image::speed::fastest,
- const I& input, const mln_value(I)& val, const N& nbh,
+ const I& input, const mln_value(I)& val, const W& win,
L& nlabels)
{
- return level_fastest_(input, val, nbh, nlabels);
+ return level_fastest_(input, val, win, nlabels);
}
Index: mln/labeling/background.hh
--- mln/labeling/background.hh (revision 1697)
+++ mln/labeling/background.hh (working copy)
@@ -43,16 +43,14 @@
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. */
+ // FIXME: Provide a neighborhood-aware version of these
+ // algorithms.
/*! 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] win The connexity of the background.
* \param[out] nlabels The number of labels.
* \return The label image.
*
@@ -63,18 +61,18 @@
*
* \see mln::labeling::level
*/
- template <typename I, typename N>
+ template <typename I, typename W>
mln_ch_value(I, unsigned)
- background(const Image<I>& input, const Neighborhood<N>& nbh,
+ background(const Image<I>& input, const Window<W>& win,
unsigned& nlabels);
# ifndef MLN_INCLUDE_ONLY
- template <typename I, typename N>
+ template <typename I, typename W>
inline
mln_ch_value(I, unsigned)
- background(const Image<I>& input, const Neighborhood<N>& nbh,
+ background(const Image<I>& input, const Window<W>& win,
unsigned& nlabels)
{
trace::entering("labeling::background");
@@ -83,7 +81,7 @@
mln_precondition(exact(input).has_data());
mln_ch_value(I, unsigned) output =
- labeling::level(input, false, nbh, nlabels);
+ labeling::level(input, false, win, nlabels);
trace::exiting("labeling::background");
return output;
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
More tests on Meyer's WST.
* tests/morpho/meyer_wst_long.cc: New test.
* tests/morpho/Makefile.am (check_PROGRAMS): Add meyer_wst and
meyer_wst_long.
(meyer_wst_SOURCES)
(meyer_wst_long_SOURCES, meyer_wst_long_CXXFLAGS):
New.
Makefile.am | 21 ++++++++++++++++-----
meyer_wst.cc | 1 -
meyer_wst_long.cc | 29 +++++++++++++++++++++++------
3 files changed, 39 insertions(+), 12 deletions(-)
Index: tests/morpho/meyer_wst.cc
--- tests/morpho/meyer_wst.cc (revision 1696)
+++ tests/morpho/meyer_wst.cc (working copy)
@@ -55,7 +55,6 @@
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 =
Index: tests/morpho/meyer_wst_long.cc
--- tests/morpho/meyer_wst_long.cc (revision 1695)
+++ tests/morpho/meyer_wst_long.cc (working copy)
@@ -30,18 +30,26 @@
#include <iostream>
+#include <mln/core/image_if.hh>
#include <mln/core/image2d.hh>
#include <mln/core/window2d.hh>
#include <mln/core/neighb2d.hh>
#include <mln/convert/to_window.hh>
+#include <mln/level/stretch.hh>
#include <mln/value/int_u8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/morpho/closing_area.hh>
#include <mln/morpho/meyer_wst.hh>
+#include <mln/pw/cst.hh>
+#include <mln/pw/value.hh>
+
+#include <mln/display/color_pretty.hh>
#include <mln/io/pgm/load.hh>
-#include <mln/io/pgm/save.hh>
+#include <mln/io/ppm/save.hh>
#include "tests/data.hh"
@@ -50,16 +58,25 @@
{
using namespace mln;
using value::int_u8;
+ using value::int_u16;
image2d<int_u8> input;
- io::pgm::load(input, MLN_IMG_DIR "/squares.pgm");
+ io::pgm::load(input, MLN_IMG_DIR "/lena.pgm");
- typedef int_u8 output_val;
+ // Simplify the input image.
+ image2d<int_u8> work(input.domain());
+ morpho::closing_area(input, c4(), 200, work);
+ // Perform a Watershed Transform.
+ typedef int_u16 wst_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);
+ image2d<wst_val> ws =
+ morpho::meyer_wst<wst_val>(work, convert::to_window(c4()), nbasins);
std::cout << "nbasins = " << nbasins << std::endl;
- io::pgm::save(output, "out.pgm");
+
+ // Save the image in color.
+ image2d<value::rgb8> input_plus_ws =
+ display::color_pretty(input | (pw::value(ws) != pw::cst(0)));
+ io::ppm::save(input_plus_ws, "out.ppm");
}
Index: tests/morpho/Makefile.am
--- tests/morpho/Makefile.am (revision 1696)
+++ tests/morpho/Makefile.am (working copy)
@@ -14,21 +14,32 @@
hit_or_miss \
laplacian \
level_components \
+ meyer_wst \
+ meyer_wst_long \
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
erosion_SOURCES = erosion.cc
+
+dilation_max_h_SOURCES = dilation_max_h.cc
erosion_min_h_SOURCES = erosion_min_h.cc
+
+opening_area_SOURCES = opening_area.cc
+closing_area_SOURCES = closing_area.cc
+
+level_components_SOURCES = level_components.cc
extrema_components_SOURCES = extrema_components.cc
+
+contrast_SOURCES = contrast.cc
gradient_SOURCES = gradient.cc
hit_or_miss_SOURCES = hit_or_miss.cc
laplacian_SOURCES = laplacian.cc
-level_components_SOURCES = level_components.cc
-opening_area_SOURCES = opening_area.cc
thinning_SOURCES = thinning.cc
+meyer_wst_SOURCES = meyer_wst.cc
+# FIXME: We should isolate this test, as it takes a long time.
+meyer_wst_long_SOURCES = meyer_wst_long.cc
+meyer_wst_long_CXXFLAGS = -O3
+
TESTS = $(check_PROGRAMS)
1
0
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
1
0
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");
+}
1
0
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
1
0