
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-04 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Add chamfer in sadbox. * chamfer.cc: New. * color_sub.cc: . * color_sub.hh: New : split ols version. * labeling_algo.cc: . * labeling_level_fast.cc: . --- chamfer.cc | 134 +++++++++++++++++++++++++++++++++++++++++++++++++ color_sub.cc | 23 -------- color_sub.hh | 60 +++++++++++++++++++++ labeling_algo.cc | 20 ++----- labeling_level_fast.cc | 11 +--- 5 files changed, 205 insertions(+), 43 deletions(-) Index: trunk/milena/sandbox/duhamel/labeling_algo.cc =================================================================== --- trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 1240) +++ trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 1241) @@ -36,15 +36,14 @@ # include <mln/value/int_u8.hh> # include <mln/level/fill.hh> # include <mln/level/stretch.hh> -# include <mln/level/saturate.hh> # include <mln/border/fill.hh> # include <mln/io/pbm/load.hh> # include <mln/io/pgm/save.hh> # include <mln/labeling/foreground.hh> # include <mln/debug/println.hh> -# include <mln/debug/println_with_border.hh> # include <mln/draw/mesh.hh> -# include "labeling_algo.hh" +# include <mln/geom/seeds2tiling.hh> +# include <mln/make/voronoi.hh> int main() { @@ -52,7 +51,7 @@ using value::int_u8; // image2d_b<bool> in = io::pbm::load("../../img/toto.pbm"); - image2d_b<bool> in = io::pbm::load("test.pbm"); + image2d_b<bool> in = io::pbm::load("toto.pbm"); image2d_b<int_u8> lab(in.domain()); image2d_b<int_u8> inte(in.domain()); @@ -64,28 +63,21 @@ std::vector<int_u8> vec; image2d_b<int> input(in.domain()); - // debug::println (in | make::box2d (100,100)); level::fill(input, lab); lab(make::point2d (0,0)) = 0; - inte = make_algo(lab, c4 ()); + inte = geom::seeds2tiling(lab, c4 ()); border::fill (inte, 0); image2d_b<int_u8> inte2(inte.domain()); level::stretch (inte, inte2); - io::pgm::save(inte, "inte.pgm"); - io::pgm::save(inte2, "inte2.pgm"); - - debug::println(lab | make::box2d (30,30) ); - - // mesh_p<point2d> m = make::graph_with_no_border(inte, c4()); + io::pgm::save(inte2, "inte.pgm"); mesh_p<point2d> m = make::voronoi(inte, lab, c4()); - std::cout << "OK" << std::endl; + std::cout << "OK : generate inte.pgm and out.pgm" << std::endl; draw::mesh (out, m, 255, 128); - // debug::println(out); io::pgm::save(out, "out.pgm"); } Index: trunk/milena/sandbox/duhamel/color_sub.cc =================================================================== --- trunk/milena/sandbox/duhamel/color_sub.cc (revision 1240) +++ trunk/milena/sandbox/duhamel/color_sub.cc (revision 1241) @@ -48,26 +48,7 @@ #include <mln/core/image_if_value.hh> #include <mln/debug/iota.hh> -namespace mln -{ - template <typename I, typename J> - void - color (Image<I>& ima_, Image<J>& out_) - { - I& ima = exact (ima_); - J& out = exact (out_); - - level::fill (out, value::rgb8(255, 0, 0)); - - { - mln_piter(I) p (ima.domain ()); - for_all (p) - { - out(p) = value::rgb8(ima(p)); - } - } - } -} +#include "color_sub.hh" int main() { @@ -75,8 +56,8 @@ image2d_b<value::int_u8> ima(3,3); debug::iota(ima); - image2d_b<value::rgb8> out(ima.domain ().bbox ()); std::cout << ima.domain() << std::endl; + image2d_b<value::rgb8> out(ima.domain ().bbox ()); color(inplace (ima | 6), out); io::ppm::save(out, "out.ppm"); debug::println(out); Index: trunk/milena/sandbox/duhamel/chamfer.cc =================================================================== --- trunk/milena/sandbox/duhamel/chamfer.cc (revision 0) +++ trunk/milena/sandbox/duhamel/chamfer.cc (revision 1241) @@ -0,0 +1,134 @@ +#include <mln/core/image2d_b.hh> +#include <mln/core/sub_image.hh> +#include <mln/core/neighb2d.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/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> + + + +namespace mln +{ + namespace convert + { +// template <typename N> +// window<mln_dpoint(N)> to_upper_window(const Neighborhood<N>& nbh_) +// { +// const N& nbh = exact(nbh_); +// typedef mln_dpoint(N) D; +// typedef mln_point(D) P; +// window<D> win; +// mln_niter(N) n(nbh, P::zero); +// for_all(n) +// if (n > P::zero) +// win.insert(n - P::zero); +// return win; +// } + + template <typename N> + window<mln_dpoint(N)> to_lower_window(const Neighborhood<N>& nbh_) + { + const N& nbh = exact(nbh_); + typedef mln_dpoint(N) D; + typedef mln_point(D) P; + window<D> win; + mln_niter(N) n(nbh, P::zero); + for_all(n) + if (n < P::zero) + win.insert(n - P::zero); + return win; + } + + } // end of namespace convert + + template <typename I, typename N, typename J> + void + chamfer (Image<I>& ima_, const Neighborhood<N>& nbh_, + mln_point(I)& point, unsigned max, Image<J>& out_) + { + I& ima = exact (ima_); + J& out = exact (out_); + + typedef window<mln_dpoint(I)> W; + + /// Init. + { + level::fill (out, max); + out(point) = 0; + } + + /// Fwd pass. + { + mln_fwd_piter (I) p (ima.domain ()); + p = point; + W win = convert::to_upper_window(nbh_); + mln_qiter(W) n(win, p); + + for_all (p) + { + for_all (n) + { + if (out(n) > out(p) + 1) + out(n) = out(p) + 1; + } + } + } + + /// Bkd pass. + { + mln_bkd_piter (I) p (ima.domain ()); + W win = convert::to_lower_window(nbh_); + mln_qiter(W) n( win, p); + + for_all (p) + { + for_all (n) + { + if (out(n) > out(p) + 1) + out(n) = out(p) + 1; + } + } + } + } +} // end of mln + +int main () +{ + using namespace mln; + using value::int_u8; + + { + image2d_b<int_u8> ima (9, 9); + image2d_b<unsigned> out (ima.domain ()); + point2d p = make::point2d(4,4); + + chamfer (ima, c4(), p, 255, out); + debug::println (out); + } + + + + { + image2d_b<int_u8> ima (1000, 1000); + image2d_b<unsigned> out (ima.domain ()); + point2d p = make::point2d(4,4); + + chamfer (ima, c4(), p, 255, out); + } + // debug::println (out); +} Index: trunk/milena/sandbox/duhamel/labeling_level_fast.cc =================================================================== --- trunk/milena/sandbox/duhamel/labeling_level_fast.cc (revision 1240) +++ trunk/milena/sandbox/duhamel/labeling_level_fast.cc (revision 1241) @@ -40,11 +40,7 @@ #include <mln/io/pgm/save.hh> #include <mln/labeling/level.hh> #include <mln/debug/iota.hh> -#include <mln/debug/println_with_border.hh> - -#include "paste.hh" -#include "fill.hh" - +#include <mln/debug/println.hh> int main() { @@ -56,12 +52,11 @@ image2d_b<value::int_u8> i1(5, 5, border); debug::iota(i1); i1[10] = i1[17] = i1[18] = i1[25] = i1[26] = i1[22] = i1[29] = 2; - // i1[5] = i1[6] = 2; - debug::println_with_border(i1); + debug::println(i1); unsigned n; image2d_b<value::int_u8> out(i1.domain(), border); - labeling_level_fast(i1, 2, c4(), out, n); + labeling::level_fast(i1, 2, c4(), out, n); std::cout << "n = " << n << std::endl; debug::println(out); Index: trunk/milena/sandbox/duhamel/color_sub.hh =================================================================== --- trunk/milena/sandbox/duhamel/color_sub.hh (revision 0) +++ trunk/milena/sandbox/duhamel/color_sub.hh (revision 1241) @@ -0,0 +1,60 @@ +// 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/sub_image.hh + * + * \brief . + */ + +#include <mln/core/image_if_value.hh> +#include <mln/core/image2d_b.hh> +#include <mln/value/rgb8.hh> +#include <mln/level/fill.hh> + +namespace mln +{ + template <typename I, typename J> + void + color (Image<I>& ima_ , Image<J>& out_) + { + I& ima = exact (ima_); + J& out = exact (out_); + // image2d_b<value::rgb8> out(ima.domain ().bbox ()); + + level::fill (out, value::rgb8(255, 0, 0)); + + { + mln_piter(I) p (ima.domain ()); + + for_all (p) + { + out(p) = value::rgb8(ima(p)); + } + } + // return out; + } +}