milena r1260: Add canvas for chamfer

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-05 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Add canvas for chamfer. * canvas/chamfer.hh: New canvas for chamfer. * geom/chamfer.hh: New. * make/win_chamfer.hh: New. --- canvas/chamfer.hh | 98 ++++++++++++++++++++++++++++++++++++++++ geom/chamfer.hh | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++ make/win_chamfer.hh | 69 ++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+) Index: trunk/milena/mln/make/win_chamfer.hh =================================================================== --- trunk/milena/mln/make/win_chamfer.hh (revision 0) +++ trunk/milena/mln/make/win_chamfer.hh (revision 1260) @@ -0,0 +1,69 @@ +# include <mln/core/w_window2d_int.hh> +# include <mln/core/w_window2d_float.hh> +# include <math.h> + +namespace mln +{ + namespace win_chamfer + { + + template<int d10, int d11> + const w_window2d_int + mk_chamfer_3x3_int() + { + int ws[] = { d11, d10, d11, + d10, 0, 0, + 0, 0, 0 }; + + return (make::w_window2d(ws)); + } + + template<int d10, int d11, int d21> + const w_window2d_int + mk_chamfer_5x5_int() + { + int ws[] = { 0, d21, 0, d21, 0, + d21, d11, d10, d11, d21, + 0, d10, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0 }; + + return (make::w_window2d(ws)); + } + + const w_window2d_float + mk_chamfer_3x3_float(float d10, float d11) + { + float ws[] = { d11, d10, d11, + d10, 0, 0, + 0, 0, 0 }; + + return (make::w_window2d(ws)); + } + + const w_window2d_float + mk_chamfer_5x5_float(float d10, float d11, float d21) + { + float ws[] = { 0, d21, 0, d21, 0, + d21, d11, d10, d11, d21, + 0, d10, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0 }; + + return (make::w_window2d(ws)); + } + + const w_window2d_float + mk_chamfer_exact() + { + float r2 = sqrt(2); + float ws[] = { r2, 1, r2, + 1, 0, 0, + 0, 0, 0 }; + + return (make::w_window2d(ws)); + } + + } // end of mln::win_chamfer + +} // end of mln Index: trunk/milena/mln/geom/chamfer.hh =================================================================== --- trunk/milena/mln/geom/chamfer.hh (revision 0) +++ trunk/milena/mln/geom/chamfer.hh (revision 1260) @@ -0,0 +1,126 @@ +// 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_GEOM_CHAMFER_HH +# define MLN_GEOM_CHAMFER_HH + +/*! \file mln/geom/chamfer.hh + * + * \brief Connected component chamfer of the image objects. + */ + +# include <mln/level/fill.hh> +# include <mln/core/w_window2d_int.hh> +# include <mln/core/w_window2d_float.hh> + +# include <mln/canvas/chamfer.hh> + +namespace mln +{ + + namespace geom + { + + + template <typename I, typename W> + mln_ch_value( I, unsigned ) + chamfer(const Image<I>& input_, const W& w_win_, + unsigned max = mln_max(unsigned)); + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + // Functors. + + template <typename I_, typename W_> + struct chamfer_t + { + typedef I_ I; + typedef W_ W; + typedef mln_point(I_) P; + + // requirements from mln::canvas::chamfer: + + const I& input; + const W& win; + + mln_ch_value(I_, unsigned) output; + bool status; + unsigned max; + + void init() { initialize(output, exact(input)); + level::fill(inplace(output | (input | true).domain()), 0); + level::fill(inplace(output | (input | false).domain()), max); } + bool handles(const P& p) const { return input(p) == false; } + + // end of requirements + + chamfer_t(const I_& input, const W_& win, unsigned max) + : input (input), + win (win), + max (max) + {} + }; + + // Routines. + + template <typename I, typename W> + mln_ch_value(I, unsigned) + chamfer_(const Image<I>& input_, const W& w_win_, + unsigned max = mln_max(unsigned)) + { + typedef chamfer_t<I, W> F; + + F f(exact(input_), exact(w_win_), max); + canvas::chamfer<F> run(f); + return f.output; + } + + } // end of namespace mln::geom::impl + +#endif // !MLN_INCLUDE_ONLY + + + // Facade. + + template <typename I, typename W> + mln_ch_value(I, unsigned) + chamfer(const Image<I>& input_, const W& w_win_, + unsigned max = mln_max(unsigned)) + { + return impl::chamfer_(exact (input_), exact(w_win_), max); + } + + + } // end of namespace mln::geom + +} // end of namespace mln + +#endif // !MLN_GEOM_CHAMFER_HH Index: trunk/milena/mln/canvas/chamfer.hh =================================================================== --- trunk/milena/mln/canvas/chamfer.hh (revision 0) +++ trunk/milena/mln/canvas/chamfer.hh (revision 1260) @@ -0,0 +1,98 @@ +// 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_CHAMFER_HH +# define MLN_CANVAS_CHAMFER_HH + +/*! \file mln/canvas/chamfer.hh + * + * \brief Connected component chamfer of the object part in a binary + * image. + */ + +namespace mln +{ + namespace canvas + { + + template <typename F> + struct chamfer + { + F& f; + + typedef typename F::I I; + typedef typename F::W W; + typedef mln_point(I) point; + + chamfer(F& f) + : f(f) + { + run(); + } + + void run() + { + /// Init. + { + f.init(); + } + + /// Fwd pass. + { + mln_fwd_piter(I) p(f.input.domain()); + mln_qiter(W) q(f.win, p); + + for_all(p) if (f.handles (p)) + for_all(q) if (f.input.has(q)) + if (f.output(q) != f.max + && f.output(q) + q.w() < f.output(p)) + f.output(p) = f.output(q) + q.w(); + } + + /// Bkd pass. + { + W w_win_b = geom::sym(f.win); + + mln_bkd_piter(I) p(f.input.domain()); + mln_qiter(W) q(w_win_b, p); + + for_all(p) if (f.handles (p)) + for_all(q) if (f.input.has(q)) + if (f.output(q) != f.max + && f.output(q) + q.w() < f.output(p)) + f.output(p) = f.output(q) + q.w(); + f.status = true; + } + + } + }; + + } // end of mln::canvas + +} // end of mln + +#endif // ! MLN_CANVAS_CHAMFER_HH
participants (1)
-
Guillaume Duhamel