milena r4215: Enable attribute computation from an external source of values

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2009-06-29 Edwin Carlinet <carlinet@lrde.epita.fr> Enable attribute computation from an external source of values. * mln/morpho/tree/compute_attribute_image.hh: Add compute_attribute_image_from routine. * tests/morpho/tree/compute_attribute_image.cc: Add some tests. --- mln/morpho/tree/compute_attribute_image.hh | 82 +++++++++++++++++++++++---- tests/morpho/tree/compute_attribute_image.cc | 5 + 2 files changed, 77 insertions(+), 10 deletions(-) Index: trunk/milena/mln/morpho/tree/compute_attribute_image.hh =================================================================== --- trunk/milena/mln/morpho/tree/compute_attribute_image.hh (revision 4214) +++ trunk/milena/mln/morpho/tree/compute_attribute_image.hh (revision 4215) @@ -74,7 +74,7 @@ ** \param[out] accu_image Optional argument used to store image ** of attribute accumulator. ** - ** @return The attribute image. + ** \return The attribute image. */ template <typename A, typename T> mln_ch_value(typename T::function, mln_result(A)) @@ -84,10 +84,30 @@ + /** The same as compute_attribute_image but uses the values + ** stored by \p values image instead. + ** + ** \param[in] a Attribute. + ** \param[in] t Component tree. + ** \param[in] values Value image. + ** \param[out] accu_image Optional argument used to store image. + ** + ** \return + */ + template <typename A, typename T, typename V> + mln_ch_value(typename T::function, mln_result(A)) + compute_attribute_image_from(const Accumulator<A>& a, + const T& t, + const Image<V>& values, + mln_ch_value(typename T::function, A)* accu_image = 0); + + + # ifndef MLN_INCLUDE_ONLY // Take_as_init specialization - + namespace internal + { template <typename A, typename I, typename P> void take_as_init (trait::accumulator::when_pix::use_none, A& accu, const I& input, const P& p) @@ -126,16 +146,14 @@ } - // Facade. - - template <typename A, typename T> + template <typename A, typename T, typename V> inline mln_ch_value(typename T::function, mln_result(A)) - compute_attribute_image(const Accumulator<A>& a_, + compute_attribute_image(const A& a, const T& t, + const V& values, mln_ch_value(typename T::function, A)* accu_image = 0) { - trace::entering("morpho::tree::compute_attribute_image"); typedef typename T::function I; mln_ch_value(I, A) acc; @@ -146,21 +164,23 @@ // 'acc'. It is usually a no-op (so useless) except for a // few accumulators, e.g., for accu::stat::rank which has the 'k' // attribute. - A a = exact(a_); mln::data::fill(acc, a); } + { // Initialize every attribute with the corresponding pixel. - mln_piter(I) p(t.f().domain()); + mln_site_piter(T) p(t); for_all(p) - take_as_init(acc(p), t.f(), p); + take_as_init(acc(p), values, p); } + { mln_up_site_piter(T) p(t); // Propagate attribute from a site to its parent. for_all(p) if (! t.is_root(p)) acc(t.parent(p)).take(acc(p)); + // Back-propagate attribute from a node to sites of its // component. Below, p is a non-node component site and // parent(p) is a node, that is, the site representative of @@ -173,6 +193,7 @@ } } + // Store accumulator image. if (accu_image) *accu_image = duplicate(acc); @@ -182,10 +203,51 @@ initialize(output, acc); mln::data::fill(output, acc); + return output; + } + } + + // Facade. + + template <typename A, typename T> + inline + mln_ch_value(typename T::function, mln_result(A)) + compute_attribute_image(const Accumulator<A>& a_, + const T& t, + mln_ch_value(typename T::function, A)* accu_image = 0) + { + trace::entering("morpho::tree::compute_attribute_image"); + + mln_ch_value(typename T::function, mln_result(A)) output; + output = internal::compute_attribute_image(exact(a_), t, t.f(), + accu_image); + trace::exiting("morpho::tree::compute_attribute_image"); + return (output); + } + + template <typename A, typename T, typename V> + inline + mln_ch_value(typename T::function, mln_result(A)) + compute_attribute_image_from(const Accumulator<A>& a_, + const T& t, + const Image<V>& values, + mln_ch_value(typename T::function, A)* accu_image = 0) + { + trace::entering("morpho::tree::compute_attribute_image_from"); + + + mln_ch_value(typename T::function, mln_result(A)) output; + output = internal::compute_attribute_image(exact(a_), t, exact(values), + accu_image); + + trace::exiting("morpho::tree::compute_attribute_image_from"); return output; } + + + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::morpho::tree Index: trunk/milena/tests/morpho/tree/compute_attribute_image.cc =================================================================== --- trunk/milena/tests/morpho/tree/compute_attribute_image.cc (revision 4214) +++ trunk/milena/tests/morpho/tree/compute_attribute_image.cc (revision 4215) @@ -27,6 +27,7 @@ #include <mln/core/alias/neighb2d.hh> #include <mln/core/site_set/p_array.hh> #include <mln/data/sort_psites.hh> +#include <mln/data/compare.hh> #include <mln/debug/println.hh> #include <mln/core/var.hh> @@ -60,13 +61,17 @@ { morpho::attribute::card<I> a; image2d<unsigned> area = morpho::tree::compute_attribute_image(a, t); + image2d<unsigned> area_bis = morpho::tree::compute_attribute_image_from(a, t, f); debug::println(area); + mln_assertion(area == area_bis); } { morpho::attribute::volume<I> v; image2d<unsigned> volume = morpho::tree::compute_attribute_image(v, t); + image2d<unsigned> volume_bis = morpho::tree::compute_attribute_image_from(v, t, f); debug::println(volume); + mln_assertion(volume == volume_bis); } }
participants (1)
-
Edwin Carlinet