
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-11-05 Matthieu Garrigues <garrigues@lrde.epita.fr> Choice a good root of the merged tree in FLLT. * sandbox/garrigues/fllt2.hh: (merge_trees) Choose a good root between the upper tree's one and the lower tree's one in order to keep the good values of the input image. (fllt) add a second call to merge_trees to test the contrast invariant of the algorithm. FIXME : In some test, we get a segv when calling merge_trees swapping the upper_tree and lower_tree arguments. Add some debug too. Fix a bug in add_child. * mln/util/tree.hh: When we delete the node from the children of its parent, we're searching (node), not (this). Update include of test_fllt4 * sandbox/garrigues/test_fllt4.cc, * sandbox/garrigues/test_fllt5.cc, * sandbox/garrigues/test_fllt_lena_tiles.cc: Update. --- mln/util/tree.hh | 3 + sandbox/garrigues/fllt2.hh | 48 +++++++++++++++++++++--------- sandbox/garrigues/test_fllt4.cc | 2 - sandbox/garrigues/test_fllt5.cc | 2 - sandbox/garrigues/test_fllt_lena_tiles.cc | 2 - 5 files changed, 40 insertions(+), 17 deletions(-) Index: trunk/milena/mln/util/tree.hh =================================================================== --- trunk/milena/mln/util/tree.hh (revision 1432) +++ trunk/milena/mln/util/tree.hh (revision 1433) @@ -29,6 +29,7 @@ # define MLN_UTIL_TREE_HH # include <vector> +# include <algorithm> # include <iostream> # include <algorithm> # include <mln/core/contract.hh> @@ -245,7 +246,7 @@ { for (typename std::vector<util::node<T>* >::iterator it = node->parent()->children().begin(); it != node->parent()->children().end(); ++it) - if ((*it) == this) + if ((*it) == node) { node->parent()->children().erase(it); break; Index: trunk/milena/sandbox/garrigues/fllt2.hh =================================================================== --- trunk/milena/sandbox/garrigues/fllt2.hh (revision 1432) +++ trunk/milena/sandbox/garrigues/fllt2.hh (revision 1433) @@ -262,9 +262,12 @@ current_region->elt().value = g; for_all(p) { - current_region->elt().points.insert(p); + if (regions(p) == 0) + { + current_region->elt().points.insert(p); regions(p) = current_region; + } else { if (regions(p)->parent() == 0) @@ -664,14 +667,23 @@ } } + fllt_tree(P, V)* main_tree = &lower; + fllt_tree(P, V)* other_tree = &upper; + + if (lower.root()->elt().points.npoints() >= ima.domain().npoints()) + { + main_tree = &upper; + other_tree = &lower; + } typename fllt_node(P, V)::children_t::iterator it; - for (it = upper.root()->children().begin(); - it != upper.root()->children().end(); ) + for (it = other_tree->root()->children().begin(); + it != other_tree->root()->children().end(); ) { - lower.root()->add_child(*it); + main_tree->root()->add_child(*it); } - mln_assertion(lower.check_consistency()); + mln_assertion(main_tree->check_consistency()); + return *main_tree; } @@ -764,19 +776,19 @@ draw_tree(ima, upper_tree); std::cout << "3/ Merge the two trees." << std::endl; + + // FIXME : the algorithm is contrast invariant. + // -> the both calls have to give the same result + // -> check it. + // FIXME : call merge_tree one time will be enough. fllt_tree(P, V) result_tree = merge_trees(lower_tree, upper_tree, low_reg, upp_reg, ima); + fllt_tree(P, V) result_tree = merge_trees(upper_tree, lower_tree, upp_reg, low_reg, ima); std::cout << "4/ Generate outputs." << std::endl; image2d<value::int_u8> output (ima.domain ()); - util::tree_to_image (lower_tree, output); - -// if (output != ima) -// { -// std::cerr << "BUG!!!" << std::endl; -// abort(); -// } + util::tree_to_image (result_tree, output); // io::pgm::save(output, "out_final.pgm"); @@ -785,7 +797,17 @@ // util::display_tree(ima, lower_tree); - draw_tree(ima, lower_tree); + draw_tree(ima, result_tree); + + debug::println(ima); + debug::println(output); + + if (output != ima) + { + std::cerr << "BUG!!!" << std::endl; + abort(); + } + // image2d<value::int_u8> viz(ima.domain()); // image2d<value::int_u8> viz2(ima.domain()); Index: trunk/milena/sandbox/garrigues/test_fllt_lena_tiles.cc =================================================================== --- trunk/milena/sandbox/garrigues/test_fllt_lena_tiles.cc (revision 1432) +++ trunk/milena/sandbox/garrigues/test_fllt_lena_tiles.cc (revision 1433) @@ -1,4 +1,4 @@ -# include "fllt.hh" +# include "fllt2.hh" # include <mln/core/image2d.hh> # include <mln/core/clone.hh> # include <mln/value/int_u8.hh> Index: trunk/milena/sandbox/garrigues/test_fllt4.cc =================================================================== --- trunk/milena/sandbox/garrigues/test_fllt4.cc (revision 1432) +++ trunk/milena/sandbox/garrigues/test_fllt4.cc (revision 1433) @@ -1,4 +1,4 @@ -# include "fllt.hh" +# include "fllt2.hh" # include <mln/core/image2d.hh> # include <mln/core/clone.hh> # include <mln/value/int_u8.hh> Index: trunk/milena/sandbox/garrigues/test_fllt5.cc =================================================================== --- trunk/milena/sandbox/garrigues/test_fllt5.cc (revision 1432) +++ trunk/milena/sandbox/garrigues/test_fllt5.cc (revision 1433) @@ -1,4 +1,4 @@ -# include "fllt.hh" +# include "fllt2.hh" # include <mln/core/image2d.hh> # include <mln/core/clone.hh> # include <mln/value/int_u8.hh>