
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-04 Simon Nivault <simon.nivault@lrde.epita.fr> Add best canvas and make median_dir use it. * mln/canvas/browsing/dir_ricard51.hh: New canvas. * mln/canvas/browsing/directional.hh: Fix some names. * mln/level/median.hh: Use new canvas. * tests/level_median_dir.cc: New. --- mln/canvas/browsing/dir_ricard51.hh | 173 ++++++++++++++++++++++++++++++++++++ mln/canvas/browsing/directional.hh | 8 - mln/level/median.hh | 63 +++---------- tests/level_median_dir.cc | 55 +++++++++++ 4 files changed, 248 insertions(+), 51 deletions(-) Index: trunk/milena/tests/level_median_dir.cc =================================================================== --- trunk/milena/tests/level_median_dir.cc (revision 0) +++ trunk/milena/tests/level_median_dir.cc (revision 1239) @@ -0,0 +1,55 @@ +// 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/level_median.cc + * + * \brief Test on mln::level::median. + */ + +#include <mln/core/image2d_b.hh> + +#include <mln/io/pgm/load.hh> +#include <mln/io/pgm/save.hh> + +#include <mln/value/int_u8.hh> +#include <mln/level/median.hh> + + +int main() +{ + using namespace mln; + using value::int_u8; + + border::thickness = 7; + + image2d_b<int_u8> + lena = io::pgm::load("../img/lena.pgm"), + out(lena.domain()); + + level::median_dir(lena, 1, 15, out); + io::pgm::save(out, "out.pgm"); +} Index: trunk/milena/mln/level/median.hh =================================================================== --- trunk/milena/mln/level/median.hh (revision 1238) +++ trunk/milena/mln/level/median.hh (revision 1239) @@ -41,7 +41,7 @@ # include <mln/set/diff.hh> # include <mln/canvas/browsing/snake_fwd.hh> -# include <mln/canvas/browsing/directional.hh> +# include <mln/canvas/browsing/dir_ricard51.hh> # include <mln/accu/median.hh> @@ -190,11 +190,6 @@ // aux data mln_point(I) p; - const mln_point(I) - pmin, pmax; - const mln_coord(I) - pmin_dir, pmax_dir, - pmin_dir_plus, pmax_dir_minus; accu::median<mln_vset(I)> med; // ctor @@ -206,12 +201,6 @@ output(exact(output)), // aux data p(), - pmin(input.domain().pmin()), - pmax(input.domain().pmax()), - pmin_dir(pmin[dir]), - pmax_dir(pmax[dir]), - pmin_dir_plus (pmin[dir] + length / 2), - pmax_dir_minus(pmax[dir] - length / 2), med(input.values()) { } @@ -220,55 +209,26 @@ { } - void next() + void init_line() { - mln_point(I) - p = this->p, - pt = p, - pu = p; - - typedef mln_coord(I)& coord_ref; - coord_ref - ct = pt[dir], - cu = pu[dir], - p_dir = p[dir]; - - // initialization (before first point of the row) med.init(); - for (ct = pmin_dir; ct < pmin_dir_plus; ++ct) - if (input.has(pt)) - med.take(input(pt)); + } - // left columns (just take new points) - for (p_dir = pmin_dir; p_dir <= pmin_dir_plus; ++p_dir, ++ct) + void add_point(mln_point(I) pt) { - if (input.has(pt)) med.take(input(pt)); - if (output.has(p)) - output(p) = med.to_result(); } - // middle columns (both take and untake) - cu = pmin[dir]; - for (; p_dir <= pmax_dir_minus; ++cu, ++p_dir, ++ct) + void remove_point(mln_point(I) pu) { - if (input.has(pt)) - med.take(input(pt)); - if (input.has(pu)) med.untake(input(pu)); - if (output.has(p)) - output(p) = med.to_result(); } - // right columns (now just untake old points) - for (; p_dir <= pmax_dir; ++cu, ++p_dir) + void next() { - if (input.has(pu)) - med.untake(input(pu)); if (output.has(p)) output(p) = med.to_result(); } - } void final() { @@ -282,7 +242,7 @@ void median_dir_(const Image<I>& input, unsigned dir, unsigned length, O& output) { median_dir_t<I,O> f(exact(input), dir, length, output); - canvas::browsing::directional(f); + canvas::browsing::dir_ricard51(f); } @@ -330,11 +290,20 @@ void median_dir(const Image<I>& input, unsigned dir, unsigned length, Image<O>& output) { + trace::entering("level::median_dir"); + + mlc_is(mln_trait_image_io(O), trait::io::write)::check(); + mlc_is(mln_trait_image_support(I), trait::support::aligned)::check(); + mlc_converts_to(mln_value(I), mln_value(O))::check(); + mln_precondition(exact(output).domain() == exact(input).domain()); typedef mln_point(I) P; mln_precondition(dir < P::dim); mln_precondition(length % 2 == 1); + impl::median_dir_(exact(input), dir, length, exact(output)); + + trace::exiting("level::median_dir"); } # endif // ! MLN_INCLUDE_ONLY Index: trunk/milena/mln/canvas/browsing/dir_ricard51.hh =================================================================== --- trunk/milena/mln/canvas/browsing/dir_ricard51.hh (revision 0) +++ trunk/milena/mln/canvas/browsing/dir_ricard51.hh (revision 1239) @@ -0,0 +1,173 @@ +// 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_DIR_RICARD51_HH +# define MLN_CANVAS_DIR_RICARD51_HH + +/*! \file mln/canvas/dir_ricard51.hh + * + * \brief Dir_Ricard51 browsing of an image. + */ + +# include <mln/core/concept/browsing.hh> +# include <mln/core/concept/image.hh> + +namespace mln +{ + + namespace canvas + { + + namespace browsing + { + + /*! FIXME : DOC + * F shall features : \n + * { \n + * --- as types: \n + * I; \n + * --- as attributes: \n + * dim; \n + * dir; // and test dir < dim \n + * input; \n + * p; \n + * length; \n + * --- as methods: \n + * void init(); \n + * void init_line(); \n + * void add_point(p) \n + * void remove_point(p) \n + * void next(); \n + * void final(); \n + * } \n + * + */ + struct dir_ricard51_t : public Browsing< dir_ricard51_t > + { + template <typename F> + void operator()(F& f) const; + } + + dir_ricard51; + +# ifndef MLN_INCLUDE_ONLY + + template <typename F> + void + dir_ricard51_t::operator()(F& f) const + { + mln_precondition(f.dir < f.dim); + typedef typename F::I I; + + const mln_point(I) + pmin = f.input.domain().pmin(), + pmax = f.input.domain().pmax(); + + const mln_coord(I) + pmin_dir = pmin[f.dir], + pmax_dir = pmax[f.dir], + pmin_dir_plus_half_length = pmin_dir + f.length / 2, + pmax_dir_minus_half_length = pmax_dir - f.length / 2; + + mln_point(I) pt, pu; + + typedef mln_coord(I)& coord_ref; + coord_ref + ct = pt[f.dir], + cu = pu[f.dir], + p_dir = f.p[f.dir]; + + f.p = pmin; + + f.init(); + + do + { + pt = f.p; + pu = f.p; + + f.init_line(); + + // initialization (before first point of the line) + for (ct = pmin_dir; ct < pmin_dir_plus_half_length; ++ ct) + if (f.input.has(pt)) + f.add_point(pt); + + // left columns (just take new points) + for (p_dir = pmin_dir; p_dir <= pmin_dir_plus_half_length; ++p_dir, ++ct) + { + if (f.input.has(pt)) + f.add_point(pt); + f.next(); + } + + // middle columns (both take and untake) + cu = pmin_dir; + for (; p_dir <= pmax_dir_minus_half_length; ++cu, ++p_dir, ++ct) + { + if (f.input.has(pt)) + f.add_point(pt); + if (f.input.has(pu)) + f.remove_point(pu); + f.next(); + } + + // right columns (now just untake old points) + for (; p_dir <= pmax_dir; ++cu, ++p_dir) + { + if (f.input.has(pu)) + f.remove_point(pu); + f.next(); + } + + p_dir = pmin_dir; + + for (int c = F::dim - 1; c >= 0; --c) + { + if (c == int(f.dir)) + continue; + if (f.p[c] != pmax[c]) + { + ++f.p[c]; + break; + } + f.p[c] = pmin[c]; + } + } while (f.p != pmin); + + f.final(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::canvas::browsing + + } // end of namespace mln::canvas + +} // end of namespace mln + +#endif // ! MLN_CANVAS_DIR_RICARD51_HH Index: trunk/milena/mln/canvas/browsing/directional.hh =================================================================== --- trunk/milena/mln/canvas/browsing/directional.hh (revision 1238) +++ trunk/milena/mln/canvas/browsing/directional.hh (revision 1239) @@ -25,10 +25,10 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_CANVAS_DIRBROWSING_HH -# define MLN_CANVAS_DIRBROWSING_HH +#ifndef MLN_CANVAS_DIRECTIONAL_HH +# define MLN_CANVAS_DIRECTIONAL_HH -/*! \file mln/canvas/dirbrowsing.hh +/*! \file mln/canvas/browsing/directional.hh * * \brief Directional browsing of an image. */ @@ -115,4 +115,4 @@ } // end of namespace mln -#endif // ! MLN_CANVAS_DIRBROWSING_HH +#endif // ! MLN_CANVAS_DIRECTIONAL_HH