r3683: Add labeling output and add doc

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox ChangeLog: 2009-04-17 Edwin Carlinet <carlinet@lrde.epita.fr> Add labeling output and add doc. * edwin/tree/components.hh, * edwin/tree/propagate.hh, * edwin/tree/propagate_node.hh: Clean and add documentation. * edwin/tree/sharp.cc: Add labeling and benchmark. --- components.hh | 43 +++++++++++++++++++++++++++++-- propagate.hh | 25 +++++++++++++++++- propagate_node.hh | 4 +- sharp.cc | 74 +++++++++++++++++++++++++++--------------------------- 4 files changed, 103 insertions(+), 43 deletions(-) Index: trunk/milena/sandbox/edwin/tree/propagate.hh =================================================================== --- trunk/milena/sandbox/edwin/tree/propagate.hh (revision 3682) +++ trunk/milena/sandbox/edwin/tree/propagate.hh (revision 3683) @@ -71,7 +71,7 @@ */ template <typename A, typename T> inline - A set_value_to_components(const Image<A>& attr_image, + A propagate_components(const Image<A>& attr_image, const T& tree, const p_array< mln_psite(A) >& component_list, const mln_value(A)& null) @@ -91,6 +91,29 @@ return out; } + + template <typename T, typename V> + inline + mln_ch_value(typename T::function, V) + set_value_to_components(const T& tree, + const p_array< mln_psite(T) >& component_list, + const V& value, + const V& null) + { + mln_ch_value(typename T::function, V) out; + initialize(out, tree.f()); + data::fill(out, null); + + mln_piter(p_array< mln_psite(T) >) p(component_list); + for_all(p) + { + out(p) = value; + morpho::tree::propagate_node_to_descendants(p, tree, out); + } + morpho::tree::propagate_representant(tree, out); + return out; + } + } // end of namespace mln::morpho::tree } // end of namespace mln::morpho } // end of namespace mln Index: trunk/milena/sandbox/edwin/tree/sharp.cc =================================================================== --- trunk/milena/sandbox/edwin/tree/sharp.cc (revision 3682) +++ trunk/milena/sandbox/edwin/tree/sharp.cc (revision 3683) @@ -30,10 +30,15 @@ #include <mln/pw/all.hh> /* level */ -#include <mln/level/stretch.hh> +//#include <mln/level/stretch.hh> + +/* label */ +#include <mln/labeling/blobs.hh> +#include <mln/value/label_16.hh> /* trace */ #include <mln/trace/quiet.hh> +#include <mln/util/timer.hh> /* std */ #include <string> @@ -49,12 +54,14 @@ abort(); } -void dsp(const std::string& str) +void dsp(const std::string& str, mln::util::timer& timer) { + std::cout << "in " << timer.read() << std::endl; std::cout << std::endl << "*********************" << std::endl << "** " << str << std::endl << "*********************" << std::endl; + timer.restart(); } namespace mln @@ -170,6 +177,7 @@ unsigned card = 0; unsigned height = 0; double sharpness = 0; + util::timer timer; if (argc < 2) usage(argv); @@ -195,9 +203,8 @@ /********************/ /* Load & Pre-treat */ /********************/ - if (mydebug) - dsp("Load & Pre-treat"); + dsp("Load & Pre-treat", timer); typedef image2d<int_u8> I; I input; @@ -208,7 +215,7 @@ /***************************/ if (mydebug) - dsp("Component tree creation"); + dsp("Component tree creation", timer); typedef p_array< mln_site_(I) > S; typedef morpho::tree::data<I,S> tree_t; @@ -221,7 +228,7 @@ /* Compute Attribute On Image */ /******************************/ if (mydebug) - dsp("Image sharp attribute"); + dsp("Image sharp attribute", timer); // TODO: l'attribut devrait favoriser les composantes plus larges // dans son calcul. Ainsi au lieu de faire un sharpness, on aurait @@ -251,7 +258,7 @@ if (card) { if (mydebug) - dsp("Image card attribute"); + dsp("Image card attribute", timer); a = duplicate((fun::p2v::ternary(card_wrapper(pw::value(a_img)) > pw::cst(card), pw::value(a), @@ -261,7 +268,7 @@ if (height) { if (mydebug) - dsp("Image height attribute"); + dsp("Image height attribute", timer); a = duplicate((fun::p2v::ternary(height_wrapper(pw::value(a_img)) > pw::cst(height), pw::value(a), pw::cst(0.0))) | a.domain()); @@ -271,7 +278,6 @@ /* Retrieve Components (Maximising the criteria) */ /************************************************/ - accumulator::arg_max<A> argmax(a); p_array< mln_psite_(A) > obj_array; // Array of object components. if (mydebug) { @@ -283,7 +289,7 @@ s << "components whose treshold > " << sharpness; else s << "components util leaves are glutted"; - dsp(s.str()); + dsp(s.str(), timer); } if (nb_components) { @@ -297,48 +303,42 @@ /* Print them */ - if (mydebug) { - dsp("Image Filtered Components"); - mln_fwd_piter_(p_array< mln_psite_(I) >) c(obj_array); - for_all(c) - std::cout << c; - } +// if (mydebug) { +// mln_fwd_piter_(p_array< mln_psite_(I) >) c(obj_array); +// for_all(c) +// std::cout << c; +// } /***********************************/ /* Use components in output image */ /***********************************/ if (mydebug) { - dsp("Create mask and propagate"); + dsp("Propagate components and stretch", timer); } // Note: now we must propagate the representant value to the other components sites. - A pre_output = morpho::tree::set_value_to_components(a, tree, obj_array, 0); - I output = level::stretch(int_u8(), pre_output); //adapt to 0-255 - io::pgm::save(output, "components.pgm"); + + //a = morpho::tree::propagate_components(a, tree, obj_array, 0); + //I output = level::stretch(int_u8(), a); //adapt to 0-255 + //io::pgm::save(output, "components.pgm"); /* EXTRA */ -// typedef mln_ch_value_(I, bool) M; -// M mask; -// initialize(mask, a); -// data::fill(mask, false); + // labeling + typedef mln_ch_value_(I, bool) M; + typedef mln_ch_value_(I, value::label<16>) L; + + M mask = morpho::tree::set_value_to_components(tree, obj_array, true, false); + value::label<16> nlabel; + L label = labeling::blobs(mask, c4(), nlabel); + io::pgm::save(label, "label.pgm"); -// mln_fwd_piter_(p_array< mln_psite_(I) >) c(obj_array); -// for_all(c) -// { -// mask(c) = true; -// propagate_node_to_descendants(c, tree, mask); -// } + if (mydebug) { + dsp("Finish", timer); + } - // mask now contains all nodes related to objects - - // /* Labeling */ -// typedef mln_ch_value_(I, value::label<8>) L; -// value::label<8> nlabel; -// L label = labeling::blobs(mask, c4(), nlabel); -// io::ppm::save(debug::colorize(value::rgb8(), label, nlabel), "label.pgm"); // /* Now store output image */ Index: trunk/milena/sandbox/edwin/tree/components.hh =================================================================== --- trunk/milena/sandbox/edwin/tree/components.hh (revision 3682) +++ trunk/milena/sandbox/edwin/tree/components.hh (revision 3683) @@ -26,8 +26,8 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef COMPONENTS_HH_ -# define COMPONENTS_HH_ +#ifndef MLN_MORPHO_TREE_COMPONENTS_HH_ +# define MLN_MORPHO_TREE_COMPONENTS_HH_ # include <mln/core/concept/image.hh> # include <mln/core/concept/function.hh> @@ -40,19 +40,56 @@ # include <mln/trace/exiting.hh> +/** +** \file mln/morpho/tree/components.hh +** +** Routines that offers different way of retrieving tree components. +** Tree components are nodes maximising the attribute. +*/ + namespace mln { namespace morpho { namespace tree { + /** + ** Retrieve components from the tree until all leaves belong to + ** components. + ** + ** @param tree Component tree. + ** @param attr_image Attribute image. + ** + ** @return Array of components. + */ template <typename T, typename A> p_array< mln_psite(A) > get_components(const T& tree, const Image<A>& attr_image); + /** + ** Retrieve the \p n most important components from the tree. n + ** should be lesser than the maximum number of components. If + ** not, the functions stops when there's no more components. + ** + ** @param tree Component tree. + ** @param attr_image Attribute image. + ** @param n Number of components to get. + ** + ** @return Array of components. + */ template <typename T, typename A> p_array< mln_psite(A) > get_components(const T& tree, const Image<A>& attr_image, unsigned n); + /** + ** Retrieve the most important components that check + ** predicate \p pred. + ** + ** @param tree Component tree. + ** @param attr_image Attribute image. + ** @param pred Predicate that components must check. + ** + ** @return Array of components. + */ template <typename T, typename A, typename P2B> p_array< mln_psite(A) > get_components(const T& tree, const Image<A>& attr_image, const Function_p2b<P2B>& pred); @@ -275,4 +312,4 @@ # endif /* !MLN_INCLUDE_ONLY */ -#endif /* !COMPONENTS_HH_ */ +#endif /* !MLN_MORPHO_TREE_COMPONENTS_HH_ */ Index: trunk/milena/sandbox/edwin/tree/propagate_node.hh =================================================================== --- trunk/milena/sandbox/edwin/tree/propagate_node.hh (revision 3682) +++ trunk/milena/sandbox/edwin/tree/propagate_node.hh (revision 3683) @@ -29,9 +29,9 @@ #ifndef MLN_MORPHO_TREE_PROPAGATE_NODE_HH_ # define MLN_MORPHO_TREE_PROPAGATE_NODE_HH_ +# include <mln/core/concept/image.hh> +# include <mln/core/macros.hh> #include <mln/morpho/tree/data.hh> -#include <mln/core/site_set/p_array.hh> -#include <stack> /// \file mln/morpho/tree/propagate_node.hh ///
participants (1)
-
Edwin Carlinet