
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-07-17 Edwin Carlinet <carlinet@lrde.epita.fr> Fix bugs in segmentation with delta colormean method. * edwin/exec/max_delta_colormean_obj.cc, * edwin/mln/morpho/tree/components_debug.hh: Minor fixes. --- exec/max_delta_colormean_obj.cc | 54 ++++++++++++++++++++++-------------- mln/morpho/tree/components_debug.hh | 2 - 2 files changed, 34 insertions(+), 22 deletions(-) Index: trunk/milena/sandbox/edwin/exec/max_delta_colormean_obj.cc =================================================================== --- trunk/milena/sandbox/edwin/exec/max_delta_colormean_obj.cc (revision 4312) +++ trunk/milena/sandbox/edwin/exec/max_delta_colormean_obj.cc (revision 4313) @@ -56,7 +56,7 @@ // debug #include <mln/morpho/tree/debug.hh> -#include <mln/morpho/tree/components.hh> +#include <mln/morpho/tree/components_debug.hh> using namespace mln; using value::int_u8; @@ -130,37 +130,49 @@ io::ppm::save(data::convert(value::rgb8(), means), "mean.ppm"); // Compute delta image. - mln_ch_value(typename T::function, int_u8) dist; + mln_ch_value(typename T::function, int_u8) dist, idist_dad, idist_bro; initialize(dist, tree.f()); + initialize(idist_dad, tree.f()); + initialize(idist_bro, tree.f()); mln_up_node_piter(T) n(tree); for_all(n) { int_u8 dist_dad, dist_bro; - value::rgb8 current, mean_bro; - ACC aux = accus(tree.parent(n)); - - aux.untake(accus(n)); + value::rgb8 current, cur_mean, bro_mean, dad_mean; + ACC aux; + ACC aux2 = accus(tree.parent(n)); // FIXME: add untake_n_times to accumlator concept - // Note: this is an approximation to avoid the real mean computation of bros. - unsigned m = accus(tree.parent(n)).count() - accus(n).count() - aux.count(); - value::rgb8 v = exact(source)(n); - - for (unsigned i = 0; i < m; i++) - aux.untake(v); - - current = convert::to<value::rgb8>(means(n)); - mean_bro = convert::to<value::rgb8>(aux.to_result()); - - dist_dad = dist_mean(convert::to<value::rgb8>(means(tree.parent(n))), - current); - dist_bro = dist_mean(convert::to<value::rgb8>(aux.to_result()), - current); + // FIXME: to optimize + { + mln_piter(T::nodes_t) child(tree.children(tree.parent(n))); + for_all(child) + if (child != n) + aux.take(accus(child)); + } + + cur_mean = convert::to<value::rgb8>(means(n)); - dist(n) = math::max(dist_bro, dist_dad); + bro_mean = convert::to<value::rgb8>(aux.to_result()); + dist_bro = aux.is_valid() ? dist_mean(bro_mean, cur_mean) : (int_u8) 0; + idist_bro(n) = dist_bro; + + aux.take(accus(n)); + aux2.untake(aux); + + dad_mean = convert::to<value::rgb8>(aux2.to_result()); + dist_dad = dist_mean(dad_mean, cur_mean); + idist_dad(n) = dist_dad; + + dist(n) = math::max(dist_bro, (int_u8) (dist_dad * 1.5)); } + morpho::tree::propagate_representative(tree, idist_bro); + morpho::tree::propagate_representative(tree, idist_dad); + io::pgm::save(idist_dad, "distance_dad.pgm"); + io::pgm::save(idist_bro, "distance_bro.pgm"); + return dist; } Index: trunk/milena/sandbox/edwin/mln/morpho/tree/components_debug.hh =================================================================== --- trunk/milena/sandbox/edwin/mln/morpho/tree/components_debug.hh (revision 4312) +++ trunk/milena/sandbox/edwin/mln/morpho/tree/components_debug.hh (revision 4313) @@ -277,7 +277,7 @@ std::stringstream fn; fn.fill('0'); fn << "debug/log_"; - fn.width(3); + fn.width(4); fn << std::right << cpt; std::ofstream out((fn.str() + ".log").c_str());