milena r2824: Fix erosion on octogone, add arith::diff_abs

URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena ChangeLog: 2008-11-06 Matthieu Garrigues <garrigues@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;
participants (1)
-
Matthieu Garrigues