
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Attribute filtering v3. * jardonnet/n_cmpt/n_cmpt3.hh: Make use of an image of set. * jardonnet/n_cmpt/n_cmpt3.cc: New. * jardonnet/n_cmpt/Makefile: Add rule. * jardonnet/n_cmpt/check/test4.pgm: New test image. Makefile | 6 + n_cmpt3.cc | 37 ++++++++++ n_cmpt3.hh | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 247 insertions(+), 2 deletions(-) Index: jardonnet/n_cmpt/n_cmpt3.hh --- jardonnet/n_cmpt/n_cmpt3.hh (revision 0) +++ jardonnet/n_cmpt/n_cmpt3.hh (revision 0) @@ -0,0 +1,206 @@ +// Copyright (C) 2008 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_N_CMPT3_HH +# define MLN_N_CMPT3_HH + +# include <mln/labeling/regional_minima.hh> +# include <mln/core/alias/neighb2d.hh> +# include <mln/util/set.hh> + +# include <mln/debug/println.hh> + +# include <mln/accu/volume.hh> +# include <mln/morpho/tree/data.hh> +# include <mln/morpho/tree/compute_attribute_image.hh> + +namespace mln +{ + + namespace n_cmpt + { + + template < typename I > + void n_cmpt3(const I& (((((((ima)))))))); + +# ifndef MLN_INCLUDE_ONLY + + template<typename I> + mln_ch_value(I, util::set<mln_psite(I)>) + minima_sets(const I& ima) + { + mln_ch_value(I, util::set<mln_psite(I)>) ima_set(ima.domain()); + + mln_piter(I) p(ima.domain()); + for_all(p) + { + if (ima(p) != literal::zero) + ima_set(p).insert(p); + } + return ima_set; + } + + template <typename I> + inline + mln_psite(I) + find_root(I& parent, + const mln_psite(I)& x) + { + if (parent(x) == x) + return x; + else + return parent(x) = find_root(parent, parent(x)); + } + + template < typename I > + unsigned count_minima(const I& ima) + { + unsigned cmpt = 0; + mln_piter(I) p(ima.domain()); + for_all(p) + { + if (ima(p) != literal::zero) + cmpt++; + } + return cmpt; + } + + template < typename I, typename N> + I + n_cmpt3(const I& ima, const N& nbh, + unsigned lambda) + { + unsigned label; + + // get /ima/ regional minima + mln_ch_value(I, unsigned) min = labeling::regional_minima(ima, nbh, label); + std::cout << "/ima/ regional minima" << std::endl; + debug::println(min); + + // compute volume image + typedef p_array<mln_psite(I)> S; + typedef image2d<unsigned> V; + typedef accu::volume<I> A; + S sp = level::sort_psites_decreasing(ima); + morpho::tree::data<I,S> t(ima, sp, nbh); + V volume = morpho::tree::compute_attribute_image(A(), t); + + // get /volume/ regional minima + mln_ch_value(I, unsigned) min_v = labeling::regional_minima(volume, nbh, label); + std::cout << "/volume/ regional minima" << std::endl; + debug::println(min_v); + + // tester minima de ima == minima de attr + //mln_assertion(min == min_v); + + mln_ch_value(I, util::set<mln_psite(I)>) ima_set = minima_sets(volume); + + // number of minima + int cmpts = count_minima(min_v); + + std::cout << "Nb of regionnal minima : " << cmpts << std::endl; + + // prepare union find + typedef mln_psite(V) P; + mln_ch_value(V, bool) deja_vu; + initialize(deja_vu, ima); + mln_ch_value(V, P) parent; + initialize(parent, ima); + mln_ch_value(V, A) data; + initialize(data, ima); + mln::level::fill(deja_vu, false); + { + mln_fwd_piter(S) p(sp); + for_all(p) + parent(p) = p; + } + + // union find sur volume + mln_fwd_piter(S) p(sp); + mln_niter(N) n(nbh, p); + for_all(p) + { + // Make set. + data(p).take_as_init(make::pix(ima, p)); + for_all(n) + { + if (volume.domain().has(n) && deja_vu(n)) + { + //do_union(n, p); + P r = find_root(parent, n); + if (r != p) + { + if (ima(r) != ima(p) && (data(p).to_result() > lambda)) + { + data(p).set_value(lambda); + continue; + } + + if (ima(r) != ima(p)) + { + std::cout << "1: ima(r) != ima(p)" << std::endl; + if (not ima_set(p).is_empty()) + { + std::cout << "2: not ima_set(p).is_empty()" << std::endl; + if (ima_set(p) != ima_set(r)) + { + std::cout << "3: ima_set(p) != ima_set(r)" << std::endl; + cmpts--; + } + } + } + ima_set(p).insert(ima_set(r)); + parent(r) = p; + } + } + } + deja_vu(p) = true; + } + + std::cout << "Nb cmpts after processing : " << cmpts << std::endl; + + // second pass + I output(ima.domain()); + { + mln_bkd_piter(S) p(sp); + for_all(p) + if (parent(p) == p) // p is root. + output(p) = ima(p); + else + output(p) = output(parent(p)); + } + return output; + } + + } // end of namespace n_cmpt + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + +#endif /* MLN_N_CMPT3_HH */ + Index: jardonnet/n_cmpt/n_cmpt3.cc --- jardonnet/n_cmpt/n_cmpt3.cc (revision 0) +++ jardonnet/n_cmpt/n_cmpt3.cc (revision 0) @@ -0,0 +1,37 @@ + +#include <iostream> + +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/value/int_u8.hh> + +#include <mln/io/pgm/load.hh> +#include <mln/io/pgm/save.hh> + +#include "n_cmpt3.hh" + +using namespace mln; +using namespace mln::value; + +bool usage(int argc, char ** argv) +{ + if (argc != 3) + { + std::cout << argv[0] << " ima.pgm lambda" << std::endl; + return false; + } + return true; +} + +int main(int argc, char ** argv) +{ + if (not usage(argc,argv)) + return 1; + + image2d<int_u8> ima; + io::pgm::load(ima, argv[1]); + unsigned lambda = atoi(argv[2]); + + io::pgm::save(n_cmpt::n_cmpt3(ima, c4(), lambda), + "out.pgm"); +} Index: jardonnet/n_cmpt/Makefile --- jardonnet/n_cmpt/Makefile (revision 2980) +++ jardonnet/n_cmpt/Makefile (working copy) @@ -4,8 +4,14 @@ n_cmpt2: n_cmpt2.hh n_cmpt2.cc g++ -I../../.. -Wall -W -Wextra n_cmpt2.cc -DNDEBUG -O1 -o n_cmpt2 +n_cmpt3: n_cmpt3.hh n_cmpt3.cc + g++ -I../../.. -Wall -W -Wextra n_cmpt3.cc -DNDEBUG -O1 -o n_cmpt3 + debug: n_cmpt.hh n_cmpt.cc - g++ -I../../.. -Wall -W -Wextra n_cmpt.cc -g -g3 -DNDEBUG -o n_cmpt + g++ -I../../.. -Wall -W -Wextra n_cmpt.cc -g -g3 -o n_cmpt debug2: n_cmpt2.hh n_cmpt2.cc - g++ -I../../.. -Wall -W -Wextra n_cmpt2.cc -g -g3 -DNDEBUG -o n_cmpt2 \ No newline at end of file + g++ -I../../.. -Wall -W -Wextra n_cmpt2.cc -g -g3 -o n_cmpt2 + +debug3: n_cmpt3.hh n_cmpt3.cc + g++ -I../../.. -Wall -W -Wextra n_cmpt3.cc -g -g3 -o n_cmpt3 Index: jardonnet/n_cmpt/check/test4.pgm Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: jardonnet/n_cmpt/check/test4.pgm ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
participants (1)
-
Ugo Jardonnet