cleanup-2008 2756: INIM: Classif: Work on density.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> INIM: Classif: Work on density. * classif/max_tree.hh (density closing|fusion): Add. * classif/v2.cc: Add parameter. max_tree.hh | 40 +++++++++++++++++++++++++++++++++++++--- v2.cc | 36 +++++++++++------------------------- 2 files changed, 48 insertions(+), 28 deletions(-) Index: classif/max_tree.hh --- classif/max_tree.hh (revision 2755) +++ classif/max_tree.hh (working copy) @@ -91,6 +91,16 @@ } // end of run() + point active_parent(const point& p) + { + if(is_root(p)) + return p; + point node = parent(p); + while (not is_active(node)) + node = parent(node); + return node; + } + void make_set(const point& p) { parent(p) = p; @@ -124,13 +134,13 @@ vol(p) += 1; nb_represent(p) += f(p); - if (parent(p) != p) + if (not is_root(p)) { nb_represent(parent(p)) += nb_represent(p); vol(parent(p)) += vol(p); } - density(p) = nb_represent(p) / (double) vol(p); + density(parent(p)) = (nb_represent(parent(p)) - nb_represent(p)) / (double) (vol(parent(p)) - vol(p)); } } @@ -147,6 +157,31 @@ } } + void density_fusion(float ratio) + { + assert(ratio < 1); + + mln_fwd_piter(S) p(s); + for_all(p) + { + if (density(active_parent(p)) > (1 - ratio) * density(p) && + density(active_parent(p)) < (1 + ratio) * density(p)) + is_active(p) = false; + } + } + + void density_closing(float lambda) + { + assert(ratio < 1); + + mln_fwd_piter(S) p(s); + for_all(p) + { + if (density(p) < lambda) + is_active(p) = false; + } + } + void compute_mean_color() { level::fill(mean_color, make::vec(0, 0, 0)); @@ -214,7 +249,6 @@ while (not is_active(node)) node = parent(node); -write: out(p) = value::rgb8(static_cast<unsigned char>(mean_color(node)[0] * f), static_cast<unsigned char>(mean_color(node)[1] * f), static_cast<unsigned char>(mean_color(node)[2] * f)); Index: classif/v2.cc --- classif/v2.cc (revision 2755) +++ classif/v2.cc (working copy) @@ -40,45 +40,30 @@ template <typename I, typename J, typename N> unsigned -compute_max_tree(const I& ima, const J& histo, const N& nbh, const unsigned f, int lambda) +compute_max_tree(const I& ima, const J& histo, const N& nbh, + const unsigned f, float lambda, float ratio) { max_tree_<J,N> run(histo, nbh); -#if 0 - I out(ima.domain()); - mln_piter(I) p(ima.domain()); - for_all(p) - { - //color at ima(p) - point3d v = point3d(ima(p).red() / f, - ima(p).green() / f, - ima(p).blue() / f); - //node the class of color with same density as v - point3d pn = run.parent(v); - //out(p) = color pn - out(p) = value::rgb8(pn[0] * f, pn[1] * f, pn[2] * f); - } - io::ppm::save(out, "tmp.ppm"); -#endif //run.number_of_nodes(); - run.volume(); - run.nb_represent_fusion(lambda); + run.volume(); run.volume_fusion(lambda); - run.color_fusion(5); + run.density_fusion(ratio); run.compute_mean_color(); - run.print_class_info(); run.to_ppm(ima, "out.ppm", f); + run.print_class_info(); + //std::cout << " Number of nodes : " << run.number_of_nodes() << std::endl; } bool usage(int argc, char ** argv) { - if (argc != 4) + if (argc != 5) { - std::cout << "usage: " << argv[0] << " image div_factor lambda" << std::endl; + std::cout << "usage: " << argv[0] << " image div_factor lambda ratio" << std::endl; return false; } return true; @@ -92,7 +77,8 @@ image2d<value::rgb8> ima; ima = io::ppm::load<value::rgb8>(argv[1]); const int div_factor = atoi(argv[2]); - const int lambda = atoi(argv[3]); + const float lambda = atof(argv[3]); + const float ratio = atof(argv[4]); //make histo image3d<unsigned> histo = fill_histo(ima, div_factor); @@ -104,5 +90,5 @@ //debug::println(phisto); // Compute max_tree - compute_max_tree(ima, histo, c6(), div_factor, lambda); + compute_max_tree(ima, histo, c6(), div_factor, lambda, ratio); }
participants (1)
-
Ugo Jardonnet