
* mln/data/compute_in_window.hh: New. * tests/data/Makefile.am: New target. * tests/data/compute_in_window.cc: New test. --- milena/ChangeLog | 10 + milena/mln/data/compute_in_window.hh | 248 ++++++++++++++++++++ milena/tests/data/Makefile.am | 2 + ...ithout_localization.cc => compute_in_window.cc} | 66 +++--- 4 files changed, 292 insertions(+), 34 deletions(-) create mode 100644 milena/mln/data/compute_in_window.hh copy milena/tests/data/{paste_without_localization.cc => compute_in_window.cc} (61%) diff --git a/milena/ChangeLog b/milena/ChangeLog index 900764c..a628305 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,15 @@ 2011-11-23 Guillaume Lazzara <z@lrde.epita.fr> + New routine in Milena. + + * mln/data/compute_in_window.hh: New. + + * tests/data/Makefile.am: New target. + + * tests/data/compute_in_window.cc: New test. + +2011-11-23 Guillaume Lazzara <z@lrde.epita.fr> + Fix compilation with multiple files. * mln/canvas/browsing/backdiagonal2d.hh, diff --git a/milena/mln/data/compute_in_window.hh b/milena/mln/data/compute_in_window.hh new file mode 100644 index 0000000..297a923 --- /dev/null +++ b/milena/mln/data/compute_in_window.hh @@ -0,0 +1,248 @@ +// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef MLN_DATA_COMPUTE_HH +# define MLN_DATA_COMPUTE_HH + +/// \file +/// +/// Compute an accumulator for each image pixel values using neighbor +/// pixel values. + +# include <mln/accu/image/init.hh> +# include <mln/accu/image/to_result.hh> +# include <mln/core/concept/meta_accumulator.hh> +# include <mln/border/mirror.hh> +# include <mln/extension/adjust.hh> + +# include <mln/debug/println_with_border.hh> + +namespace mln +{ + + namespace data + { + + + /// Compute an accumulator for each image pixel values using neighbor + /// pixel values. + template <typename A, typename I, typename W> + mln_ch_value(I, mln_result(A)) + compute_in_window(const Accumulator<A>& a, const Image<I>& input, + const Window<W>& win); + + /// \overload + /// + /// \param[in] a A meta-accumulator. + /// \param[in] input The input image. + /// \return The accumulator result. + /// + template <typename A, typename I, typename W> + mln_ch_value(I, mln_result(A)) + compute_in_window(const Meta_Accumulator<A>& a, const Image<I>& input, + const Window<W>& win); + + + +# ifndef MLN_INCLUDE_ONLY + + namespace internal + { + + template <typename A, typename I, typename W> + void + compute_in_window_tests(const Accumulator<A>& a, const Image<I>& input_, + const Window<W>& win_) + { + (void) a; + const W& win = exact(win_); + const I& input = exact(input_); + + mln_assertion(win.is_valid()); + mln_assertion(input.is_valid()); + } + + } // end of namespace mln::data::internal + + + namespace impl + { + + namespace generic + { + + template <typename A, typename I, typename W> + mln_ch_value(I, mln_result(A)) + compute_in_window(const Accumulator<A>& a, + const Image<I>& input_, + const Window<W>& win_) + { + trace::entering("mln::impl::generic::compute_in_window"); + + const I& input = exact(input_); + const W& win = exact(win_); + + internal::compute_in_window_tests(a, input, win); + + mln_ch_value(I, A) accu; + initialize(accu, input); + + accu::image::init(accu); + + mln_piter(I) p(accu.domain()); + mln_qiter(W) q(win, p); + + for_all(p) + for_all(q) + if (input.domain().has(q)) + accu(p).take(input(q)); + + mln_ch_value(I, mln_result(A)) + output = accu::image::to_result(accu); + + trace::exiting("mln::impl::generic::compute_in_window"); + return output; + } + + } // end of namespace mln::impl::generic + + + template <typename A, typename I, typename W> + mln_ch_value(I, mln_result(A)) + compute_in_window_fastest(const Accumulator<A>& a, + const Image<I>& input_, + const Window<W>& win_) + { + trace::entering("mln::impl::generic::compute_in_window_fastest"); + + const W& win = exact(win_); + const I& input = exact(input_); + + internal::compute_in_window_tests(a, input, win); + + typedef mln_ch_value(I, A) J; + J accu; + initialize(accu, input); + + accu::image::init(accu); + + extension::adjust(input, win); + border::mirror(input); + + mln_pixter(J) p(accu); + mln_qixter(J, W) q(p, win); + + for_all(p) + for_all(q) + p.val().take(input.element(q.offset())); + + mln_ch_value(I, mln_result(A)) + output = accu::image::to_result(accu); + + trace::exiting("mln::impl::generic::compute_in_window_fastest"); + return output; + } + + + } // end of namespace mln::data::impl + + + // Dispatch + + namespace internal + { + + template <typename A, typename I, typename W> + mln_ch_value(I, mln_result(A)) + compute_in_window_dispatch(const Accumulator<A>& a, + const Image<I>& input, + const Window<W>& win, + trait::image::speed::fastest) + { + return impl::compute_in_window_fastest(a, input, win); + } + + template <typename A, typename I, typename W> + mln_ch_value(I, mln_result(A)) + compute_in_window_dispatch(const Accumulator<A>& a, + const Image<I>& input, + const Window<W>& win, + trait::image::speed::any) + { + return impl::generic::compute_in_window(a, input, win); + } + + template <typename A, typename I, typename W> + mln_ch_value(I, mln_result(A)) + compute_in_window_dispatch(const Accumulator<A>& a, + const Image<I>& input, + const Window<W>& win) + { + return compute_in_window_dispatch(a, input, win, + mln_trait_image_speed(I)()); + } + + } // end of namespace mln::data::internal + + + + // Facades. + + template <typename A, typename I, typename W> + mln_ch_value(I, mln_result(A)) + compute_in_window(const Accumulator<A>& a, const Image<I>& input, + const Window<W>& win) + { + trace::entering("data::compute_in_window"); + + internal::compute_in_window_tests(a, input, win); + + mln_ch_value(I, mln_result(A)) + output = data::internal::compute_in_window_dispatch(a, input, win); + + trace::exiting("data::compute_in_window"); + return output; + } + + + template <typename A, typename I, typename W> + mln_ch_value(I, mln_result(A)) + compute_in_window(const Meta_Accumulator<A>& a, const Image<I>& input, + const Window<W>& win) + { + typedef mln_accu_with(A, mln_value(I)) A_; + A_ a_ = accu::unmeta(exact(a), mln_value(I)()); + + return data::compute_in_window(a_, input, win); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::data + +} // end of namespace mln + + +#endif // ! MLN_DATA_COMPUTE_HH diff --git a/milena/tests/data/Makefile.am b/milena/tests/data/Makefile.am index 205337e..4b04dfb 100644 --- a/milena/tests/data/Makefile.am +++ b/milena/tests/data/Makefile.am @@ -23,6 +23,7 @@ check_PROGRAMS = \ apply \ compare \ compute \ + compute_in_window \ convert \ fill \ fill_with_image \ @@ -45,6 +46,7 @@ abs_SOURCES = abs.cc apply_SOURCES = apply.cc compare_SOURCES = compare.cc compute_SOURCES = compute.cc +compute_in_window_SOURCES = compute_in_window.cc convert_SOURCES = convert.cc fill_SOURCES = fill.cc fill_with_image_SOURCES = fill_with_image.cc diff --git a/milena/tests/data/paste_without_localization.cc b/milena/tests/data/compute_in_window.cc similarity index 61% copy from milena/tests/data/paste_without_localization.cc copy to milena/tests/data/compute_in_window.cc index dd0f479..8df7f7a 100644 --- a/milena/tests/data/paste_without_localization.cc +++ b/milena/tests/data/compute_in_window.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,59 +23,57 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. +#include <mln/debug/println.hh> #include <mln/core/image/image2d.hh> - -#include <mln/data/paste_without_localization.hh> -#include <mln/data/compare.hh> - +#include <mln/core/alias/window2d.hh> +#include <mln/data/compute_in_window.hh> #include <mln/debug/iota.hh> -#include <mln/debug/println.hh> +#include <mln/accu/stat/mean.hh> +#include <mln/make/image2d.hh> +#include <mln/data/compare.hh> +#include <mln/data/convert.hh> int main() { using namespace mln; - box2d b(point2d(1,2), point2d(6,8)); - image2d<unsigned> ima(b, 3); + image2d<int> ima(3, 3); debug::iota(ima); - image2d<unsigned> tmp(6, 7, 3); - image2d<unsigned> ref(6, 7, 3); - debug::iota(ref); + // Generic + { + int data[] = { + 3, 3, 4, + 4, 5, 5, + 6, 6, 7 + }; + accu::stat::mean<int> m; + image2d<float> res = data::impl::generic::compute_in_window(m, ima, win_c8p()); + image2d<int> res_i = data::convert(int(), res); - // Lines - { - data::impl::paste_without_localization_lines(ima, tmp); - mln_assertion(tmp == ref); + image2d<int> ref = make::image2d(data); + + mln_assertion(res_i == ref); } // Fastest { - data::impl::paste_without_localization_fastest(ima, tmp); - mln_assertion(tmp == ref); - } + int data[] = { + 2, 3, 4, + 4, 5, 6, + 6, 7, 8 + }; - // Fast - { - data::impl::paste_without_localization_fast(ima, tmp); - mln_assertion(tmp == ref); - } - - // Generic - { - data::impl::generic::paste_without_localization(ima, tmp); - mln_assertion(tmp == ref); - } + accu::stat::mean<int> m; + image2d<float> res = data::compute_in_window(m, ima, win_c8p()); + image2d<int> res_i = data::convert(int(), res); + image2d<int> ref = make::image2d(data); - // Dispatch - { - data::paste_without_localization(ima, tmp); - mln_assertion(tmp == ref); + mln_assertion(res_i == ref); } - } -- 1.7.2.5