
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-08 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Update color for image_if and subimage. * color_sub.cc, * color_sub.hh: Update, uncomment FIXME when level::paste ready. Update chamfer. * canvas_chamfer.hh: New. * chamfer.cc, * chamfer.hh: Update. --- canvas_chamfer.hh | 98 ++++++++++++++++++++++++++ chamfer.cc | 27 +------ chamfer.hh | 197 ++++++++++++++++++++++++------------------------------ color_sub.cc | 8 +- color_sub.hh | 19 ++--- 5 files changed, 207 insertions(+), 142 deletions(-) Index: trunk/milena/sandbox/duhamel/color_sub.cc =================================================================== --- trunk/milena/sandbox/duhamel/color_sub.cc (revision 1265) +++ trunk/milena/sandbox/duhamel/color_sub.cc (revision 1266) @@ -54,10 +54,10 @@ { using namespace mln; - image2d_b<value::int_u8> ima(3,3); + + image2d_b<value::int_u8> ima(10,10); debug::iota(ima); - std::cout << ima.domain() << std::endl; - image2d_b<value::rgb8> out = color(inplace (ima | 6)); + image2d_b<value::rgb8> out = color(inplace (ima | 50)); io::ppm::save(out, "out.ppm"); - debug::println(out); + // debug::println(out); } Index: trunk/milena/sandbox/duhamel/chamfer.cc =================================================================== --- trunk/milena/sandbox/duhamel/chamfer.cc (revision 1265) +++ trunk/milena/sandbox/duhamel/chamfer.cc (revision 1266) @@ -1,34 +1,17 @@ #include <mln/core/image2d_b.hh> #include <mln/core/sub_image.hh> #include <mln/core/image_if_value.hh> -#include <mln/core/neighb2d.hh> #include <mln/core/inplace.hh> -#include <mln/value/int_u8.hh> #include <mln/level/fill.hh> -#include <mln/level/stretch.hh> -#include <mln/io/pbm/load.hh> -#include <mln/io/pgm/save.hh> -#include <mln/io/pgm/save.hh> -#include <mln/io/pgm/save.hh> -#include <mln/core/mesh_image.hh> -# include <mln/labeling/base.hh> # include <mln/debug/println.hh> -# include <mln/core/window2d.hh> # include <mln/core/w_window2d_int.hh> -# include <mln/convert/to_window.hh> -# include <mln/core/concept/dpoint.hh> -# include <mln/core/concept/neighborhood.hh> -# include <mln/core/window.hh> -# include <mln/pw/image.hh> -# include <mln/pw/cst.hh> -# include <mln/metal/is_a.hh> - +# include <mln/core/w_window2d_float.hh> # include <mln/core/image_if_interval.hh> +# include "win_chamfer.hh" #include "chamfer.hh" - int main() { using namespace mln; @@ -40,7 +23,7 @@ level::fill(ima, false); ima.at(4,4) = true; const w_window2d_int& w_win = win_chamfer::mk_chamfer_3x3_int<2, 0> (); - image2d_b<unsigned> out = chamfer(ima, w_win, max); + image2d_b<unsigned> out = geom::chamfer(ima, w_win, max); debug::println(out | value::interval(0, 8)); } @@ -48,7 +31,7 @@ level::fill(ima, false); ima.at(4,4) = true; const w_window2d_int& w_win = win_chamfer::mk_chamfer_3x3_int<2, 3> (); - image2d_b<unsigned> out = chamfer(ima, w_win, max); + image2d_b<unsigned> out = geom::chamfer(ima, w_win, max); debug::println(out | value::interval(0, 8)); } @@ -56,7 +39,7 @@ level::fill(ima, false); ima.at(4,4) = true; const w_window2d_int& w_win = win_chamfer::mk_chamfer_5x5_int<4, 6, 9> (); - image2d_b<unsigned> out = chamfer(ima, w_win, max); + image2d_b<unsigned> out = geom::chamfer(ima, w_win, max); image2d_b<unsigned>::fwd_piter p(out.domain()); for_all(p) out(p) = out(p) / 2; Index: trunk/milena/sandbox/duhamel/canvas_chamfer.hh =================================================================== --- trunk/milena/sandbox/duhamel/canvas_chamfer.hh (revision 0) +++ trunk/milena/sandbox/duhamel/canvas_chamfer.hh (revision 1266) @@ -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 Index: trunk/milena/sandbox/duhamel/color_sub.hh =================================================================== --- trunk/milena/sandbox/duhamel/color_sub.hh (revision 1265) +++ trunk/milena/sandbox/duhamel/color_sub.hh (revision 1266) @@ -25,7 +25,7 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/sub_image.hh +/*! \file ?/sub_image.hh * * \brief . */ @@ -34,30 +34,31 @@ #include <mln/core/image2d_b.hh> #include <mln/value/rgb8.hh> #include <mln/level/fill.hh> +#include <mln/level/paste.hh> + + +#include <mln/trait/image_from_mesh.hh> namespace mln { + template <typename I> - mln_ch_value (I, value::rgb8) + typename trait::image_from_mesh < mln_mesh(I), value::rgb8 >::ret color (const Image<I>& input_) { const I& input = exact (input_); - mln_ch_value(I, value::rgb8) output; - initialize(output, input); - - // image2d_b<value::rgb8> output(ima.domain ().bbox ()); - + image2d_b<value::rgb8> output(input.domain().bbox()); level::fill (output, value::rgb8(255, 0, 0)); +// /// FIXME by : +// level::paste(input, output); { mln_piter(I) p (input.domain ()); for_all (p) - { output(p) = value::rgb8(input(p)); } - } return output; } } Index: trunk/milena/sandbox/duhamel/chamfer.hh =================================================================== --- trunk/milena/sandbox/duhamel/chamfer.hh (revision 1265) +++ trunk/milena/sandbox/duhamel/chamfer.hh (revision 1266) @@ -1,143 +1,126 @@ -# include <mln/core/image2d_b.hh> -# include <mln/core/sub_image.hh> -# include <mln/core/image_if_value.hh> -# include <mln/core/neighb2d.hh> -# include <mln/core/inplace.hh> +// 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/value/int_u8.hh> # include <mln/level/fill.hh> -# include <mln/level/stretch.hh> -# include <mln/io/pbm/load.hh> -# include <mln/io/pgm/save.hh> -# include <mln/io/pgm/save.hh> -# include <mln/io/pgm/save.hh> -# include <mln/core/mesh_image.hh> -# include <mln/labeling/base.hh> -# include <mln/debug/println.hh> -# include <mln/core/window2d.hh> # include <mln/core/w_window2d_int.hh> # include <mln/core/w_window2d_float.hh> -# include <mln/convert/to_window.hh> -# include <mln/core/concept/dpoint.hh> -# include <mln/core/concept/neighborhood.hh> -# include <mln/core/window.hh> -# include <mln/pw/image.hh> -# include <mln/pw/cst.hh> -# include <mln/metal/is_a.hh> - -# include <mln/core/image_if_interval.hh> -# include <mln/core/dpoint2d.hh> -# include <math.h> + +# include "canvas_chamfer.hh" namespace mln { - namespace win_chamfer - { - template<int d10, int d11> - const w_window2d_int - mk_chamfer_3x3_int() + namespace geom { - 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 }; + 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 (make::w_window2d(ws)); - } +# ifndef MLN_INCLUDE_ONLY - const w_window2d_float - mk_chamfer_3x3_float(float d10, float d11) + namespace impl { - float ws[] = { d11, d10, d11, - d10, 0, 0, - 0, 0, 0 }; - return (make::w_window2d(ws)); - } + // Functors. - const w_window2d_float - mk_chamfer_5x5_float(float d10, float d11, float d21) + template <typename I_, typename W_> + struct chamfer_t { - 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 }; + typedef I_ I; + typedef W_ W; + typedef mln_point(I_) P; - return (make::w_window2d(ws)); - } + // requirements from mln::canvas::chamfer: - const w_window2d_float - mk_chamfer_exact() - { - float r2 = sqrt(2); - float ws[] = { r2, 1, r2, - 1, 0, 0, - 0, 0, 0 }; + const I& input; + const W& win; - return (make::w_window2d(ws)); - } + 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) + {} + }; - } // end of mln::win_chamfer + // Routines. template <typename I, typename W> mln_ch_value(I, unsigned) - chamfer(const Image<I>& input_, const Weighted_Window<W>& w_win_, + chamfer_(const Image<I>& input_, const W& w_win_, unsigned max = mln_max(unsigned)) { - const I& input = exact(input_); - const W& w_win = exact(w_win_); + typedef chamfer_t<I, W> F; - mln_ch_value(I, unsigned) output; - initialize(output, input); - - /// Init. - { - level::fill(inplace(output | (input | true).domain()), 0); - level::fill(inplace(output | (input | false).domain()), max); + F f(exact(input_), exact(w_win_), max); + canvas::chamfer<F> run(f); + return f.output; } - /// Fwd pass. - { - mln_fwd_piter(I) p(input.domain()); - mln_qiter(W) q(w_win, p); + } // end of namespace mln::geom::impl - for_all(p) if (input(p) == false) - for_all(q) if (input.has(q)) - if (output(q) != max - && output(q) + q.w() < output(p)) - output(p) = output(q) + q.w(); - } - - /// Bkd pass. - { +#endif // !MLN_INCLUDE_ONLY - W w_win_b = geom::sym(w_win); - mln_bkd_piter(I) p(input.domain()); - mln_qiter(W) q(w_win_b, p); + // Facade. - for_all(p) if (input(p) == false) - for_all(q) if (input.has(q)) - if (output(q) != max - && output(q) + q.w() < output(p)) - output(p) = output(q) + q.w(); + 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); } - return output; - } -} // end of mln + } // end of namespace mln::geom + +} // end of namespace mln + +#endif // !MLN_GEOM_CHAMFER_HH