milena r1214: Add algorithm for extend labeling (slow 3min for this test)

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-01 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Add algorithm for extend labeling (slow 3min for this test). * labeling_algo.cc: New. * labeling_algo.hh: New. Update. * graph_labeling.hh: Update. --- graph_labeling.hh | 2 - labeling_algo.cc | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ labeling_algo.hh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 1 deletion(-) Index: trunk/milena/sandbox/duhamel/graph_labeling.hh =================================================================== --- trunk/milena/sandbox/duhamel/graph_labeling.hh (revision 1213) +++ trunk/milena/sandbox/duhamel/graph_labeling.hh (revision 1214) @@ -14,7 +14,7 @@ namespace mln { - template <typename I, typename N, typename T> + template <typename I, typename N> mesh_p<point2d>* make_graph (Image<I>& ima_, const Neighborhood<N>& nbh) Index: trunk/milena/sandbox/duhamel/labeling_algo.cc =================================================================== --- trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 0) +++ trunk/milena/sandbox/duhamel/labeling_algo.cc (revision 1214) @@ -0,0 +1,62 @@ +// 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/labeling_foreground.cc + * + * \brief Test on mln::labeling::foreground. + */ + +# 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/io/pbm/load.hh> +# include <mln/labeling/foreground.hh> +# include <mln/debug/println.hh> +# include "labeling_algo.hh" + +int main() +{ + using namespace mln; + using value::int_u8; + + image2d_b<bool> in = io::pbm::load("../../img/toto.pbm"); + image2d_b<unsigned> lab(in.domain()); + image2d_b<unsigned> out(in.domain()); + + unsigned n; + labeling::foreground(in, c4(), lab, n); + std::cout << n << std::endl; + + image2d_b<int> input(in.domain()); + level::fill(input, lab); + + debug::println(lab | make::box2d(50, 30)); + out = make_algo (lab, c4 ()); + debug::println(out | make::box2d(50, 30)); +} Index: trunk/milena/sandbox/duhamel/labeling_algo.hh =================================================================== --- trunk/milena/sandbox/duhamel/labeling_algo.hh (revision 0) +++ trunk/milena/sandbox/duhamel/labeling_algo.hh (revision 1214) @@ -0,0 +1,63 @@ +# include <mln/core/queue_p.hh> +# include <mln/core/clone.hh> + +namespace mln +{ + template <typename I, typename N> + I + make_algo (Image<I>& ima_, + const Neighborhood<N>& nbh) + { + I& ima = exact(ima_); + I out = clone(ima_); + queue_p<mln_point (I)> q; + int i; + + // init + { + mln_fwd_piter(I) p(ima.domain()); + mln_niter(N) n(nbh, p); + + for_all (p) + { + if (ima(p) == 0) + for_all(n) + if (ima(n) != 0) + { + q.push (p); + goto end; + } + end: + i = 0; + } + } + + std::cout << "q points = " + << q.npoints () + << std::endl; + //body + { + while (q.npoints ()) + { + + mln_point (I) po = q.front (); + q.pop (); + mln_invariant (ima(po) == 0); + + mln_niter(N) ne(nbh, po); + for_all (ne) + { + if (ima.has(ne)) + { + if (out(ne) != 0) + out(po) = out (ne); + else + if (!q.has (ne)) + q.push (ne); + } + } + } + } + return out; + } +}
participants (1)
-
Guillaume Duhamel