cleanup-2008 2086: Augment gradient_elementary; it is a sample code.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Augment gradient_elementary; it is a sample code. * tests/morpho/gradient_elementary.cc: New. * tests/morpho/Makefile.am: Update. * mln/morpho/gradient_elementary.hh (gradient_elementary_): Rename as... (gradient_elementary_on_function): ...this. (gradient_elementary_on_set): New. (todo): Update. Add a selector. * img/tiny.pbm: New. mln/morpho/gradient_elementary.hh | 78 +++++++++++++++++++++++++++++++----- tests/morpho/Makefile.am | 2 tests/morpho/gradient_elementary.cc | 24 +++++++---- 3 files changed, 88 insertions(+), 16 deletions(-) Index: tests/morpho/gradient_elementary.cc --- tests/morpho/gradient_elementary.cc (revision 2085) +++ tests/morpho/gradient_elementary.cc (working copy) @@ -25,19 +25,21 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/morpho/gradient.cc +/*! \file tests/morpho/gradient_elementary.cc * - * \brief Test on mln::morpho::gradient. + * \brief Test on mln::morpho::gradient_elementary. */ #include <mln/core/image2d.hh> -#include <mln/win/rectangle2d.hh> +#include <mln/core/neighb2d.hh> +#include <mln/io/pbm/load.hh> +#include <mln/io/pbm/save.hh> #include <mln/io/pgm/load.hh> #include <mln/io/pgm/save.hh> #include <mln/value/int_u8.hh> -#include <mln/morpho/gradient.hh> +#include <mln/morpho/gradient_elementary.hh> #include "tests/data.hh" @@ -47,12 +49,20 @@ using namespace mln; using value::int_u8; - win::rectangle2d rect(5, 5); - border::thickness = 2; + border::thickness = 0; + { image2d<int_u8> lena; io::pgm::load(lena, MLN_IMG_DIR "/tiny.pgm"); - io::pgm::save( morpho::gradient(lena, rect), + io::pgm::save( morpho::gradient_elementary(lena, c4()), "out.pgm" ); } + { + image2d<bool> pic; + io::pbm::load(pic, MLN_IMG_DIR "/tiny.pbm"); + + io::pbm::save( morpho::gradient_elementary(pic, c4()), + "out.pbm" ); + } +} Index: tests/morpho/Makefile.am --- tests/morpho/Makefile.am (revision 2085) +++ tests/morpho/Makefile.am (working copy) @@ -11,6 +11,7 @@ erosion \ erosion_min_h \ gradient \ + gradient_elementary \ hit_or_miss \ laplacian \ lena_line_graph_image_wst1 \ @@ -35,6 +36,7 @@ contrast_SOURCES = contrast.cc gradient_SOURCES = gradient.cc +gradient_elementary_SOURCES = gradient_elementary.cc hit_or_miss_SOURCES = hit_or_miss.cc laplacian_SOURCES = laplacian.cc thinning_SOURCES = thinning.cc Index: mln/morpho/gradient_elementary.hh --- mln/morpho/gradient_elementary.hh (revision 2085) +++ mln/morpho/gradient_elementary.hh (working copy) @@ -31,11 +31,12 @@ /// \file mln/morpho/gradient_elementary.hh /// \brief Morphological elementary gradient. /// -/// \todo Write specific code. +/// \todo Handle border + add fastest versions. # include <mln/core/concept/image.hh> # include <mln/core/concept/neighborhood.hh> # include <mln/accu/min_max.hh> +# include <mln/level/fill.hh> namespace mln @@ -68,10 +69,9 @@ template <typename I, typename N> mln_concrete(I) - gradient_elementary_(const mln::trait::image::kind::any&, - const I& input, const N& nbh) + gradient_elementary_on_function(const I& input, const N& nbh) { - trace::entering("morpho::impl::generic::gradient_elementary_"); + trace::entering("morpho::impl::generic::gradient_elementary_on_function"); mln_concrete(I) output; initialize(output, input); @@ -87,15 +87,76 @@ output(p) = m.second() - m.first(); } - trace::exiting("morpho::impl::generic::gradient_elementary_"); + trace::exiting("morpho::impl::generic::gradient_elementary_on_function"); return output; + } + + template <typename I, typename N> + mln_concrete(I) + gradient_elementary_on_set(const I& input, const N& nbh) + { + trace::entering("morpho::impl::generic::gradient_elementary_on_set"); + + mln_concrete(I) output; + initialize(output, input); + level::fill(output, false); + mln_piter(I) p(input.domain()); + mln_niter(N) n(nbh, p); + for_all(p) + { + bool b = input(p); + for_all(n) if (input.has(n)) + if (input(n) != b) + { + output(p) = true; + break; + } } - } // end of namespace mln::internal::generic + trace::exiting("morpho::impl::generic::gradient_elementary_on_set"); + return output; + } + + } // end of namespace mln::impl::generic - } // end of namespace mln::internal + // Different cases. + + template <typename I, typename N> + mln_concrete(I) + gradient_elementary_(const mln::trait::image::kind::any&, + const mln::trait::image::speed::any&, + const I& input, const N& nbh) + { + return generic::gradient_elementary_on_function(input, nbh); + } + + template <typename I, typename N> + mln_concrete(I) + gradient_elementary_(const mln::trait::image::kind::logic&, + const mln::trait::image::speed::any&, + const I& input, const N& nbh) + { + return generic::gradient_elementary_on_set(input, nbh); + } + + + // Selector. + + template <typename I, typename N> + mln_concrete(I) + gradient_elementary_(const I& input, const N& nbh) + { + return gradient_elementary_(mln_trait_image_kind(I)(), + mln_trait_image_speed(I)(), + input, nbh); + } + + } // end of namespace mln::impl + + + // Facade. template <typename I, typename N> mln_concrete(I) @@ -108,8 +169,7 @@ mln_precondition(input.has_data()); // FIXME: mln_precondition(! nbh.is_empty()); - mln_concrete(I) output = impl::generic::gradient_elementary_(mln_trait_image_kind(I)(), - input, nbh); + mln_concrete(I) output = impl::gradient_elementary_(input, nbh); trace::exiting("morpho::gradient_elementary"); return output; Index: img/tiny.pbm Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: img/tiny.pbm ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
participants (1)
-
Thierry Geraud