https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add a couple of geodesic transforms.
* mln/transform/influence_zone_geodesic.hh: New.
* mln/transform/all.hh: Update.
* tests/transform/influence_zone_geodesic.cc: New.
* mln/transform/distance_geodesic.hh: New.
* tests/transform/distance_geodesic.cc: New.
mln/transform/all.hh | 13 +-
mln/transform/distance_geodesic.hh | 153 +++++++++++++++++++++++++++
mln/transform/influence_zone_geodesic.hh | 160 +++++++++++++++++++++++++++++
tests/transform/distance_geodesic.cc | 52 +++++++++
tests/transform/influence_zone_geodesic.cc | 58 ++++++++++
5 files changed, 430 insertions(+), 6 deletions(-)
Index: tests/transform/distance_geodesic.cc
--- tests/transform/distance_geodesic.cc (revision 0)
+++ tests/transform/distance_geodesic.cc (revision 0)
@@ -0,0 +1,52 @@
+// 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/transform/distance_geodesic.cc
+///
+/// Test on mln::transform::distance_geodesic.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/level/fill.hh>
+#include <mln/debug/println.hh>
+
+#include <mln/transform/distance_geodesic.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<bool> input(9, 9);
+ level::fill(input, false);
+ input.at(4, 4) = true;
+
+ image2d<int_u8> output = transform::distance_geodesic(input, c4(), int_u8(4));
+ debug::println(output);
+}
Index: tests/transform/influence_zone_geodesic.cc
--- tests/transform/influence_zone_geodesic.cc (revision 0)
+++ tests/transform/influence_zone_geodesic.cc (revision 0)
@@ -0,0 +1,58 @@
+// 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/transform/influence_zone_geodesic.cc
+///
+/// Test on mln::transform::influence_zone_geodesic.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/make/image2d.hh>
+#include <mln/debug/println.hh>
+
+#include <mln/transform/influence_zone_geodesic.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ int_u8 vals[] =
+ { 1, 1, 0, 0, 0, 0, 3,
+ 1, 1, 1, 0, 0, 0, 0,
+ 0, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 2, 0,
+ 0, 0, 0, 0, 2, 2, 0,
+ 0, 0, 0, 0, 0, 0, 0 };
+ image2d<int_u8> input = make::image2d(vals);
+
+ image2d<int_u8> output = transform::influence_zone_geodesic(input, c4(), int_u8(1));
+ debug::println(output);
+}
Index: mln/transform/influence_zone_geodesic.hh
--- mln/transform/influence_zone_geodesic.hh (revision 0)
+++ mln/transform/influence_zone_geodesic.hh (revision 0)
@@ -0,0 +1,160 @@
+// 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_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH
+# define MLN_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH
+
+/// \file mln/transform/influence_zone_geodesic.hh
+///
+/// Discrete geodesic distance transform.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/site_set/p_queue_fast.hh>
+# include <mln/core/routine/clone.hh>
+# include <mln/level/fill.hh>
+
+# include <mln/debug/println.hh>
+
+
+namespace mln
+{
+
+ namespace transform
+ {
+
+ /// Discrete geodesic distance transform.
+ template <typename I, typename N, typename D>
+ mln_concrete(I)
+ influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh, D max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ namespace generic
+ {
+
+ template <typename I, typename N, typename D>
+ mln_concrete(I)
+ influence_zone_geodesic(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ D max)
+ {
+ trace::entering("transform::impl::generic::influence_zone_geodesic");
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+
+ mln_precondition(input.has_data());
+
+ mln_ch_value(I, D) dmap; // Distance map is aux data.
+ initialize(dmap, input);
+
+ typedef mln_site(I) P;
+ p_queue_fast<P> q;
+
+ mln_concrete(I) output = clone(input);
+
+ // Initialization.
+ {
+ level::fill(dmap, max);
+ mln_piter(I) p(input.domain());
+ mln_niter(N) n(nbh, p);
+ for_all(p)
+ if (input(p) != 0) // p in a component
+ {
+ dmap(p) = 0;
+ for_all(n)
+ if (input.domain().has(n) && input(n) == 0) // n in background
+ {
+ q.push(p);
+ break;
+ }
+ }
+ }
+
+ // Propagation.
+ {
+ P p;
+ mln_niter(N) n(nbh, p);
+ while (! q.is_empty())
+ {
+ p = q.pop_front();
+ if (dmap(p) == max)
+ {
+ // Saturation so stop.
+ q.clear();
+ break;
+ }
+ for_all(n)
+ if (input.domain().has(n) && dmap(n) == max)
+ {
+ dmap(n) = dmap(p) + 1;
+ output(n) = output(p);
+ q.push(n);
+ }
+ }
+ }
+
+ trace::exiting("transform::impl::generic::influence_zone_geodesic");
+ return output;
+ }
+
+ } // end of namespace mln::transform::impl::generic
+
+ } // end of namespace mln::transform::impl
+
+
+ // Facade.
+
+ template <typename I, typename N, typename D>
+ inline
+ mln_concrete(I)
+ influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh,
+ D distance_max)
+ {
+ trace::entering("transform::influence_zone_geodesic");
+
+ // FIXME: tests.
+
+ mln_concrete(I) output;
+ output = impl::generic::influence_zone_geodesic(input, nbh, distance_max);
+
+ trace::exiting("transform::influence_zone_geodesic");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::transform
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRANSFORM_DISTANCE_HH
Index: mln/transform/all.hh
--- mln/transform/all.hh (revision 2827)
+++ mln/transform/all.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// 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
@@ -28,22 +28,23 @@
#ifndef MLN_TRANSFORM_ALL_HH
# define MLN_TRANSFORM_ALL_HH
-/*! \file mln/transform/all.hh
- *
- * \brief File that includes all "point-wise" expression tools.
- */
+/// \file mln/transform/all.hh
+///
+/// File that includes all transforms.
namespace mln
{
- /// Namespace of "point-wise" expression tools.
+ /// Namespace of transforms.
namespace transform {}
} // end of namespace mln
# include <mln/transform/distance.hh>
+# include <mln/transform/distance_geodesic.hh>
+# include <mln/transform/influence_zone_geodesic.hh>
#endif // ! MLN_TRANSFORM_ALL_HH
Index: mln/transform/distance_geodesic.hh
--- mln/transform/distance_geodesic.hh (revision 0)
+++ mln/transform/distance_geodesic.hh (revision 0)
@@ -0,0 +1,153 @@
+// 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_TRANSFORM_DISTANCE_GEODESIC_HH
+# define MLN_TRANSFORM_DISTANCE_GEODESIC_HH
+
+/// \file mln/transform/distance_geodesic.hh
+///
+/// Discrete geodesic distance transform.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/site_set/p_queue_fast.hh>
+# include <mln/level/fill.hh>
+
+
+
+namespace mln
+{
+
+ namespace transform
+ {
+
+ /// Discrete geodesic distance transform.
+ template <typename I, typename N, typename D>
+ mln_ch_value(I, D)
+ distance_geodesic(const Image<I>& input, const Neighborhood<N>& nbh, D max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ namespace generic
+ {
+
+ template <typename I, typename N, typename D>
+ mln_ch_value(I, D)
+ distance_geodesic(const Image<I>& input_, const Neighborhood<N>& nbh_, D max)
+ {
+ trace::entering("transform::impl::generic::distance_geodesic");
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+
+ mln_precondition(input.has_data());
+
+ mln_ch_value(I, D) output;
+ initialize(output, input);
+
+ typedef mln_site(I) P;
+ p_queue_fast<P> q;
+
+ // Initialization.
+ {
+ level::fill(output, max);
+ mln_piter(I) p(input.domain());
+ mln_niter(N) n(nbh, p);
+ for_all(p)
+ if (input(p) == true) // p in object
+ {
+ output(p) = 0;
+ for_all(n)
+ if (input.domain().has(n) && input(n) == false) // n in background
+ {
+ q.push(p);
+ break;
+ }
+ }
+ }
+
+ // Propagation.
+ {
+ P p;
+ mln_niter(N) n(nbh, p);
+ while (! q.is_empty())
+ {
+ p = q.pop_front();
+ for_all(n)
+ if (input.domain().has(n) && output(n) == max)
+ {
+ output(n) = output(p) + 1;
+ if (output(n) == max)
+ {
+ // Saturation so stop.
+ q.clear();
+ break;
+ }
+ q.push(n);
+ }
+ }
+ }
+
+ trace::exiting("transform::impl::generic::distance_geodesic");
+ return output;
+ }
+
+ } // end of namespace mln::transform::impl::generic
+
+ } // end of namespace mln::transform::impl
+
+
+ // Facade.
+
+ template <typename I, typename N, typename D>
+ inline
+ mln_ch_value(I, D)
+ distance_geodesic(const Image<I>& input, const Neighborhood<N>& nbh, D max)
+ {
+ trace::entering("transform::distance_geodesic");
+
+ // FIXME: tests.
+
+ mln_ch_value(I, D) output;
+ output = impl::generic::distance_geodesic(input, nbh, max);
+
+ trace::exiting("transform::distance_geodesic");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::transform
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRANSFORM_DISTANCE_HH
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
ChangeLog:
2008-11-06 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add arith::diff_abs.
* mln/arith/all.hh: add diff_abs.hh.
* mln/arith/diff_abs.hh: New, compute the absolute difference between
two images.
* mln/fun/vv2v/diff_abs.hh: New, diff_abs vv2v function.
* mln/level/transform.hh: Add a generic version of transform working
with 2 images and a vv2v functions.
* mln/math/all.hh: add diff_abs.hh.
* mln/math/diff_abs.hh: New, compute the absolute difference between
two values.
* tests/arith/Makefile.am: Add diff_abs test.
* tests/arith/diff_abs.cc: New, test arith::diff_abs.
* mln/core/clock_neighb.hh: Start to clean this neighboorhood.
Fix erosion on octogone.
* mln/morpho/erosion.spe.hh: Fix erosion on octogone by decomposing
the octogone with a vline, a hline, a diagonal and a backdiagonal. All
of these elements have a width of (width(oct) + 2) / 3.
---
mln/arith/all.hh | 1
mln/arith/diff_abs.hh | 86 +++++++++++++++++++++++++++++++++++++++++
mln/core/clock_neighb.hh | 36 ++++++++---------
mln/fun/vv2v/diff_abs.hh | 78 +++++++++++++++++++++++++++++++++++++
mln/level/transform.hh | 95 ++++++++++++++++++++++++++++++++++++++++++++++
mln/math/all.hh | 1
mln/math/diff_abs.hh | 63 ++++++++++++++++++++++++++++++
mln/morpho/erosion.spe.hh | 11 ++---
tests/arith/Makefile.am | 2
tests/arith/diff_abs.cc | 73 +++++++++++++++++++++++++++++++++++
10 files changed, 423 insertions(+), 23 deletions(-)
Index: branches/cleanup-2008/milena/tests/arith/diff_abs.cc
===================================================================
--- branches/cleanup-2008/milena/tests/arith/diff_abs.cc (revision 0)
+++ branches/cleanup-2008/milena/tests/arith/diff_abs.cc (revision 2824)
@@ -0,0 +1,73 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/arith/diff_abs.cc
+ *
+ * \brief Tests on mln::arith::diff_abs.
+ */
+
+#include <mln/core/image/image2d.hh>
+#include <mln/debug/iota.hh>
+#include <mln/arith/diff_abs.hh>
+#include <mln/level/compare.hh>
+
+int main()
+{
+ using namespace mln;
+
+ trace::quiet = false;
+
+ {
+ image2d<int> ima(3,3);
+
+ int vs1[3][3] = {
+ {0, 1, 2},
+ {3, 4, 5},
+ {6, 7, 8}
+ };
+
+
+ int vs2[3][3] = {
+ {1, 0, 5},
+ {8, 5, 6},
+ {9, 5, 2}
+ };
+
+ int vs_ref[3][3] = {
+ {1, 1, 3},
+ {5, 1, 1},
+ {3, 2, 6}
+ };
+
+ image2d<int> ima1 = make::image(vs1);
+ image2d<int> ima2 = make::image(vs2);
+ image2d<int> ref = make::image(vs_ref);
+
+ mln_assertion (arith::diff_abs(ima1, ima2) == ref);
+ }
+
+}
Index: branches/cleanup-2008/milena/tests/arith/Makefile.am
===================================================================
--- branches/cleanup-2008/milena/tests/arith/Makefile.am (revision 2823)
+++ branches/cleanup-2008/milena/tests/arith/Makefile.am (revision 2824)
@@ -4,12 +4,14 @@
check_PROGRAMS = \
all_headers \
+ diff_abs \
minus \
plus \
revert \
times
all_headers_SOURCES = all_headers.cc
+diff_abs_SOURCES = diff_abs.cc
minus_SOURCES = minus.cc
plus_SOURCES = plus.cc
revert_SOURCES = revert.cc
Index: branches/cleanup-2008/milena/mln/core/clock_neighb.hh
===================================================================
--- branches/cleanup-2008/milena/mln/core/clock_neighb.hh (revision 2823)
+++ branches/cleanup-2008/milena/mln/core/clock_neighb.hh (revision 2824)
@@ -30,7 +30,7 @@
/*! \file mln/core/clock_neighb.hh
*
- * \brief Definition of the generic neighborhood class mln::clock_neighb_.
+ * \brief Definition of the generic neighborhood class mln::clock_neighb.
*/
# include <mln/core/concept/neighborhood.hh>
@@ -47,27 +47,27 @@
/*! \brief Generic neighborhood class.
*
- * This neighborhood of window is just like a set of delta-points.
- * The parameter is \c D, type of delta-point.
+ * This neighborhood of window is just like a set of delta-psites.
+ * The parameter is \c D, type of delta-psite.
*/
template <typename D>
- struct clock_neighb_ : public Neighborhood< clock_neighb_ <D> >
+ struct clock_neighb : public Neighborhood< clock_neighb <D> >
{
/// Dpsite associated type.
- typedef D dpoint;
+ typedef D dpsite;
/// Site associated type.
typedef mln_psite(D) point;
- /*! \brief Site_Iterator type to browse the points of a generic
- * neighborhood w.r.t. the ordering of delta-points.
+ /*! \brief Site_Iterator type to browse the psites of a generic
+ * neighborhood w.r.t. the ordering of delta-psites.
*/
typedef dpsites_fwd_piter<D> fwd_niter;
- /*! \brief Site_Iterator type to browse the points of a generic
- * neighborhood w.r.t. the reverse ordering of delta-points.
+ /*! \brief Site_Iterator type to browse the psites of a generic
+ * neighborhood w.r.t. the reverse ordering of delta-psites.
*
- * !!! Be careful the start delta point become the last now.
+ * !!! Be careful the start delta psite become the last now.
*/
typedef dpsites_bkd_piter<D> bkd_niter;
@@ -80,18 +80,18 @@
* The constructed neighborhood is empty. You have to use insert()
* to proceed to the neighborhood definition.
*/
- clock_neighb_();
+ clock_neighb();
- /*! \brief Insert a delta-point \p dp in the neighborhood
+ /*! \brief Insert a delta-psite \p dp in the neighborhood
* definition.
*
- * \param[in] dp The delta-point to insert.
+ * \param[in] dp The delta-psite to insert.
*
- * This method also insert the symmetrical delta-point, - \p dp,
+ * This method also insert the symmetrical delta-psite, - \p dp,
* in the neighborhood definition; thus the client has not to
* ensure the symmetry property; that is automatic.
*/
- clock_neighb_<D>& append(const D& dp);
+ clock_neighb<D>& append(const D& dp);
/// \}
const std::vector<D>& vect() const
{
@@ -106,14 +106,14 @@
template <typename D>
inline
- clock_neighb_<D>::clock_neighb_()
+ clock_neighb<D>::clock_neighb()
{
}
template <typename D>
inline
- clock_neighb_<D>&
- clock_neighb_<D>::append(const D& dp)
+ clock_neighb<D>&
+ clock_neighb<D>::append(const D& dp)
{
vec_.push_back(dp);
return *this;
Index: branches/cleanup-2008/milena/mln/math/all.hh
===================================================================
--- branches/cleanup-2008/milena/mln/math/all.hh (revision 2823)
+++ branches/cleanup-2008/milena/mln/math/all.hh (revision 2824)
@@ -44,6 +44,7 @@
# include <mln/math/abs.hh>
+# include <mln/math/diff_abs.hh>
# include <mln/math/jacobi.hh>
# include <mln/math/max.hh>
# include <mln/math/min.hh>
Index: branches/cleanup-2008/milena/mln/math/diff_abs.hh
===================================================================
--- branches/cleanup-2008/milena/mln/math/diff_abs.hh (revision 0)
+++ branches/cleanup-2008/milena/mln/math/diff_abs.hh (revision 2824)
@@ -0,0 +1,63 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MATH_DIFF_ABS_HH
+# define MLN_MATH_DIFF_ABS_HH
+
+/*! \file mln/math/diff_abs.hh
+ *
+ * \brief Define diff_abs routine.
+ */
+
+
+namespace mln
+{
+
+ namespace math
+ {
+
+ template <typename T>
+ T diff_abs(const T& v1, const T& v2);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ inline
+ T diff_abs(const T& v1, const T& v2)
+ {
+ return abs(v1 - v2);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::math
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MATH_DIFF_ABS_HH
Index: branches/cleanup-2008/milena/mln/level/transform.hh
===================================================================
--- branches/cleanup-2008/milena/mln/level/transform.hh (revision 2823)
+++ branches/cleanup-2008/milena/mln/level/transform.hh (revision 2824)
@@ -67,6 +67,22 @@
transform(const Image<I>& input, const Function_v2v<F>& f);
+ /*! Transform two images \p ima1 \p ima2 through a function \p f
+ *
+ * \param[in] input The input image.
+ * \param[in] f The function.
+ *
+ * This routine runs: \n
+ * for all p of \p input, \p output(p) = \p f( \p input(p) ).
+ *
+ */
+ template <typename I, typename J, typename F>
+ mln_ch_value(I, mln_result(F))
+ transform(const Image<I>& ima1,
+ const Image<J>& ima2,
+ const Function_vv2v<F>& f);
+
+
# ifndef MLN_INCLUDE_ONLY
namespace internal
@@ -97,6 +113,38 @@
mln_precondition(exact(input).has_data());
mln_precondition(exact(output).domain() >= exact(input).domain());
}
+
+ template <typename I, typename J, typename F, typename O>
+ inline
+ void transform_tests(const Image<I>& ima1,
+ const Image<J>& ima2,
+ const Function_v2v<F>& f,
+ Image<O>& output)
+ {
+ // Avoid a warning about an undefined variable when NDEBUG
+ // is not defined.
+ (void) ima1;
+ (void) ima2;
+ (void) f;
+ (void) output;
+
+ // Properties check
+ mln_precondition((mlc_is(mln_trait_image_pw_io(O),
+ trait::image::pw_io::read_write)::value ||
+ mlc_is(mln_trait_image_vw_io(O),
+ trait::image::vw_io::read_write)::value));
+
+ // FIXME Convert test
+ mlc_converts_to(mln_result(F), mln_value(O))::check();
+
+
+ // Dynamic tests
+ mln_precondition(exact(ima1).has_data());
+ mln_precondition(exact(ima2).has_data());
+ mln_precondition(exact(ima1).domain() == exact(ima2).domain());
+ mln_precondition(exact(output).domain() >= exact(ima1).domain());
+ }
+
} // end of namespace mln::level::internal
@@ -135,6 +183,35 @@
return output;
}
+
+ // Generic implementation.
+ template <typename I, typename J, typename F>
+ inline
+ mln_ch_value(I, mln_result(F))
+ transform(const Image<I>& ima1_,
+ const Image<J>& ima2_,
+ const Function_vv2v<F>& f_)
+ {
+ trace::entering("level::impl::generic::transform");
+
+ const I& ima1 = exact(ima1_);
+ const I& ima2 = exact(ima2_);
+ const F& f = exact(f_);
+
+ mln_ch_value(I, mln_result(F)) output;
+ initialize(output, ima1);
+
+// level::internal::transform_tests(ima1, ima2, f, output);
+
+ mln_piter(I) p(ima1.domain());
+ for_all(p)
+ output(p) = f(ima1(p), ima2(p));
+
+ trace::exiting("level::impl::generic::transform");
+
+ return output;
+ }
+
} // end of namespace mln::level::impl::generic
@@ -157,6 +234,24 @@
return output;
}
+ template <typename I, typename J, typename F>
+ inline
+ mln_ch_value(I, mln_result(F))
+ transform(const Image<I>& ima1,
+ const Image<J>& ima2,
+ const Function_vv2v<F>& f)
+ {
+ trace::entering("level::transform");
+
+ mln_ch_value(I, mln_result(F)) output;
+ output = impl::generic::transform(exact(ima1), exact(ima2), exact(f));
+
+ trace::exiting("level::transform");
+
+ return output;
+
+ }
+
# endif // ! MLN_INCLUDE_ONLY
Index: branches/cleanup-2008/milena/mln/arith/all.hh
===================================================================
--- branches/cleanup-2008/milena/mln/arith/all.hh (revision 2823)
+++ branches/cleanup-2008/milena/mln/arith/all.hh (revision 2824)
@@ -54,6 +54,7 @@
}
+# include <mln/arith/diff_abs.hh>
# include <mln/arith/min.hh>
# include <mln/arith/minus.hh>
# include <mln/arith/plus.hh>
Index: branches/cleanup-2008/milena/mln/arith/diff_abs.hh
===================================================================
--- branches/cleanup-2008/milena/mln/arith/diff_abs.hh (revision 0)
+++ branches/cleanup-2008/milena/mln/arith/diff_abs.hh (revision 2824)
@@ -0,0 +1,86 @@
+// 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_ARITH_DIFF_ABS_HH
+# define MLN_ARITH_DIFF_ABS_HH
+
+/*! \file mln/arith/diff_abs.hh
+ *
+ * \brief Point-wise addition between images.
+ *
+ * \todo Speedup; some versions are not optimal.
+ */
+
+# include <mln/arith/includes.hh>
+# include <mln/fun/vv2v/diff_abs.hh>
+# include <mln/level/transform.hh>
+
+namespace mln
+{
+
+ namespace arith
+ {
+
+ /*! Point-wise absolute difference of images \p lhs and \p rhs.
+ *
+ * \param[in] lhs First operand image.
+ * \param[in] rhs Second operand image.
+ * \result The result image.
+ *
+ * \pre \p lhs.domain == \p rhs.domain
+ */
+ template <typename I>
+ mln_concrete(I)
+ diff_abs(const Image<I>& lhs, const Image<I>& rhs);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ diff_abs(const Image<I>& lhs, const Image<I>& rhs)
+ {
+ trace::entering("arith::diff_abs");
+ mln_precondition(exact(lhs).has_data());
+ mln_precondition(exact(rhs).has_data());
+ mln_precondition(exact(rhs).domain() == exact(lhs).domain());
+
+ mln_concrete(I) output = level::transform(lhs, rhs, fun::vv2v::diff_abs<mln_value(I)>());
+
+ trace::exiting("arith::diff_abs");
+ return output;
+ }
+
+ } // end of namespace mln::arith
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ARITH_DIFF_ABS_HH
Index: branches/cleanup-2008/milena/mln/fun/vv2v/diff_abs.hh
===================================================================
--- branches/cleanup-2008/milena/mln/fun/vv2v/diff_abs.hh (revision 0)
+++ branches/cleanup-2008/milena/mln/fun/vv2v/diff_abs.hh (revision 2824)
@@ -0,0 +1,78 @@
+// 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_FUN_VV2V_DIFF_ABS_HH
+# define MLN_FUN_VV2V_DIFF_ABS_HH
+
+/// \file mln/fun/vv2v/diff_abs.hh
+/// \brief Computing the absolute difference between two values using
+/// a functor.
+
+# include <mln/core/concept/function.hh>
+# include <mln/math/diff_abs.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace vv2v
+ {
+
+ // FIXME: Doc.
+
+ /// \brief A functor computing the diff_absimum of two values.
+ template <typename V>
+ struct diff_abs : public Function_vv2v< diff_abs<V> >
+ {
+ typedef V result;
+ V operator()(const V& v1, const V& v2) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ inline
+ V
+ diff_abs<V>::operator()(const V& v1, const V& v2) const
+ {
+ return mln::math::diff_abs(v1, v2);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::vv2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_VV2V_DIFF_ABS_HH
Index: branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh
===================================================================
--- branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh (revision 2823)
+++ branches/cleanup-2008/milena/mln/morpho/erosion.spe.hh (revision 2824)
@@ -295,12 +295,13 @@
const I& input = exact(input_);
- const unsigned len = win.length() / 3 + 1;
+ const unsigned len = (win.length() + 2) / 3;
- mln_concrete(I) temp_1, temp_2, output;
- temp_1 = morpho::erosion(input, win::hline2d(len));
- temp_2 = morpho::erosion(temp_1, win::diag2d(len));
- output = morpho::erosion(temp_2, win::backdiag2d(len));
+ mln_concrete(I) output;
+ output = morpho::erosion(input, win::hline2d(len));
+ output = morpho::erosion(output, win::vline2d(len));
+ output = morpho::erosion(output, win::diag2d(len));
+ output = morpho::erosion(output, win::backdiag2d(len));
trace::exiting("morpho::impl::erosion_(win::octagon2d)");
return output;