URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-05 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add fast-gaussian
* sandbox/nivault/fast_gaussian.hh: New.
* sandbox/nivault/tests/test.cc: New.
* sandbox/nivault/tests/test: New.
* sandbox/nivault/tests: New.
fast_gaussian.hh | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/test | 4
tests/test.cc | 42 ++++++++
3 files changed, 334 insertions(+)
Index: trunk/milena/sandbox/nivault/tests/test
===================================================================
--- trunk/milena/sandbox/nivault/tests/test (revision 0)
+++ trunk/milena/sandbox/nivault/tests/test (revision 1069)
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+g++ -I../../.. -I../.. -I.. test.cc -O1
+./a.out
Property changes on: trunk/milena/sandbox/nivault/tests/test
___________________________________________________________________
Name: svn:executable
+ *
Index: trunk/milena/sandbox/nivault/tests/test.cc
===================================================================
--- trunk/milena/sandbox/nivault/tests/test.cc (revision 0)
+++ trunk/milena/sandbox/nivault/tests/test.cc (revision 1069)
@@ -0,0 +1,42 @@
+// Copyright (C) 2007 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.
+
+#include <mln/core/image2d_b.hh>
+#include <mln/io/load_pgm.hh>
+#include <mln/io/save_pgm.hh>
+
+#include <fast_gaussian.hh>
+
+int main()
+{
+ mln::image2d_b<mln::value::int_u<8u> > im1 = mln::io::load_pgm("../../../img/lena.pgm");
+ mln::image2d_b<float> im2;
+
+ mln::linear::gaussian(im1, 0.2, im2);
+
+ // mln::io::save_pgm(im2, "gausslena.pgm");
+ }
Index: trunk/milena/sandbox/nivault/fast_gaussian.hh
===================================================================
--- trunk/milena/sandbox/nivault/fast_gaussian.hh (revision 0)
+++ trunk/milena/sandbox/nivault/fast_gaussian.hh (revision 1069)
@@ -0,0 +1,288 @@
+// Copyright (C) 2001, 2002, 2003, 2004 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, Inc., 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, 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 OLENA_CONVOL_FAST_GAUSSIAN_FILTER_HH__
+# define OLENA_CONVOL_FAST_GAUSSIAN_FILTER_HH__
+
+#include <mln/core/concept/image.hh>
+#include <mln/level/paste.hh>
+#include <mln/geom/ncols.hh>
+
+
+namespace mln
+{
+
+ namespace linear
+ {
+
+
+ struct recursivefilter_coef_
+ {
+
+ /*!
+ ** \brief Constructor.
+ */
+ recursivefilter_coef_(float a0, float a1,
+ float b0, float b1,
+ float c0, float c1,
+ float w0, float w1,
+ float s);
+ std::vector<float> n, d, nm, dm;
+ float sumA, sumC;
+ };
+
+ recursivefilter_coef_::recursivefilter_coef_(float a0, float a1,
+ float b0, float b1,
+ float c0, float c1,
+ float w0, float w1,
+ float s)
+ {
+ n.reserve(5);
+ d.reserve(5);
+ nm.reserve(5);
+ dm.reserve(5);
+
+ b0 /= s;
+ b1 /= s;
+ w0 /= s;
+ w1 /= s;
+
+ float sin0 = sin(w0);
+ float sin1 = sin(w1);
+ float cos0 = cos(w0);
+ float cos1 = cos(w1);
+
+ sumA =
+ (2.0 * a1 * exp( b0 ) * cos0 * cos0 - a0 * sin0 * exp( 2.0 * b0 )
+ + a0 * sin0 - 2.0 * a1 * exp( b0 )) /
+ (( 2.0 * cos0 * exp( b0 ) - exp( 2.0 * b0 ) - 1 ) * sin0);
+
+ sumC =
+ (2.0 * c1 * exp( b1 ) * cos1 * cos1 - c0 * sin1 * exp( 2.0 * b1 )
+ + c0 * sin1 - 2.0 * c1 * exp( b1 ))
+ / (( 2.0 * cos1 * exp( b1 ) - exp( 2.0 * b1 ) - 1 ) * sin1);
+
+ a0 /= (sumA + sumC);
+ a1 /= (sumA + sumC);
+ c0 /= (sumA + sumC);
+ c1 /= (sumA + sumC);
+
+ n[3] =
+ exp( -b1 - 2*b0 ) * (c1 * sin1 - cos1 * c0) +
+ exp( -b0 - 2*b1 ) * (a1 * sin0 - cos0 * a0);
+ n[2] =
+ 2 * exp(-b0 - b1) * ((a0 + c0) * cos1 * cos0 -
+ cos1 * a1 * sin0 -
+ cos0 * c1 * sin1) +
+ c0 * exp(-2 * b0) + a0 * exp(-2 * b1);
+ n[1] =
+ exp(-b1) * (c1 * sin1 - (c0 + 2*a0) * cos1) +
+ exp(-b0) * (a1 * sin0 - (2*c0 + a0) * cos0);
+ n[0] =
+ a0 + c0;
+
+ d[4] = exp(-2 * b0 - 2 * b1);
+ d[3] =
+ -2 * cos0 * exp(-b0 - 2*b1) -
+ 2 * cos1 * exp(-b1 - 2*b0);
+ d[2] =
+ 4 * cos1 * cos0 * exp(-b0 - b1) +
+ exp(-2*b1) + exp(-2*b0);
+ d[1] =
+ -2*exp(-b1) * cos1 - 2 * exp(-b0) * cos0;
+
+ for (unsigned i = 1; i <= 3; ++i)
+ {
+ dm[i] = d[i];
+ nm[i] = n[i] - d[i] * n[0];
+ }
+ dm[4] = d[4];
+ nm[4] = -d[4] * n[0];
+ }
+
+
+
+ template <class WorkType, class I>
+ void
+ recursivefilter_(I& ima,
+ const recursivefilter_coef_& c,
+ const mln_point(I)& start,
+ const mln_point(I)& finish,
+ int len,
+ const mln_dpoint(I)& d)
+ {
+ std::vector<WorkType> tmp1(len);
+ std::vector<WorkType> tmp2(len);
+
+ // The fourth degree approximation implies to have a special
+ // look on the four first points we consider that there is
+ // no signal before 0 (to be discussed)
+
+ // --
+ // Causal part
+
+ tmp1[0] =
+ c.n[0]*ima(start);
+
+ tmp1[1] =
+ c.n[0]*ima(start + d)
+ + c.n[1]*ima(start)
+ - c.d[1]*tmp1[0];
+
+ tmp1[2] =
+ c.n[0]*ima(start + d + d)
+ + c.n[1]*ima(start + d)
+ + c.n[2]*ima(start)
+ - c.d[1]*tmp1[1]
+ - c.d[2]*tmp1[0];
+
+ tmp1[3] =
+ c.n[0]*ima(start + d + d + d)
+ + c.n[1]*ima(start + d + d)
+ + c.n[2]*ima(start + d)
+ + c.n[3]*ima(start)
+ - c.d[1]*tmp1[2] - c.d[2]*tmp1[1]
+ - c.d[3]*tmp1[0];
+
+ mln_point(I) current(start + d + d + d + d);
+ for (mln_coord(I) i = 4; i < len; ++i)
+ {
+ tmp1[i] =
+ c.n[0]*ima(current)
+ + c.n[1]*ima(current - d)
+ + c.n[2]*ima(current - d - d)
+ + c.n[3]*ima(current - d - d - d)
+ - c.d[1]*tmp1[i - 1] - c.d[2]*tmp1[i - 2]
+ - c.d[3]*tmp1[i - 3] - c.d[4]*tmp1[i - 4];
+ current += d;
+ }
+
+ // Non causal part
+
+ tmp2[len - 1] = 0;
+
+ tmp2[len - 2] =
+ c.nm[1]*ima(finish);
+
+ tmp2[len - 3] =
+ c.nm[1]*ima(finish - d)
+ + c.nm[2]*ima(finish)
+ - c.dm[1]*tmp2[len-2];
+
+ tmp2[len - 4] =
+ c.nm[1]*ima(finish - d - d)
+ + c.nm[2]*ima(finish - d)
+ + c.nm[3]*ima(finish)
+ - c.dm[1]*tmp2[len-3]
+ - c.dm[2]*tmp2[len-2];
+
+ current = finish - d - d - d ;
+
+ for (int i = len - 5; i >= 0; --i)
+ {
+ tmp2[i] =
+ c.nm[1]*ima(current)
+ + c.nm[2]*ima(current + d)
+ + c.nm[3]*ima(current + d + d)
+ + c.nm[4]*ima(current + d + d + d)
+ - c.dm[1]*tmp2[i+1] - c.dm[2]*tmp2[i+2]
+ - c.dm[3]*tmp2[i+3] - c.dm[4]*tmp2[i+4];
+ current -= d;
+ }
+
+ // Combine results from causal and non-causal parts.
+
+ current = start;
+ for (int i = 0; i < len; ++i)
+ {
+ ima(current) = tmp1[i] + tmp2[i];
+ current += d;
+ }
+ }
+
+
+ template <class I, class F>
+ void
+ gaussian_(Image<I>& img_, const F& coef)
+ {
+ I& img = exact(img_);
+ typedef mln_point(I) P;
+ // Apply on columns.
+
+ recursivefilter_<float>(img, coef,
+ make::point2d(0, - img.border()), // FIXME
+ make::point2d(0, geom::ncols(img) - 1 + img.border()),
+ geom::ncols(img) + 2 * img.border(),
+ make::dpoint2d(0, 1));
+ }
+
+
+ template <class I, class F, class O>
+ void
+ gaussian_common_(const Image<I>& in,
+ const F& coef,
+ float sigma,
+ Image<O>& out)
+ {
+ mln_ch_value(O, float) work_img(exact(in).domain());
+ level::paste(in, work_img);
+
+ // On tiny sigma, Derich algorithm doesn't work.
+ // It is the same thing that to convolve with a Dirac.
+ if (sigma > 0.006)
+ gaussian_(work_img, coef);
+ /* Convert the result image to the user-requested datatype.
+ FIXME: We are making an unnecessary copy in case the
+ user expects a ntg::float_s image. */
+ level::paste(work_img, out);
+ }
+
+
+
+
+ template <class I, class O>
+ void
+ gaussian(const Image<I>& in, float sigma,
+ Image<O>& out)
+ {
+ recursivefilter_coef_
+ coef(1.68f, 3.735f,
+ 1.783f, 1.723f,
+ -0.6803f, -0.2598f,
+ 0.6318f, 1.997f,
+ sigma);
+
+ gaussian_common_(in, coef, sigma, out);
+ }
+
+ }
+
+}
+
+
+
+#endif // OLENA_CONVOL_FAST_GAUSSIAN_FILTER_HH__
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add labeling routines.
* tests/sort_points.cc: Rename as...
* tests/level_sort_points.cc: ...this.
Augment.
* tests/labeling.cc: Rename as...
* tests/labeling_foreground.cc: ...this.
Update.
* tests/labeling_regional_maxima.cc: New.
* mln/convert/to_vec_p.hh: New.
* mln/pw/image.hh (change_value): Use fixme.
* mln/core/vec_p.hh (reserve, hook_): New.
* mln/core/vec_p_piter.hh (vec_p_bkd_piter_): Code.
* mln/level/sort_points.hh (sort_points): Rename as...
(sort_points_increasing): ...this.
(sort_points_decreasing): New.
* mln/level/fill.hh: Add & to the C function arg; that fixes
the behavior of icpc when calling fill with the literal 0.
* mln/level/labeling.hh: Remove; obsolete because of
labeling::level.
* mln/linear/sobel.hh: Add FIXME.
* mln/canvas/labeling.hh: New.
* mln/labeling/flat_zones.hh: New.
* mln/labeling/+foreground.hh: Remove.
* mln/labeling/level.hh: New.
* mln/labeling/foreground.hh: New.
* mln/labeling/regional_minima.hh: New.
* mln/labeling/base.hh: New.
* mln/labeling/regional_maxima.hh: New.
* mln/labeling/background.hh: New.
mln/canvas/labeling.hh | 157 ++++++++++++++++++++++++++++++++++++++
mln/convert/to_vec_p.hh | 71 +++++++++++++++++
mln/core/vec_p.hh | 20 ++++
mln/core/vec_p_piter.hh | 121 ++++++++++++++++++++++++++++-
mln/labeling/background.hh | 79 +++++++++++++++++++
mln/labeling/base.hh | 94 ++++++++++++++++++++++
mln/labeling/flat_zones.hh | 111 ++++++++++++++++++++++++++
mln/labeling/foreground.hh | 79 +++++++++++++++++++
mln/labeling/level.hh | 118 ++++++++++++++++++++++++++++
mln/labeling/regional_maxima.hh | 120 +++++++++++++++++++++++++++++
mln/labeling/regional_minima.hh | 120 +++++++++++++++++++++++++++++
mln/level/fill.hh | 5 -
mln/level/sort_points.hh | 110 ++++++++++++++++++++------
mln/linear/sobel.hh | 2
mln/pw/image.hh | 2
tests/labeling_foreground.cc | 45 ++--------
tests/labeling_regional_maxima.cc | 57 +++++++++++++
tests/level_sort_points.cc | 15 ++-
18 files changed, 1254 insertions(+), 72 deletions(-)
Index: tests/level_sort_points.cc
--- tests/level_sort_points.cc (revision 1067)
+++ tests/level_sort_points.cc (working copy)
@@ -47,10 +47,13 @@
image2d_b<int_u8> ima(3, 3);
debug::iota(ima);
- std::vector<point2d> vec = level::sort_points(ima);
-
- std::copy(vec.begin(), vec.end(),
- std::ostream_iterator<point2d>(std::cout, " "));
- std::cout << std::endl;
-
+ vec_p<point2d> vec;
+ {
+ vec = level::sort_points_increasing(ima);
+ std::cout << vec << std::endl;
+ }
+ {
+ vec = level::sort_points_decreasing(ima);
+ std::cout << vec << std::endl;
+ }
}
Index: tests/labeling_foreground.cc
--- tests/labeling_foreground.cc (revision 1067)
+++ tests/labeling_foreground.cc (working copy)
@@ -25,54 +25,33 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/labeling.cc
+/*! \file tests/labeling_foreground.cc
*
- * \brief Tests on mln::level::labeling.
+ * \brief Test on mln::labeling::foreground.
*/
#include <mln/core/image2d_b.hh>
#include <mln/core/neighb2d.hh>
-
#include <mln/value/int_u8.hh>
-#include <mln/value/label.hh>
-
-#include <mln/pw/value.hh>
-#include <mln/pw/cst.hh>
-#include <mln/fun/ops.hh>
+#include <mln/pw/all.hh>
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-
-#include <mln/level/fill.hh>
-#include <mln/level/labeling.hh>
-#include <mln/level/to_enc.hh>
-
+#include <mln/labeling/foreground.hh>
int main()
{
using namespace mln;
using value::int_u8;
- using value::label;
- image2d_b<int_u8> lena = io::load_pgm("../img/lena.pgm");
-
- image2d_b<bool> bin(lena.domain());
- level::fill(bin, pw::value(lena) > pw::cst(127));
-
- {
- image2d_b<int_u8> lab(lena.domain());
- level::labeling(bin, c4(), lab);
- io::save_pgm(lab, "lab.pgm");
- }
-
- {
- image2d_b< label<8> > lab(lena.domain());
- level::labeling(bin, c4(), lab);
-
- image2d_b< int_u8 > out(lena.domain());
- level::to_enc(lab, out);
+ image2d_b<int_u8>
+ lena = io::load_pgm("../img/tiny.pgm"),
+ out(lena.domain());
+
+ unsigned n;
+ labeling::foreground((pw::value(lena) > pw::cst(127)) | lena.domain(),
+ c4(), out, n);
io::save_pgm(out, "out.pgm");
- }
-
+ mln_assertion(n = 14);
}
Index: tests/labeling_regional_maxima.cc
--- tests/labeling_regional_maxima.cc (revision 0)
+++ tests/labeling_regional_maxima.cc (revision 0)
@@ -0,0 +1,57 @@
+// Copyright (C) 2007 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/labeling_regional_maxima.cc
+ *
+ * \brief Test on mln::labeling::regional_maxima.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/io/load_pgm.hh>
+#include <mln/io/save_pgm.hh>
+
+#include <mln/labeling/regional_maxima.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d_b<int_u8>
+ lena = io::load_pgm("../img/lena.pgm"),
+ out(lena.domain());
+
+ unsigned n;
+ labeling::regional_maxima(lena, c4(), out, n);
+ mln_assertion(n = 255);
+
+ io::save_pgm(out, "out.pgm");
+}
Index: mln/convert/to_vec_p.hh
--- mln/convert/to_vec_p.hh (revision 0)
+++ mln/convert/to_vec_p.hh (revision 0)
@@ -0,0 +1,71 @@
+// Copyright (C) 2007 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_CONVERT_TO_VEC_P_HH
+# define MLN_CONVERT_TO_VEC_P_HH
+
+/*! \file mln/convert/to_vec_p.hh
+ *
+ * \brief Conversions to mln::vec_p.
+ */
+
+# include <mln/core/vec_p.hh>
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// Convert a point set \p pset into a vec_p (point set vector).
+ template <typename S>
+ vec_p<mln_point(S)> to_vec_p(const Point_Set<S>& pset);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S>
+ vec_p<mln_point(S)> to_vec_p(const Point_Set<S>& pset_)
+ {
+ const S& pset = exact(pset_);
+ vec_p<mln_point(S)> v;
+ v.reserve(pset.npoints());
+ mln_fwd_piter(S) p(pset);
+ for_all(p)
+ v.append(p);
+ return v;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_VEC_P_HH
Index: mln/pw/image.hh
--- mln/pw/image.hh (revision 1067)
+++ mln/pw/image.hh (working copy)
@@ -109,7 +109,7 @@
template <typename U>
struct change_value
{
- typedef void ret;
+ typedef internal::fixme ret;
};
protected:
Index: mln/core/vec_p.hh
--- mln/core/vec_p.hh (revision 1067)
+++ mln/core/vec_p.hh (working copy)
@@ -79,6 +79,9 @@
/// Constructor from a vector \p vect.
vec_p(const std::vector<P>& vect);
+ /// Reserve \p n cells.
+ void reserve(std::size_t n);
+
/// Test is \p p belongs to this point set.
bool has(const P& p) const;
@@ -100,6 +103,9 @@
/// Return the \p i-th point.
const P& operator[](unsigned i) const;
+ /// Hook to data.
+ std::vector<P>& hook_();
+
protected:
std::vector<P> vect_;
@@ -129,6 +135,20 @@
template <typename P>
void
+ vec_p<P>::reserve(std::size_t n)
+ {
+ vect_.reserve(n);
+ }
+
+ template <typename P>
+ std::vector<P>&
+ vec_p<P>::hook_()
+ {
+ return vect_;
+ }
+
+ template <typename P>
+ void
vec_p<P>::update_bb_() const
{
bb_.init();
Index: mln/core/vec_p_piter.hh
--- mln/core/vec_p_piter.hh (revision 1067)
+++ mln/core/vec_p_piter.hh (working copy)
@@ -92,15 +92,63 @@
- // FIXME:
+ /*! \brief Backward iterator on points of a vec_p<P>.
+ *
+ */
template <typename P>
- struct vec_p_bkd_piter_ : internal::fixme
- {};
+ struct vec_p_bkd_piter_ : public Point_Iterator< vec_p_bkd_piter_<P> >
+ {
+ enum { dim = P::dim };
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Point associated type.
+ typedef P point;
+
+ /// Dpoint associated type.
+ typedef mln_dpoint(P) dpoint;
+
+ /// Coordinate associated type.
+ typedef mln_coord(P) coord;
+
+ /// Coordinate associated type.
+ template <typename S>
+ vec_p_bkd_piter_(const Point_Set<S>& s);
+
+ /// Give a hook to the point address.
+ const P* pointer_() const;
+
+ /// Read-only access to the \p i-th coordinate.
+ coord operator[](unsigned i) const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Convert the iterator into a point.
+ operator P() const;
+
+ protected:
+ const std::vector<P>& vect_;
+ int i_;
+ P p_;
+ };
# ifndef MLN_INCLUDE_ONLY
+ // vec_p_fwd_piter_<P>
+
template <typename P>
template <typename S>
vec_p_fwd_piter_<P>::vec_p_fwd_piter_(const Point_Set<S>& s)
@@ -153,6 +201,7 @@
vec_p_fwd_piter_<P>::next_()
{
++i_;
+ if (is_valid())
p_ = vect_[i_];
}
@@ -163,6 +212,72 @@
return p_;
}
+
+ // vec_p_bkd_piter_<P>
+
+ template <typename P>
+ template <typename S>
+ vec_p_bkd_piter_<P>::vec_p_bkd_piter_(const Point_Set<S>& s)
+ : vect_(exact(s).vect())
+ {
+ invalidate();
+ }
+
+ template <typename P>
+ const P*
+ vec_p_bkd_piter_<P>::pointer_() const
+ {
+ return & p_;
+ }
+
+ template <typename P>
+ mln_coord(P)
+ vec_p_bkd_piter_<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < dim);
+ mln_precondition(is_valid());
+ return p_[i];
+ }
+
+ template <typename P>
+ bool
+ vec_p_bkd_piter_<P>::is_valid() const
+ {
+ return i_ >= 0;
+ }
+
+ template <typename P>
+ void
+ vec_p_bkd_piter_<P>::invalidate()
+ {
+ i_ = -1;
+ }
+
+ template <typename P>
+ void
+ vec_p_bkd_piter_<P>::start()
+ {
+ i_ = vect_.size() - 1;
+ if (is_valid())
+ p_ = vect_[i_];
+ }
+
+ template <typename P>
+ void
+ vec_p_bkd_piter_<P>::next_()
+ {
+ --i_;
+ if (is_valid())
+ p_ = vect_[i_];
+ }
+
+ template <typename P>
+ vec_p_bkd_piter_<P>::operator P() const
+ {
+ mln_precondition(is_valid());
+ return p_;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/level/sort_points.hh
--- mln/level/sort_points.hh (revision 1067)
+++ mln/level/sort_points.hh (working copy)
@@ -31,13 +31,14 @@
/*! \file mln/level/sort_points.hh
*
* \brief Sort_Points the contents of an image into another one.
+ *
+ * \todo Factor code + optimize.
*/
-# include <vector>
-# include <utility>
# include <algorithm>
# include <mln/core/concept/image.hh>
+# include <mln/convert/to_vec_p.hh>
# include <mln/histo/compute.hh>
@@ -55,7 +56,7 @@
* \pre \p input.has_data
*/
template <typename I>
- std::vector<mln_point(I)> sort_points(const Image<I>& input);
+ vec_p<mln_point(I)> sort_points_increasing(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
@@ -63,6 +64,8 @@
namespace impl
{
+ // utility
+
template <typename I>
struct value_point_less_
{
@@ -82,31 +85,40 @@
};
template <typename I>
- std::vector<mln_point(I)>
- sort_points(metal::false_, // general case
- const Image<I>& input_)
+ struct value_point_greater_
{
- const I& input = exact(input_);
+ const I& ima_;
- std::vector<mln_point(I)> vec;
- vec.reserve(input.npoints());
+ value_point_greater_(const I& ima)
+ : ima_(ima)
+ {
+ }
- mln_fwd_piter(I) p(input.domain());
- for_all(p)
- vec.push_back(p);
+ bool operator()(const mln_point(I)& lhs,
+ const mln_point(I)& rhs) const
+ {
+ return ima_(lhs) > ima_(rhs) || (ima_(lhs) = ima_(rhs)
+ && lhs > rhs);
+ }
+ };
- std::sort(vec.begin(), vec.end(),
+
+ // increasing
+
+ template <typename I>
+ vec_p<mln_point(I)>
+ sort_points_increasing_(metal::false_, const I& input) // general case
+ {
+ vec_p<mln_point(I)> v = convert::to_vec_p(input.domain());
+ std::sort(v.hook_().begin(), v.hook_().end(),
value_point_less_<I>(input));
- return vec;
+ return v;
}
template <typename I>
- std::vector<mln_point(I)>
- sort_points(metal::true_, // low quantization
- const Image<I>& input_)
+ vec_p<mln_point(I)>
+ sort_points_increasing_(metal::true_, const I& input) // low quantization
{
- const I& input = exact(input_);
-
typedef mln_vset(I) S;
const S& vset = input.values();
const unsigned n = vset.nvalues();
@@ -120,12 +132,46 @@
for (unsigned i = 1; i != n; ++i)
loc[i] = loc[i-1] + h[i-1];
- /*
- MEMO. Decreasing case is:
+ // computing output data
+ std::vector<mln_point(I)> vec(input.npoints());
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ vec[loc[vset.index_of(input(p))]++] = p;
+
+ vec_p<mln_point(I)> v;
+ v.hook_() = vec;
+ return v;
+ }
+
+
+ // decreasing
+
+ template <typename I>
+ vec_p<mln_point(I)>
+ sort_points_decreasing_(metal::false_, const I& input) // general case
+ {
+ vec_p<mln_point(I)> v = convert::to_vec_p(input.domain());
+ std::sort(v.hook_().begin(), v.hook_().end(),
+ value_point_greater_<I>(input));
+ return v;
+ }
+
+ template <typename I>
+ vec_p<mln_point(I)>
+ sort_points_decreasing_(metal::true_, const I& input) // low quantization
+ {
+ typedef mln_vset(I) S;
+ const S& vset = input.values();
+ const unsigned n = vset.nvalues();
+
+ // h
+ histo::data<S> h = histo::compute(input);
+
+ // preparing output data
+ std::vector<unsigned> loc(vset.nvalues());
loc[n-1] = 0;
for (unsigned i = n - 2; i != 0; --i)
loc[i] = loc[i+1] + h[i+1];
- */
// computing output data
std::vector<mln_point(I)> vec(input.npoints());
@@ -133,20 +179,32 @@
for_all(p)
vec[loc[vset.index_of(input(p))]++] = p;
- return vec;
+ vec_p<mln_point(I)> v;
+ v.hook_() = vec;
+ return v;
}
+
} // end of namespace mln::level::impl
+ // Facades.
+
template <typename I>
- std::vector<mln_point(I)>
- sort_points(const Image<I>& input)
+ vec_p<mln_point(I)>
+ sort_points_increasing(const Image<I>& input)
{
mln_precondition(exact(input).has_data());
- return impl::sort_points(mln_is_value_lowq(I)(), exact(input));
+ return impl::sort_points_increasing_(mln_is_value_lowq(I)(), exact(input));
}
+ template <typename I>
+ vec_p<mln_point(I)>
+ sort_points_decreasing(const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ return impl::sort_points_decreasing_(mln_is_value_lowq(I)(), exact(input));
+ }
# endif // ! MLN_INCLUDE_ONLY
Index: mln/level/fill.hh
--- mln/level/fill.hh (revision 1067)
+++ mln/level/fill.hh (working copy)
@@ -86,7 +86,7 @@
* \todo Take benefit from quantization when possible.
*/
template <typename I>
- void fill(Image<I>& ima, mln_value(I) (*f)(const mln_point(I)& p));
+ void fill(Image<I>& ima, mln_value(I) (*(&f))(const mln_point(I)& p));
/*! Fill the image \p ima with the values given by the array \p arr.
@@ -191,8 +191,9 @@
template <typename I>
void fill(Image<I>& ima_,
- mln_value(I) (*f)(const mln_point(I)& p))
+ mln_value(I) (*(&f))(const mln_point(I)& p))
{
+ mln_precondition(f != 0);
I& ima = exact(ima_);
mln_precondition(ima.has_data());
mln_piter(I) p(ima.domain());
Index: mln/linear/sobel.hh
--- mln/linear/sobel.hh (revision 1067)
+++ mln/linear/sobel.hh (working copy)
@@ -102,7 +102,7 @@
O temp(exact(input).domain());
sobel_v(input, temp);
// output
- arith::plus_inplace(output, temp);
+ arith::plus_inplace(output, temp); // FIXME: abs before plus!!!
level::abs_inplace(output);
}
Index: mln/canvas/labeling.hh
--- mln/canvas/labeling.hh (revision 0)
+++ mln/canvas/labeling.hh (revision 0)
@@ -0,0 +1,157 @@
+// Copyright (C) 2007 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_CANVAS_LABELING_HH
+# define MLN_CANVAS_LABELING_HH
+
+/*! \file mln/canvas/labeling.hh
+ *
+ * \brief Connected component labeling of the object part in a binary
+ * image.
+ */
+
+# include <mln/level/fill.hh>
+# include <mln/level/sort_points.hh>
+
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ template <typename F>
+ struct labeling
+ {
+ F& f;
+
+ typedef typename F::I I;
+ typedef typename F::N N;
+ typedef typename F::O O;
+ typedef typename F::S S;
+ typedef mln_point(I) point;
+
+ // aux:
+ mln_ch_value(O, bool) deja_vu;
+ mln_ch_value(O, point) parent;
+
+ labeling(F& f)
+ : f(f),
+ deja_vu(f.output.domain()),
+ parent(f.output.domain())
+ {
+ run();
+ }
+
+ void run()
+ {
+ // init
+ {
+ f.nlabels = 0;
+ mln::level::fill(deja_vu, false);
+ f.init();
+ }
+ // first pass
+ {
+ mln_fwd_piter(S) p(f.s);
+ mln_niter(N) n(f.nbh, 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);
+ else
+ f.do_no_union(n, p);
+ deja_vu(p) = true;
+ }
+ }
+
+ // second pass
+ {
+ mln_bkd_piter(S) p(f.s);
+ mln_niter(N) n(f.nbh, p);
+ for_all(p) if (f.handles(p))
+ {
+ if (is_root(p))
+ {
+ if (f.labels(p))
+ {
+ if (f.nlabels = mln_max(mln_value(O)))
+ {
+ f.status = false;
+ return;
+ }
+ f.output(p) = ++f.nlabels;
+ }
+ }
+ else
+ f.output(p) = f.output(parent(p));
+ }
+ f.status = true;
+ }
+
+ } // end of run()
+
+ void make_set(const point& p)
+ {
+ parent(p) = p;
+ f.init_attr(p);
+ }
+
+ bool is_root(const point& p) const
+ {
+ return parent(p) = p;
+ }
+
+ point find_root(const point& x)
+ {
+ if (parent(x) = x)
+ return x;
+ else
+ return parent(x) = find_root(parent(x));
+ }
+
+ void do_union(const point& n, const point& p)
+ {
+ point r = find_root(n);
+ if (r != p)
+ {
+ parent(r) = p;
+ f.merge_attr(r, p);
+ }
+ }
+
+ };
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_LABELING_HH
Index: mln/labeling/flat_zones.hh
--- mln/labeling/flat_zones.hh (revision 0)
+++ mln/labeling/flat_zones.hh (revision 0)
@@ -0,0 +1,111 @@
+// Copyright (C) 2007 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_LABELING_FLAT_ZONES_HH
+# define MLN_LABELING_FLAT_ZONES_HH
+
+/*! \file mln/labeling/flat_zones.hh
+ *
+ * \brief Connected component labeling of the flat zones of an image.
+ */
+
+# include <mln/labeling/base.hh>
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /*! Connected component labeling of the flat zones of an image.
+ *
+ * \param[in] input The input image.
+ * \param[in] nbh The neighborhood to consider.
+ * \param[out] output The label image.
+ * \param[out] nlabels The number of labels.
+ *
+ * \return The number of labels.
+ */
+ template <typename I, typename N, typename O>
+ bool flat_zones(const Image<I>& input, const Neighborhood<N>& nbh,
+ Image<O>& output,
+ unsigned& nlabels);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I_, typename N_, typename O_>
+ struct flat_zones_ : base_<I_,N_,O_>
+ {
+ typedef mln_point(I_) P;
+
+ // requirements from mln::canvas::labeling:
+
+ typedef mln_pset(I_) S;
+ const S& s;
+ mln_value(O) nlabels;
+ bool status;
+
+ bool equiv(const P& n, const P&) const { return input(n) = input(p); }
+
+ // end of requirements
+
+ flat_zones_(const I_& input, const N_& nbh, O_& output)
+ : base_<I_,N_,O_>(input, nbh, output),
+ s(input.domain())
+ {}
+ };
+
+ } // end of namespace mln::labeling::impl
+
+
+ // Facade.
+
+ template <typename I, typename N, typename O>
+ bool flat_zones(const Image<I>& input, const Neighborhood<N>& nbh,
+ Image<O>& output,
+ unsigned& nlabels)
+ {
+ typedef impl::flat_zones_<I,N,O> F;
+ F f(exact(input), exact(nbh), exact(output));
+ canvas::labeling<F> run(f);
+ nlabels = f.nlabels;
+ return f.status;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_FLAT_ZONES_HH
Index: mln/labeling/level.hh
--- mln/labeling/level.hh (revision 0)
+++ mln/labeling/level.hh (revision 0)
@@ -0,0 +1,118 @@
+// Copyright (C) 2007 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_LABELING_LEVEL_HH
+# define MLN_LABELING_LEVEL_HH
+
+/*! \file mln/labeling/level.hh
+ *
+ * \brief Connected component labeling of the image objects at a given
+ * level.
+ */
+
+# include <mln/labeling/base.hh>
+# include <mln/level/fill.hh>
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /*! 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[out] output The label image.
+ * \param[out] nlabels The number of labels.
+ *
+ * \return Succeed or not.
+ */
+ template <typename I, typename N, typename O>
+ bool level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
+ Image<O>& output, unsigned& nlabels);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I_, typename N_, typename O_>
+ struct level_ : base_<I_,N_,O_>
+ {
+ typedef mln_point(I_) P;
+
+ // requirements from mln::canvas::labeling:
+
+ typedef mln_pset(I_) S;
+ const S& s;
+
+ void init() { mln::level::fill(this->output, 0); }
+ bool handles(const P& p) const { return input(p) = val; }
+ bool equiv(const P& n, const P&) const { return input(n) = val; }
+
+ // end of requirements
+
+ const mln_value(I_)& val;
+
+ level_(const I_& input, const mln_value(I_)& val, const N_& nbh, O_& output)
+ : base_<I_,N_,O_>(input, nbh, output),
+ s(input.domain()),
+ val(val)
+ {}
+ };
+
+ } // end of namespace mln::labeling::impl
+
+
+ // Facade.
+
+ template <typename I, typename N, typename O>
+ bool level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
+ Image<O>& output, unsigned& nlabels)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ typedef impl::level_<I,N,O> F;
+ F f(exact(input), val, exact(nbh), exact(output));
+ canvas::labeling<F> run(f);
+ nlabels = f.nlabels;
+ return f.status;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_LEVEL_HH
Index: mln/labeling/foreground.hh
--- mln/labeling/foreground.hh (revision 0)
+++ mln/labeling/foreground.hh (revision 0)
@@ -0,0 +1,79 @@
+// Copyright (C) 2007 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_LABELING_FOREGROUND_HH
+# define MLN_LABELING_FOREGROUND_HH
+
+/*! \file mln/labeling/foreground.hh
+ *
+ * \brief Connected component labeling of the object part in a binary
+ * image.
+ */
+
+# include <mln/labeling/level.hh>
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /*! 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[out] output The label image.
+ * \param[out] nlabels The number of labels.
+ *
+ * \return The number of labels.
+ */
+ template <typename I, typename N, typename O>
+ bool foreground(const Image<I>& input, const Neighborhood<N>& nbh,
+ Image<O>& output,
+ unsigned& nlabels);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename N, typename O>
+ bool foreground(const Image<I>& input, const Neighborhood<N>& nbh,
+ Image<O>& output,
+ unsigned& nlabels)
+ {
+ return labeling::level(input, true, nbh, output, nlabels);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_FOREGROUND_HH
Index: mln/labeling/regional_minima.hh
--- mln/labeling/regional_minima.hh (revision 0)
+++ mln/labeling/regional_minima.hh (revision 0)
@@ -0,0 +1,120 @@
+// Copyright (C) 2007 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_LABELING_REGIONAL_MINIMA_HH
+# define MLN_LABELING_REGIONAL_MINIMA_HH
+
+/*! \file mln/labeling/regional_minima.hh
+ *
+ * \brief Connected component labeling of the regional minima of an
+ * image.
+ */
+
+# include <mln/labeling/base.hh>
+# include <mln/level/sort_points.hh>
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /*! Connected component labeling of the regional minima of an
+ * image.
+ *
+ * \param[in] input The input image.
+ * \param[in] nbh The neighborhood to consider.
+ * \param[out] output The label image.
+ *
+ * \return The number of labels.
+ */
+ template <typename I, typename N, typename O>
+ bool regional_minima(const Image<I>& input, const Neighborhood<N>& nbh,
+ Image<O>& output, unsigned& nlabels);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I_, typename N_, typename O_>
+ struct regional_minima_ : base_<I_,N_,O_>
+ {
+ typedef mln_point(I_) P;
+
+ // requirements from mln::canvas::labeling:
+
+ typedef vec_p<P> S;
+ S s;
+
+ void init() { mln::level::fill(this->output, 0);
+ level::fill(attr, 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));
+ attr(p) = false; }
+ void merge_attr(const P& r, const P& p) { attr(p) = attr(p) && attr(r); }
+
+ // end of requirements
+
+ mln_ch_value(O_, bool) attr;
+
+ regional_minima_(const I_& input, const N_& nbh, O_& output)
+ : base_<I_,N_,O_>(input, nbh, output),
+ s(level::sort_points_increasing(input)),
+ attr(output.domain())
+ {
+ }
+ };
+
+ } // end of namespace mln::labeling::impl
+
+
+ // Facade.
+
+ template <typename I, typename N, typename O>
+ bool regional_minima(const Image<I>& input, const Neighborhood<N>& nbh,
+ Image<O>& output, unsigned& nlabels)
+ {
+ typedef impl::regional_minima_<I,N,O> F;
+ F f(exact(input), exact(nbh), exact(output));
+ canvas::labeling<F> run(f);
+ nlabels = f.nlabels;
+ return f.status;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_REGIONAL_MINIMA_HH
Index: mln/labeling/base.hh
--- mln/labeling/base.hh (revision 0)
+++ mln/labeling/base.hh (revision 0)
@@ -0,0 +1,94 @@
+// Copyright (C) 2007 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_LABELING_BASE_HH
+# define MLN_LABELING_BASE_HH
+
+/*! \file mln/labeling/base.hh
+ *
+ * \brief Base class for labeling functors.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/canvas/labeling.hh>
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ /// Base class for labeling functors.
+ template <typename I_, typename N_, typename O_>
+ struct base_
+ {
+ typedef I_ I;
+ typedef N_ N;
+ typedef O_ O;
+ typedef mln_point(I_) P;
+
+ const I& input;
+ const N& nbh;
+ O& output;
+
+ mln_value(O_) nlabels;
+ bool status;
+
+ base_(const I_& input, const N_& nbh, O_& output)
+ : input(input),
+ nbh(nbh),
+ output(output)
+ {
+ }
+
+ // Defaults.
+
+ bool handles(const P&) const { return true; }
+ bool labels(const P&) const { return true; }
+ void init() {}
+ void do_no_union(const P&, const P&) {}
+ void init_attr(const P&) {}
+ void merge_attr(const P&, const P&) {}
+ };
+
+ } // end of namespace mln::labeling::impl
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_BASE_HH
Index: mln/labeling/regional_maxima.hh
--- mln/labeling/regional_maxima.hh (revision 0)
+++ mln/labeling/regional_maxima.hh (revision 0)
@@ -0,0 +1,120 @@
+// Copyright (C) 2007 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_LABELING_REGIONAL_MAXIMA_HH
+# define MLN_LABELING_REGIONAL_MAXIMA_HH
+
+/*! \file mln/labeling/regional_maxima.hh
+ *
+ * \brief Connected component labeling of the regional maxima of an
+ * image.
+ */
+
+# include <mln/labeling/base.hh>
+# include <mln/level/sort_points.hh>
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /*! Connected component labeling of the regional maxima of an
+ * image.
+ *
+ * \param[in] input The input image.
+ * \param[in] nbh The neighborhood to consider.
+ * \param[out] output The label image.
+ *
+ * \return The number of labels.
+ */
+ template <typename I, typename N, typename O>
+ bool regional_maxima(const Image<I>& input, const Neighborhood<N>& nbh,
+ Image<O>& output, unsigned& nlabels);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I_, typename N_, typename O_>
+ struct regional_maxima_ : base_<I_,N_,O_>
+ {
+ typedef mln_point(I_) P;
+
+ // requirements from mln::canvas::labeling:
+
+ typedef vec_p<P> S;
+ S s;
+
+ void init() { mln::level::fill(this->output, 0);
+ level::fill(attr, 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));
+ attr(p) = false; }
+ void merge_attr(const P& r, const P& p) { attr(p) = attr(p) && attr(r); }
+
+ // end of requirements
+
+ mln_ch_value(O_, bool) attr;
+
+ regional_maxima_(const I_& input, const N_& nbh, O_& output)
+ : base_<I_,N_,O_>(input, nbh, output),
+ s(level::sort_points_decreasing(input)),
+ attr(output.domain())
+ {
+ }
+ };
+
+ } // end of namespace mln::labeling::impl
+
+
+ // Facade.
+
+ template <typename I, typename N, typename O>
+ bool regional_maxima(const Image<I>& input, const Neighborhood<N>& nbh,
+ Image<O>& output, unsigned& nlabels)
+ {
+ typedef impl::regional_maxima_<I,N,O> F;
+ F f(exact(input), exact(nbh), exact(output));
+ canvas::labeling<F> run(f);
+ nlabels = f.nlabels;
+ return f.status;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_REGIONAL_MAXIMA_HH
Index: mln/labeling/background.hh
--- mln/labeling/background.hh (revision 0)
+++ mln/labeling/background.hh (revision 0)
@@ -0,0 +1,79 @@
+// Copyright (C) 2007 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_LABELING_BACKGROUND_HH
+# define MLN_LABELING_BACKGROUND_HH
+
+/*! \file mln/labeling/background.hh
+ *
+ * \brief Connected component labeling of the background in a binary
+ * image.
+ */
+
+# include <mln/labeling/level.hh>
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /*! Connected component labeling of the background in a binary
+ * image.
+ *
+ * \param[in] input The input image.
+ * \param[in] nbh The neighborhood to consider.
+ * \param[out] output The label image.
+ * \param[out] nlabels The number of labels.
+ *
+ * \return The number of labels.
+ */
+ template <typename I, typename N, typename O>
+ bool background(const Image<I>& input, const Neighborhood<N>& nbh,
+ Image<O>& output,
+ unsigned& nlabels);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename N, typename O>
+ bool background(const Image<I>& input, const Neighborhood<N>& nbh,
+ Image<O>& output,
+ unsigned& nlabels)
+ {
+ return labeling::level(input, false, nbh, output, nlabels);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_BACKGROUND_HH
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add room in sandbox.
* sandbox/duhamel: New.
* sandbox/levillain: New.
* sandbox/nivault: New.
* sandbox/jardonnet: New.
* sandbox/geraud: New.
* sandbox/garrigues: New.
* sandbox/cxxcompilation: Rename as...
* sandbox/ballas: ...this.
compilation_unit.rb | 56 --------------------
methods | 104 --------------------------------------
test.cc | 69 -------------------------
vaucanson_bench | 141 ----------------------------------------------------
4 files changed, 370 deletions(-)
Index: sandbox/cxxcompilation/compilation_unit.rb
--- sandbox/cxxcompilation/compilation_unit.rb (revision 1066)
+++ sandbox/cxxcompilation/compilation_unit.rb (working copy)
@@ -1,56 +0,0 @@
-#! /usr/bin/ruby
-
-#Create a compilation unit file from a .cc file
-
-#USAGE: ./compilation_unit.rb file.cc
-
-
-class CompilationUnit
- attr_reader :sourceFileName, :name, :namespaceName
-
- public
- def initialize(sourceFileName)
-
-
- @sourceFileName = sourceFileName
- @name = sourceFileName.gsub(/.cc\z/, ".unit.cc")
- @namespaceName = "__instanciator_code"
-
- if not File.exist?(@name) then
- self.createCompilationUnitFile
- end
- end
-
- def update
- createCompilationUnitFile
- end
-
- #Create UnitCompilationfile from source
- def createCompilationUnitFile
- sourceFile = File.new("#{@sourceFileName}", "r")
- destinationFile = File.new("#{@name}", "w")
-
- # Copy usefull include files into cache file.
- sourceFile.each_line do |line|
- destinationFile.puts(line) if line =~ /#include/
- end
-
- # trash namespace
- destinationFile.puts("namespace #{@namespaceName} {")
-
- # puts code line into trash namespace
- sourceFile.close
- sourceFile = File.new("#{@sourceFileName}", "r")
- sourceFile.each_line do |line|
- destinationFile.puts(line) if not (line =~ /#include/)
- end
-
- # end of namespace
- destinationFile.puts("}")
-
- sourceFile.close
- destinationFile.close
- end
-end
-
-unit = CompilationUnit.new(ARGV[0])
Index: sandbox/cxxcompilation/test.cc
--- sandbox/cxxcompilation/test.cc (revision 1066)
+++ sandbox/cxxcompilation/test.cc (working copy)
@@ -1,69 +0,0 @@
-// Copyright (C) 2007 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.
-
-#include <oln/core/2d/image2d.hh>
-#include <oln/core/3d/image3d.hh>
-#include <oln/core/1d/image1d.hh>
-#include <oln/level/fill.hh>
-
-
-using namespace oln;
-
-int main(void)
-{
- image1d<char> ima1d1(5);
- image1d<int> ima1d2(5);
- image1d<float> ima1d3(5);
- image1d<double> ima1d4(5);
-
- level::fill(inplace(ima1d1), 5);
- level::fill(inplace(ima1d2), 5);
- level::fill(inplace(ima1d3), 5);
- level::fill(inplace(ima1d4), 5);
-
- image2d<char> ima2d1(5, 5);
- image2d<int> ima2d2(5, 5);
- image2d<float> ima2d3(5, 5);
- image2d<double> ima2d4(5, 5);
-
- level::fill(inplace(ima2d1), 5);
- level::fill(inplace(ima2d2), 5);
- level::fill(inplace(ima2d3), 5);
- level::fill(inplace(ima2d4), 5);
-
- image3d<char> ima3d1(5, 5, 5);
- image3d<int> ima3d2(5, 5, 5);
- image3d<float> ima3d3(5, 5, 5);
- image3d<double> ima3d4(5, 5, 5);
-
- level::fill(inplace(ima3d1), 5);
- level::fill(inplace(ima3d2), 5);
- level::fill(inplace(ima3d3), 5);
- level::fill(inplace(ima3d4), 5);
-
- return 0;
-}
Index: sandbox/cxxcompilation/methods
--- sandbox/cxxcompilation/methods (revision 1066)
+++ sandbox/cxxcompilation/methods (working copy)
@@ -1,104 +0,0 @@
- -*- Outline -*-
-
-* without optimization flags
-
-** Benchmark
-
-compilation: 2.131
-execution: 18.538
-total: 22.670
-
-
-* O1
-
-** Benchmark
-compilation: 3.616
-execution: 4.893
-total: 8.509
-
-* O2
-** Benchmark
-compilation: 4.610
-execution: 3.781
-total: 8.391
-
-* 03
-compilation: 5.071
-execution: 1.567
-total: 6.638
-
-
-
-
-The next part introduces different method to speed up C++ compilation time.
-
-Test are made with union_find.cc file.
-
-* precompiled header (without optimization option)
-
-** Description
-
-Generate precompiled header (.gch) which can parsed in a faster way by g++.
-
-
-How to automize header precompilation, just make a precompilation of usefull header ?
-
-** Benchmark
-
-compilation: 3.733
-execution: 18.119
-total: 21.852
-
-* ccache (without optimization option)
-
-** Description
-
-"ccache is a compiler cache. It acts as a caching pre-processor to C/C++ compilers, using the -E compiler switch and a hash to detect when a compilation can be satisfied from cache. This often results in a 5 to 10 times speedup in common compilations." http://cache.samba.org
-
-** Benchmark
-
-* Vacauson Way (without optimization option)
-
-** Description
-
-cf: http://www.lrde.epita.fr/cgi-bin/twiki/view/Know/SpeedUpCxxCompilation
-
-
-*** total recompilation protocol of source.cc:
---> (1) compile source.cc to "ref".o (cache used for function addresse reference)
---> (2) source.cc -> source.o with -DINTERFACE_ONLY (real program)
---> (3) links source.o to "ref".o
-
-*** Protocole:
---> do (1)
---> do (2) and (3) as long as there is no linkage error, else redo (1)
-
-
-*** Problems:
-
-You must recompile the cache when you use an new algorithm/data type in your program.
---> solution: ask developper to write usefull algorithm/data types/includes at the start of the programm and uses template instantiation
-
-
-Automatization??
---> how deals with several files
---> how deals with missing .hh files
---> differenciate link error from other error
-
-***Others things:
-
-wrapper script or Makefile???
---> script used by Makefile
-
-** Benchmark
-
-*** first compilation or total recompilation is longer than a normal compilation
-
-you need to compile program two times
-
-
-*** next time when cache recompilation is not needed
-
-compilation: 0.200
-execution: 17.875
-toto: 18.075
Index: sandbox/cxxcompilation/vaucanson_bench
--- sandbox/cxxcompilation/vaucanson_bench (revision 1066)
+++ sandbox/cxxcompilation/vaucanson_bench (working copy)
@@ -1,141 +0,0 @@
- -*- Outline -*-
-
-* Summary:
-
- This files present c++ compilation benchmark with Vaucanson method.
-
-* Vaucanson method:
-
-** Files used:
-*** source.cc
-client code
-
-*** source.unit.cc
-This files contains instantiations of templated data and algorithms used by the client code.
-
-A Compilation unit copies #include directives used by source.cc
-Furthermore, it copies client source code into a trash name's (in order to instantiated templates).
-
-But other method exists to create compilation unit(cf .hcc).
-
-
-** Compilation process:
-
-*** total recompilation
-
---> (1) compile source.unit.cc to an object file (source.unit.o) (cache used to find function address reference).
-
---> (2) compile source.cc to source.o with -DINTERFACE_ONLY (or INCLUDE_ONLY, we want to compile just the interface the objects).
-
---> (3) link source.o with source.unit.o
-
-*** Protocol:
---> do (1)
---> do (2) and (3) as long as there are no linkage errors, else redo (1)
-
-
-
-
-* Benchmark:
-
-** With Olena:
-
-compile command:
-g++ -W -Wall -Werror -ansi -pedantic -Ipath/metalic -Ipath/olena -Ipath/extended
-
-dimension of image used for test: 512 * 512.
-Note: We can add optimization flag to speed up execution time.
-
-
-*******************************************************************************
-** File: oln/morpho/Rd/union_find.cc
-
-*** normal compilation:
-compilation time: 4.110
-execution time: 42.893
-total time: 47.003
-
-*** With Vaucanson method:
-
-**** total recompilation:
-
-compilation time: 6.749
---> (1) : 4.062
---> (2) : 2.524
---> (3) : 0.163
-
-execution time: 42.058
-total time: 48.807
-
-~= 2 second slower than a normal compilation
-
-**** Usual recompilation
-
-compilation time: 2.702
---> (2) : 2.542
---> (3) : 0.160
-
-execution time:42.060
-total time: 44.762
-
-*******************************************************************************
-** oln/morpho/Rd/queue_based.cc
-
-*** normal compilation:
-compilation time: 4.296
-execution time: 35.836
-total time: 40.132
-
-*** With Vaucanson method:
-
-**** total recompilation:
-
-compilation time: 7.187
---> (1) : 4.378
---> (2) : 2.636
---> (3) : 0.173
-
-execution time: 35.836
-total time: 43.023
-
-**** Usual recompilation
-
-compilation time: 2.809
---> (2) : 2.636
---> (3) : 0.173
-
-*******************************************************************************
-** test.cc
-
-(declare and fill 12 differents image types)
-
-*** normal compilation:
-compilation time: 25.585
-execution time: 0.006
-total time: 25.596
-
-*** With Vaucanson method:
-
-**** total recompilation:
-
-compilation time: 45.087
---> (1) : 25.378
---> (2) : 19.318
---> (3) : 0.391
-
-execution time: 0.006
-total time: 45.093
-
-**** Usual recompilation
-
-compilation time: 19.664
---> (2) : 19.259
---> (3) : 0.405
-
-** with morpher
-
-FIXME
-
-*** With Milena
-
-FIXME
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fix missing file.
* mln/value/cast.hh: New.
labeling/+foreground.hh | 106 ++++++++++++++++++++++++++++++++++++++++++++++++
value/cast.hh | 85 ++++++++++++++++++++++++++++++++++++++
2 files changed, 191 insertions(+)
Index: mln/value/cast.hh
--- mln/value/cast.hh (revision 0)
+++ mln/value/cast.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 2007 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_VALUE_CAST_HH
+# define MLN_VALUE_CAST_HH
+
+/*! \file mln/value/cast.hh
+ * \brief Definition of the mln::value::cast routine.
+ */
+
+# include <mln/core/concept/value.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /// Cast a value \p src from type \c Src to type \c Dest.
+ template <typename Dest, typename Src>
+ Dest cast(const Src& src);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ template <typename S>
+ const S&
+ cast_(const S& src, ...)
+ {
+ return src;
+ }
+
+ template <typename T, typename S>
+ typename S::equiv
+ cast_(const T&, const Value<S>& src)
+ {
+ return exact(src);
+ }
+
+ } // end of namespace mln::value::internal
+
+ template <typename Dest, typename Src>
+ Dest cast(const Src& src)
+ {
+ return internal::cast_(src, src);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_CAST_HH
Index: mln/labeling/+foreground.hh
--- mln/labeling/+foreground.hh (revision 0)
+++ mln/labeling/+foreground.hh (revision 0)
@@ -0,0 +1,106 @@
+// Copyright (C) 2007 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_LABELING_FOREGROUND_HH
+# define MLN_LABELING_FOREGROUND_HH
+
+/*! \file mln/labeling/foreground.hh
+ *
+ * \brief Foreground a function-object onto image pixel values.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ namespace labeling
+ {
+
+ /*! Foreground a function-object to the image \p input.
+ *
+ * \param[in,out] input The input image.
+ * \param[in] f The function-object.
+ *
+ * This routine runs: \n
+ * for all p of \p input, \p input(p) = \p f( \p input(p) ) \n
+ *
+ * This routine is equivalent to labeling::tranform(input, f, input)
+ * but it is faster since a single iterator is required.
+ *
+ * \todo Add versions for lowq images.
+ */
+ template <typename I, typename F>
+ void foreground(Image<I>& input, const Function_v2v<F>& f);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I, typename F>
+ void foreground_(Image<I>& input_, const F& f)
+ {
+ I& input = exact(input_);
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ input(p) = f(input(p));
+ }
+
+ template <typename I, typename F>
+ void foreground_(Fast_Image<I>& input_, const F& f)
+ {
+ I& input = exact(input_);
+ mln_pixter(I) pxl(input);
+ for_all(pxl)
+ pxl.val() = f(pxl.val());
+ }
+
+ } // end of namespace mln::labeling::impl
+
+
+ // Facade.
+
+ template <typename I, typename F>
+ void foreground(Image<I>& input, const Function_v2v<F>& f)
+ {
+ mln_precondition(exact(input).has_data());
+ impl::foreground_(exact(input), exact(f));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::labeling
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LABELING_FOREGROUND_HH