
* mln/accu/center.hh: make it compute the mass center instead of the bbox center. * mln/core/site_set/p_graph_piter.hh: add element(); * mln/debug/colorize.hh: Pass the color type as arguments instead of passing the return type as template parameter. * mln/debug/draw_graph.hh: add a new signature. * mln/literal/colors.hh, * mln/level/convert.hh: update comments. * mln/level/transform.spe.hh: add new specializations/dispatches when the function is of type Function_i2v. * mln/value/label.hh: Fix missing include. --- milena/ChangeLog | 22 ++++++ milena/mln/accu/center.hh | 20 +++-- milena/mln/core/site_set/p_graph_piter.hh | 13 +++- milena/mln/debug/colorize.hh | 24 ++++-- milena/mln/debug/draw_graph.hh | 38 ++++++++-- milena/mln/level/convert.hh | 13 ++-- milena/mln/level/transform.spe.hh | 109 ++++++++++++++++++++++++----- milena/mln/literal/colors.hh | 9 +-- milena/mln/value/label.hh | 3 +- 9 files changed, 195 insertions(+), 56 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 7091654..28fdcc9 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,27 @@ 2008-11-27 Guillaume Lazzara <z@lrde.epita.fr> + Various small fixes. + + * mln/accu/center.hh: make it compute the mass center instead of the + bbox center. + + * mln/core/site_set/p_graph_piter.hh: add element(); + + * mln/debug/colorize.hh: Pass the color type as arguments instead of + passing the return type as template parameter. + + * mln/debug/draw_graph.hh: add a new signature. + + * mln/literal/colors.hh, + * mln/level/convert.hh: update comments. + + * mln/level/transform.spe.hh: add new specializations/dispatches when + the function is of type Function_i2v. + + * mln/value/label.hh: Fix missing include. + +2008-11-27 Guillaume Lazzara <z@lrde.epita.fr> + Update unit_tests and labeling::compute test. * tests/labeling/compute.cc: use label8 instead of int_u8 as labeled diff --git a/milena/mln/accu/center.hh b/milena/mln/accu/center.hh index 2aacfce..4102925 100644 --- a/milena/mln/accu/center.hh +++ b/milena/mln/accu/center.hh @@ -30,7 +30,7 @@ /// \file mln/accu/center.hh /// -/// Define an accumulator that computes the center of a site set. +/// Define an accumulator that computes the mass center of a site set. # include <mln/accu/internal/base.hh> # include <mln/accu/bbox.hh> @@ -66,7 +66,8 @@ namespace mln bool is_valid() const; protected: - accu::bbox<P> bbox_; + algebra::vec<P::dim, float> center_; + unsigned nsites_; }; namespace meta @@ -102,14 +103,16 @@ namespace mln void center<P>::init() { - bbox_.init(); + center_ = literal::zero; + nsites_ = 0; } template <typename P> inline void center<P>::take(const argument& t) { - bbox_.take(t); + center_ += t.to_vec(); + ++nsites_; } template <typename P> @@ -117,7 +120,8 @@ namespace mln void center<P>::take(const center<P>& other) { - bbox_.take(other.bbox_); + center_ += other.center_; + nsites_ += other.nsites_; } template <typename P> @@ -125,14 +129,14 @@ namespace mln P center<P>::to_result() const { - return bbox_.to_result().center(); + return P(center_ / nsites_); } template <typename P> inline center<P>::operator P() const { - return P(bbox_.to_result().center()); + return to_result(); } template <typename P> @@ -140,7 +144,7 @@ namespace mln bool center<P>::is_valid() const { - return bbox_.is_valid(); + return nsites_ > 0; } # endif // ! MLN_INCLUDE_ONLY diff --git a/milena/mln/core/site_set/p_graph_piter.hh b/milena/mln/core/site_set/p_graph_piter.hh index bbc3a54..37c3ed3 100644 --- a/milena/mln/core/site_set/p_graph_piter.hh +++ b/milena/mln/core/site_set/p_graph_piter.hh @@ -79,6 +79,9 @@ namespace mln void next_(); /// \} + /// Return the underlying graph element. + mln_q_subject(iter) element(); + private: /// Update the psite corresponding to this iterator. @@ -89,7 +92,7 @@ namespace mln /// The psite corresponding to this iterator. using super_::p_; - /// The underlying vertex iterator. + /// The underlying graph iterator. iter iter_; }; @@ -156,6 +159,14 @@ namespace mln template <typename S, typename I> inline + mln_q_subject(I) + p_graph_piter<S,I>::element() + { + return iter_.subj_(); + } + + template <typename S, typename I> + inline void p_graph_piter<S,I>::update_() { diff --git a/milena/mln/debug/colorize.hh b/milena/mln/debug/colorize.hh index cf99383..a015f9b 100644 --- a/milena/mln/debug/colorize.hh +++ b/milena/mln/debug/colorize.hh @@ -61,11 +61,15 @@ namespace mln * variables mln::debug::colorize_::min_value and * mln::debug::colorize_::max_value. * + * \param[in] value value type used in the returned image. * \param[in] labeled_image A labeled image (\sa labeling::blobs). * \param[in] nlabels Number of labels. */ - template <typename I, typename L> - mln_concrete(I) colorize(const Image<L>& labeled_image, mln_value(L) nlabels); + template <typename V, typename L> + mln_ch_value(L, V) + colorize(const V& value, + const Image<L>& labeled_image, + const mln_value(L)& nlabels); # ifndef MLN_INCLUDE_ONLY @@ -93,18 +97,22 @@ namespace mln } - template <typename I, typename L> + template <typename V, typename L> inline - mln_concrete(I) - colorize(const Image<L>& input, mln_value(L) nlabels) + mln_ch_value(L, V) + colorize(const V& value, + const Image<L>& input, + const mln_value(L)& nlabels) { trace::entering("debug::colorize"); mln_precondition(exact(input).has_data()); + // FIXME: check that V is a color type. // FIXME: we want to be sure that this is a label. mlc_is_a(mln_value(L), mln::value::Symbolic)::check(); + (void) value; unsigned label_count = nlabels.next(); - static fun::i2v::array<mln_value(I)> f(0); + static fun::i2v::array<V> f(0); int diff_size = f.size() - label_count; if (diff_size < 0) { @@ -119,8 +127,8 @@ namespace mln for (; i < f.size(); ++i) f(i) = internal::random_color(); } - mln_precondition(f.size() == (label_count)); - mln_concrete(I) output = level::transform(input, f); + mln_assertion(f.size() >= (label_count)); + mln_ch_value(L, V) output = level::transform(input, f); trace::exiting("debug::colorize"); return output; diff --git a/milena/mln/debug/draw_graph.hh b/milena/mln/debug/draw_graph.hh index a891534..f163923 100644 --- a/milena/mln/debug/draw_graph.hh +++ b/milena/mln/debug/draw_graph.hh @@ -36,6 +36,7 @@ /// \todo write a version for graph images. # include <mln/core/site_set/p_vertices.hh> +# include <mln/core/site_set/p_edges.hh> # include <mln/draw/line.hh> # include <mln/level/fill.hh> @@ -58,9 +59,14 @@ namespace mln template <typename I, typename G, typename F> void draw_graph(Image<I>& ima, const p_vertices<G, F>& pv, - mln_value(I) vertex_v, mln_value(I) edge_v); + mln_value(I) vertex_v, mln_value(I) edge_v); + template <typename I, typename G, typename F, typename E> + void + draw_graph(Image<I>& ima, + const p_vertices<G, F>& pv, const Function<E>& fcolor); + # ifndef MLN_INCLUDE_ONLY @@ -73,13 +79,10 @@ namespace mln inline void draw_graph(Image<I>& ima, - const p_vertices<G, F>& pv, - mln_value(I) vertex_v, - mln_value(I) edge_v) + const p_vertices<G, F>& pv, + mln_value(I) vertex_v, + mln_value(I) edge_v) { - // Fill the background. - level::fill(ima, literal::black); - // Draw edges. const G& g = pv.graph(); typedef p_vertices<G, F> pv_t; @@ -94,7 +97,28 @@ namespace mln exact(ima)(p) = vertex_v; } + // FIXME: Refactor + be more restrictive on the function type. + template <typename I, typename G, typename F, typename E> + inline + void + draw_graph(Image<I>& ima, + const p_vertices<G, F>& pv, const Function<E>& fcolor_) + { + const E& fcolor = exact(fcolor_); + // Draw edges. + const G& g = pv.graph(); + typedef p_vertices<G, F> pv_t; + mln_edge_iter(G) ei(g); + for_all(ei) + draw::line(exact(ima), pv(ei.v1()), pv(ei.v2()), fcolor(ei)); + + // Draw vertices. + mln_piter(pv_t) p(pv); + for_all(p) + if (exact(ima).has(p)) + exact(ima)(p) = fcolor(p.element()); + } # endif // ! MLN_INCLUDE_ONLY diff --git a/milena/mln/level/convert.hh b/milena/mln/level/convert.hh index 9e667b7..68d900d 100644 --- a/milena/mln/level/convert.hh +++ b/milena/mln/level/convert.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,12 +28,11 @@ #ifndef MLN_LEVEL_CONVERT_HH # define MLN_LEVEL_CONVERT_HH -/*! \file mln/level/convert.hh - * - * \brief Convert the contents of an image into another one. - * - * \todo Re-write doc. - */ +/// \file mln/level/convert.hh +/// +/// Convert the contents of an image into another one. +/// +/// \todo Re-write doc. # include <mln/fun/v2v/convert.hh> # include <mln/level/transform.hh> diff --git a/milena/mln/level/transform.spe.hh b/milena/mln/level/transform.spe.hh index 8edfe0f..db91d1b 100644 --- a/milena/mln/level/transform.spe.hh +++ b/milena/mln/level/transform.spe.hh @@ -97,9 +97,9 @@ namespace mln template <typename I, typename F> mln_ch_value(I, mln_result(F)) - transform_lowq(const Image<I>& input_, const Function_v2v<F>& f_) + transform_lowq_v2v(const Image<I>& input_, const Function_v2v<F>& f_) { - trace::entering("level::impl::transform_lowq"); + trace::entering("level::impl::transform_lowq_v2v"); mlc_is(mln_trait_image_pw_io(mln_ch_value(I, mln_result(F))), trait::image::pw_io::read_write)::check(); @@ -118,6 +118,31 @@ namespace mln for_all(p) output(p) = lut(input(p)); + trace::exiting("level::impl::transform_lowq_v2v"); + return output; + } + + + template <typename I, typename F> + mln_ch_value(I, mln_result(F)) + transform_lowq_i2v(const Image<I>& input_, const Function_i2v<F>& f_) + { + trace::entering("level::impl::transform_lowq"); + + mlc_is(mln_trait_image_pw_io(mln_ch_value(I, mln_result(F))), + trait::image::pw_io::read_write)::check(); + + const I& input = exact(input_); + const F& f = exact(f_); + level::internal::transform_tests(input, f); + + mln_ch_value(I, mln_result(F)) output; + initialize(output, input); + + mln_piter(I) p(input.domain()); + for_all(p) + output(p) = f(input(p)); + trace::exiting("level::impl::transform_lowq"); return output; } @@ -125,9 +150,9 @@ namespace mln template <typename I, typename F> mln_ch_value(I, mln_result(F)) - transform_taken(const Image<I>& input_, const Function_v2v<F>& f_) + transform_taken_v2v(const Image<I>& input_, const Function_v2v<F>& f_) { - trace::entering("level::impl::transform_taken"); + trace::entering("level::impl::transform_taken_v2v"); mlc_is(mln_trait_image_pw_io(mln_ch_value(I, mln_result(F))), trait::image::pw_io::read_write)::check(); @@ -146,7 +171,32 @@ namespace mln for_all(p) output(p) = lut(input(p)); - trace::exiting("level::impl::transform_taken"); + trace::exiting("level::impl::transform_taken_v2v"); + return output; + } + + + template <typename I, typename F> + mln_ch_value(I, mln_result(F)) + transform_taken_i2v(const Image<I>& input_, const Function_i2v<F>& f_) + { + trace::entering("level::impl::transform_taken_i2v"); + + mlc_is(mln_trait_image_pw_io(mln_ch_value(I, mln_result(F))), + trait::image::pw_io::read_write)::check(); + + const I& input = exact(input_); + const F& f = exact(f_); + level::internal::transform_tests(input, f); + + mln_ch_value(I, mln_result(F)) output; + initialize(output, input); + + mln_piter(I) p(input.domain()); + for_all(p) + output(p) = f(input(p)); + + trace::exiting("level::impl::transform_taken_i2v"); return output; } @@ -189,12 +239,8 @@ namespace mln mln_pixter(const I) pi(input); mln_pixter(O) po(output); - po.start(); - for_all(pi) - { + for_all_2(pi, po) po.val() = f(pi.val()); - po.next(); - } trace::exiting("level::impl::transform_fast"); return output; @@ -227,7 +273,6 @@ namespace mln return output; } - template <typename I1, typename I2, typename F> mln_ch_value(I1, mln_result(F)) transform_fastest(const Image<I1>& input1_, const Image<I2>& input2_, @@ -293,9 +338,18 @@ namespace mln trait::image::quant::low, const Image<I>& input, const Function_v2v<F>& f) { - return level::impl::transform_taken(input, f); + return level::impl::transform_taken_v2v(input, f); } + template <typename I, typename F> + inline + mln_ch_value(I, mln_result(F)) + transform_dispatch(trait::image::vw_set::uni, + trait::image::quant::low, + const Image<I>& input, const Function_i2v<F>& f) + { + return level::impl::transform_taken_i2v(input, f); + } template <typename I, typename F> inline @@ -304,9 +358,18 @@ namespace mln trait::image::quant::low, const Image<I>& input, const Function_v2v<F>& f) { - return level::impl::transform_lowq(input, f); + return level::impl::transform_lowq_v2v(input, f); } + template <typename I, typename F> + inline + mln_ch_value(I, mln_result(F)) + transform_dispatch(trait::image::vw_set::any, + trait::image::quant::low, + const Image<I>& input, const Function_i2v<F>& f) + { + return level::impl::transform_lowq_i2v(input, f); + } template <typename I, typename F> inline @@ -328,7 +391,15 @@ namespace mln return level::impl::transform_fast_lowq(input, f); } - + template <typename I, typename F> + inline + mln_ch_value(I, mln_result(F)) + transform_dispatch(trait::image::quant::low, + trait::image::value_access::direct, + const Image<I>& input, const Function_i2v<F>& f) + { + return level::impl::transform_fast(input, f); + } template <typename I, typename F> inline @@ -339,7 +410,7 @@ namespace mln { return transform_dispatch(mln_trait_image_vw_set(I)(), mln_trait_image_quant(I)(), - input, f); + input, exact(f)); } @@ -351,7 +422,7 @@ namespace mln { return transform_dispatch(mln_trait_image_vw_set(I)(), mln_trait_image_quant(I)(), - input, f); + input, exact(f)); } template <typename I, typename F> @@ -376,11 +447,11 @@ namespace mln trait::image::value_alignement::with_grid)::value) return transform_dispatch(mln_trait_image_quant(I)(), mln_trait_image_value_access(I)(), - input, f_); + input, exact(f_)); else return transform_dispatch(mln_trait_image_vw_set(I)(), mln_trait_image_quant(I)(), - input, f_); + input, exact(f_)); } @@ -422,7 +493,7 @@ namespace mln transform_dispatch(const Image<I>& input, const Function_v2v<F>& f) { return transform_dispatch(mln_trait_image_value_storage(I)(), - input, f); + input, exact(f)); } template <typename I1, typename I2, typename F> diff --git a/milena/mln/literal/colors.hh b/milena/mln/literal/colors.hh index 8e1c135..6263c68 100644 --- a/milena/mln/literal/colors.hh +++ b/milena/mln/literal/colors.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,10 +28,9 @@ #ifndef MLN_LITERAL_COLORS_HH # define MLN_LITERAL_COLORS_HH -/*! \file mln/literal/colors.hh - * \brief Definition of the colors literal. - * - */ +/// \file mln/literal/colors.hh +/// +/// Definition of the colors literal. # include <mln/core/concept/literal.hh> diff --git a/milena/mln/value/label.hh b/milena/mln/value/label.hh index 8421133..4a97a5c 100644 --- a/milena/mln/value/label.hh +++ b/milena/mln/value/label.hh @@ -32,12 +32,13 @@ /// /// Define a generic class for labels. +# include <mln/debug/format.hh> # include <mln/metal/math/pow.hh> +# include <mln/trait/value_.hh> # include <mln/value/concept/symbolic.hh> # include <mln/value/internal/value_like.hh> # include <mln/value/internal/convert.hh> # include <mln/value/internal/encoding.hh> -# include <mln/trait/value_.hh> namespace mln -- 1.5.6.5