r4006: Some experiments about treshold auto-detection for attribute filtering

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-06-05 Edwin Carlinet <carlinet@lrde.epita.fr> Some experiments about treshold auto-detection for attribute filtering. * edwin/rush/granulometry/Makefile: Remove. * edwin/rush/granulometry/granulometry.hh: Add function to retrieve treshold. * edwin/rush/granulometry/test.cc: Test file. --- granulometry.hh | 34 ++++++++++++++++++++++++---------- test.cc | 16 ++++++++++++---- 2 files changed, 36 insertions(+), 14 deletions(-) Index: trunk/milena/sandbox/edwin/rush/granulometry/Makefile (deleted) =================================================================== Index: trunk/milena/sandbox/edwin/rush/granulometry/test.cc =================================================================== --- trunk/milena/sandbox/edwin/rush/granulometry/test.cc (revision 4005) +++ trunk/milena/sandbox/edwin/rush/granulometry/test.cc (revision 4006) @@ -40,7 +40,7 @@ #include <mln/morpho/attribute/card.hh> #include <mln/data/fill.hh> -#include "../../tree/propagate_node.hh" +#include <mln/morpho/tree/propagate_node.hh> #include <iostream> #include <map> @@ -73,8 +73,6 @@ typedef morpho::attribute::card<I> card_t; A a = morpho::tree::compute_attribute_image(card_t (), tree); - - { typedef std::map<mln_value_(A), unsigned> F; F f = morpho::tree::compute_attribute_curve_beta(tree, a); @@ -97,11 +95,21 @@ std::cout << it->first << " -> " << it->second << " = " << count << std::endl; - mln_assertion(count == it->second); + //mln_assertion(count == it->second); } } + std::cout << "part 2" << std::endl; + { + typedef std::map<mln_value_(A), unsigned> F; + F f = morpho::tree::compute_attribute_curve(tree, a); + F::iterator it; + for (it = f.begin(); it != f.end(); ++it) + std::cout << it->first << " -> " << it->second << std::endl; + unsigned lambda = morpho::tree::get_delta(f); + std::cout << "lambda: " << lambda << " : " << f[lambda] << std::endl; + } } Index: trunk/milena/sandbox/edwin/rush/granulometry/granulometry.hh =================================================================== --- trunk/milena/sandbox/edwin/rush/granulometry/granulometry.hh (revision 4005) +++ trunk/milena/sandbox/edwin/rush/granulometry/granulometry.hh (revision 4006) @@ -73,25 +73,40 @@ private: const A& f_; }; - - } - template <typename T, typename A> + template <typename T, typename F> inline - std::map<mln_value(A), unsigned> - compute_attribute_curve(const T& tree, const Image<A>& attr_img) + std::map<mln_value(F), unsigned> + compute_attribute_curve(const T& tree, const Image<F>& f_) { - const A& a = exact(attr_img); + const F& f = exact(f_); - std::map< mln_value(A), unsigned > f; + std::map< mln_value(F), unsigned > g; mln_node_piter(T) n(tree); for_all(n) - f[a(n)]++; + g[f(n)]++; + + return g; + } + template <typename F> + inline + F get_delta(const std::map<F, unsigned>& f) + { + typedef typename std::map<F, unsigned>::const_iterator IT; + // pre: f pseudo-decreasing - return f; + IT current, it; + double d = -1; + current = it = f.begin(); + while (++it != f.end() && d < -0.5) + { + d = (current->second - it->second) / (it->first - current->first); + current = it; + } + return (current->first); } @@ -104,7 +119,6 @@ // TODO: precondition attribut croissant - typedef std::priority_queue< mln_psite(A), std::vector< mln_psite(A) >, internal::attr_less<A> > q_type; std::map< mln_value(A), unsigned > f; internal::attr_less<A> cmp(a);
participants (1)
-
Edwin Carlinet