last-svn-commit-549-ga657c01 WIP: Split apps/bench/dilation-lena.

* apps/bench/dilation-lena.cc (nongen::dilation) (nongen_2ptr::dilation) (nongen_1ptr::dilation) (gen::dilation) (fast::dilation) (fast_noaccu::dilation) (faster::dilation) (faster_noaccu::dilation) (fast_static::dilation) (faster_static::dilation): Move functions... * apps/bench/dilation-lena.hh: ...here (new file). --- milena/apps/bench/Makefile.am | 2 +- milena/apps/bench/dilation-lena.cc | 314 +------------------- .../bench/{dilation-lena.cc => dilation-lena.hh} | 92 +------ 3 files changed, 9 insertions(+), 399 deletions(-) copy milena/apps/bench/{dilation-lena.cc => dilation-lena.hh} (79%) diff --git a/milena/apps/bench/Makefile.am b/milena/apps/bench/Makefile.am index 266b71b..40f0147 100644 --- a/milena/apps/bench/Makefile.am +++ b/milena/apps/bench/Makefile.am @@ -36,7 +36,7 @@ EXTRA_DIST += \ static_window.hh \ trait.hh -dilation_lena_SOURCES = dilation-lena.cc +dilation_lena_SOURCES = dilation-lena.cc dilation-lena.hh gradient_lena_SOURCES = gradient-lena.cc gradient_spe_lena_SOURCES = gradient-spe-lena.cc diff --git a/milena/apps/bench/dilation-lena.cc b/milena/apps/bench/dilation-lena.cc index e4996fb..82b4497 100644 --- a/milena/apps/bench/dilation-lena.cc +++ b/milena/apps/bench/dilation-lena.cc @@ -23,322 +23,10 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#include <cstddef> - -#include <iostream> - -#include <mln/core/image/image2d.hh> -#include <mln/core/alias/window2d.hh> - -#include <mln/io/pgm/load.hh> -#include <mln/io/pgm/save.hh> - -#include <mln/value/int_u8.hh> - -#include <mln/accu/stat/max.hh> - -#include <mln/util/timer.hh> - -#include "apps/bench/static_window.hh" -#include "apps/bench/static_dpoints_pixter.hh" -#include "apps/bench/trait.hh" - +#include "apps/bench/dilation-lena.hh" #include "apps/data.hh" - -namespace nongen -{ - typedef mln::image2d<mln::value::int_u8> image; - - image dilation(const image& input) - { - image output (input.nrows(), input.ncols()); // Initialize an output image. - for (unsigned int r = 0; r < input.nrows(); ++r) // Iterate on rows. - for (unsigned int c = 0; c < input.ncols(); ++c) - { // Iterate on columns. - unsigned char sup = input.at_(r, c); - if (r != 0 && input.at_(r-1, c) > sup) sup = input.at_(r-1, c); - if (r != input.nrows() - 1 && input.at_(r+1, c) > sup) sup = input.at_(r+1, c); - if (c != 0 && input.at_(r, c-1) > sup) sup = input.at_(r, c-1); - if (c != input.ncols() - 1 && input.at_(r, c+1) > sup) sup = input.at_(r, c+1); - output.at_(r, c) = sup; - } - return output; - } -} - -namespace nongen_2ptr -{ - typedef mln::image2d<mln::value::int_u8> image; - - image dilation(const image& input) - { - typedef mln::value::int_u8 val_t; - // Offsets corresponding to a 4-c window on INPUT. - ptrdiff_t win_offset[4] = { &input.at_(-1, 0) - &input.at_(0, 0), - &input.at_(+1, 0) - &input.at_(0, 0), - &input.at_( 0, -1) - &input.at_(0, 0), - &input.at_( 0, +1) - &input.at_(0, 0) }; - - image output (input.nrows(), input.ncols()); // Initialize an output image. - for (unsigned int r = 0; r < input.nrows(); ++r) // Iterate on rows. - { - const val_t* pi = &input.at_(r, 0); - val_t* po = &output.at_(r, 0); - for (; pi < &input.at_(r, 0) + input.ncols(); ++pi, ++po) - { - unsigned char sup = *pi; - // (-1, 0) neighbor. - if (r != 0 - && *(pi + win_offset[0]) > sup) - sup = *(pi + win_offset[0]); - // (+1, 0) neighbor. - if (r != input.nrows() - 1 - && *(pi + win_offset[1]) > sup) - sup = *(pi + win_offset[1]); - // (0, -1) neighbor. - if (pi != &input.at_(r, 0) - && *(pi + win_offset[2]) > sup) - sup = *(pi + win_offset[2]); - // (0, +1) neighbor. - if (pi != &input.at_(r, 0) + input.ncols() - 1 - && *(pi + win_offset[3]) > sup) - sup = *(pi + win_offset[3]); - *po = sup; - } - } - return output; - } -} - -namespace nongen_1ptr -{ - typedef mln::image2d<mln::value::int_u8> image; - - image dilation(const image& input) - { - typedef mln::value::int_u8 val_t; - // Offsets corresponding to a 4-c window on INPUT. - ptrdiff_t win_offset[4] = { &input.at_(-1, 0) - &input.at_(0, 0), - &input.at_(+1, 0) - &input.at_(0, 0), - &input.at_( 0, -1) - &input.at_(0, 0), - &input.at_( 0, +1) - &input.at_(0, 0) }; - - image output; - initialize(output, input); - // Offset between a the pixel located at the same position in - // INPUT and OUTPUT. - ptrdiff_t output_offset = &output.at_(0, 0) - &input.at_(0, 0); - - for (unsigned int r = 0; r < input.nrows(); ++r) // Iterate on rows. - { - for (const val_t* pi = &input.at_(r, 0); - pi < &input.at_(r, 0) + input.ncols(); - ++pi) - { - unsigned char sup = *pi; - // (-1, 0) neighbor. - if (r != 0 - && *(pi + win_offset[0]) > sup) - sup = *(pi + win_offset[0]); - // (+1, 0) neighbor. - if (r != input.nrows() - 1 - && *(pi + win_offset[1]) > sup) - sup = *(pi + win_offset[1]); - // (0, -1) neighbor. - if (pi != &input.at_(r, 0) - && *(pi + win_offset[2]) > sup) - sup = *(pi + win_offset[2]); - // (0, +1) neighbor. - if (pi != &input.at_(r, 0) + input.ncols() - 1 - && *(pi + win_offset[3]) > sup) - sup = *(pi + win_offset[3]); - const_cast<val_t&>(*(pi + output_offset)) = sup; - } - } - return output; - } -} - -namespace gen -{ - using namespace mln; - - template <typename I, typename W> - mln_concrete(I) dilation(const I& input, const W& win) - { - mln_concrete(I) output; initialize(output, input); // Initialize output. - mln_piter(I) p(input.domain()); // Iterator on sites of the domain of `input'. - mln_qiter(W) q(win, p); // Iterator on the neighbors of `p' w.r.t. `win'. - for_all(p) - { - // FIXME: Cheat: replace the accu::supremum by a maximum. - mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum. - for_all(q) if (input.has(q)) - sup.take(input(q)); - output(p) = sup.to_result(); - } - return output; - } -} - -namespace fast -{ - using namespace mln; - - template <typename I, typename W> - mln_concrete(I) dilation(const I& input, const W& win) - { - typedef mln_concrete(I) O; - O output; initialize(output, input); // Initialize output. - - mln_pixter(const I) pi(input); // Iterator on the pixels of `input'. - mln_pixter(O) po(output); // Iterator on the pixels of `output'. - - mln_qixter(const I, W) q(pi, win); // Iterator on the neighbors of `p' w.r.t. `win'. - for_all_2(pi, po) - { - // FIXME: Cheat: replace the accu::supremum by a maximum. - mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum. - for_all(q) - sup.take(q.val()); - po.val() = sup.to_result(); - } - return output; - } -} - -namespace fast_noaccu -{ - using namespace mln; - - template <typename I, typename W> - mln_concrete(I) dilation(const I& input, const W& win) - { - typedef mln_concrete(I) O; - O output; initialize(output, input); // Initialize output. - - mln_pixter(const I) pi(input); // Iterator on the pixels of `input'. - mln_pixter(O) po(output); // Iterator on the pixels of `output'. - - mln_qixter(const I, W) q(pi, win); // Iterator on the neighbors of `p' w.r.t. `win'. - for_all_2(pi, po) - { - // FIXME: Cheat: replace the accu::supremum by a maximum. - mln_value(I) sup = mln_min(mln_value(I)); - for_all(q) - if (q.val() > sup) - sup = q.val(); - po.val() = sup; - } - return output; - } -} - -namespace faster -{ - using namespace mln; - - template <typename I, typename W> - mln_concrete(I) dilation(const I& input, const W& win) - { - typedef mln_concrete(I) O; - O output; initialize(output, input); // Initialize output. - - mln_pixter(const I) p(input); // Iterator on the pixels of `input'. - - mln_qixter(const I, W) q(p, win); // Iterator on the neighbors of `p' w.r.t. `win'. - for_all(p) - { - // FIXME: Cheat: replace the accu::supremum by a maximum. - mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum. - for_all(q) - sup.take(q.val()); - *(output.buffer() + p.offset()) = sup.to_result(); - } - return output; - } -} - -namespace faster_noaccu -{ - using namespace mln; - - template <typename I, typename W> - mln_concrete(I) dilation(const I& input, const W& win) - { - typedef mln_concrete(I) O; - O output; initialize(output, input); // Initialize output. - - mln_pixter(const I) p(input); // Iterator on the pixels of `input'. - - mln_qixter(const I, W) q(p, win); // Iterator on the neighbors of `p' w.r.t. `win'. - for_all(p) - { - // FIXME: Cheat: replace the accu::supremum by a maximum. - mln_value(I) sup = mln_min(mln_value(I)); - for_all(q) - if (q.val() > sup) - sup = q.val(); - *(output.buffer() + p.offset()) = sup; - } - return output; - } -} - -namespace fast_static -{ - using namespace mln; - - template <typename I, typename W> - mln_concrete(I) dilation(const I& input, const W& win) - { - typedef mln_concrete(I) O; - O output; initialize(output, input); // Initialize output. - - mln_pixter(const I) pi(input); // Iterator on the pixels of `input'. - mln_pixter(O) po(output); // Iterator on the pixels of `output'. - mln_static_qixter(const I, W) q(pi, win); // Iterator on the neighbors of `p' w.r.t. `win'. - - for_all_2(pi, po) - { - // FIXME: Cheat: replace the accu::supremum by a maximum. - mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum. - for_all(q) - sup.take(q.val()); - po.val() = sup.to_result(); - } - return output; - } -} - -namespace faster_static -{ - using namespace mln; - - template <typename I, typename W> - mln_concrete(I) dilation(const I& input, const W& win) - { - typedef mln_concrete(I) O; - O output; initialize(output, input); // Initialize output. - - mln_pixter(const I) p(input); // Iterator on the pixels of `input'. - mln_static_qixter(const I, W) q(p, win); // Iterator on the neighbors of `p' w.r.t. `win'. - - for_all(p) - { - // FIXME: Cheat: replace the accu::supremum by a maximum. - mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum. - for_all(q) - sup.take(q.val()); - *(output.buffer() + p.offset()) = sup.to_result(); - } - return output; - } -} - - // Shortcut macros for run. #define DILATION_WITH_BUILTIN_WINDOW(Namespace, Suffix, Headline) \ diff --git a/milena/apps/bench/dilation-lena.cc b/milena/apps/bench/dilation-lena.hh similarity index 79% copy from milena/apps/bench/dilation-lena.cc copy to milena/apps/bench/dilation-lena.hh index e4996fb..c89eb4e 100644 --- a/milena/apps/bench/dilation-lena.cc +++ b/milena/apps/bench/dilation-lena.hh @@ -23,6 +23,12 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. +#ifndef APPS_BENCH_DILATION_LENA_HH +#define APPS_BENCH_DILATION_LENA_HH + +/// \file +/// \brief Dilation benchmark cases. + #include <cstddef> #include <iostream> @@ -43,9 +49,6 @@ #include "apps/bench/static_dpoints_pixter.hh" #include "apps/bench/trait.hh" -#include "apps/data.hh" - - namespace nongen { @@ -338,85 +341,4 @@ namespace faster_static } } - -// Shortcut macros for run. - -#define DILATION_WITH_BUILTIN_WINDOW(Namespace, Suffix, Headline) \ - do \ - { \ - d = lena; \ - t.start(); \ - for (unsigned i = 0; i < niters; ++i) \ - d = Namespace::dilation(d); \ - t.stop(); \ - std::cout << Headline << t.read() << " s" << std::endl; \ - io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \ - } \ - while (0) - -#define DILATION(Namespace, Win, Suffix, Headline) \ - do \ - { \ - d = lena; \ - t.start(); \ - for (unsigned i = 0; i < niters; ++i) \ - d = Namespace::dilation(d, Win); \ - t.stop(); \ - std::cout << Headline << t.read() << " s" << std::endl; \ - io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \ - } \ - while (0) - - -void -run(const std::string& filename, const std::string& length, unsigned niters) -{ - using namespace mln; - using value::int_u8; - - border::thickness = 1; - image2d<int_u8> lena; - io::pgm::load(lena, filename); - - image2d<int_u8> d; - util::timer t; - - std::string prefix = "dilation-lena-out"; - std::cout << "== " << filename << std::endl; - - DILATION_WITH_BUILTIN_WINDOW(nongen, "nongen", "nongen\t\t"); - DILATION_WITH_BUILTIN_WINDOW(nongen_2ptr, "nongen_2ptr", "nongen_2ptr\t"); - DILATION_WITH_BUILTIN_WINDOW(nongen_1ptr, "nongen_1ptr", "nongen_1ptr\t"); - - DILATION(gen, win_c4p(), "gen", "gen\t\t"); - // FIXME: Introduce a new test case, gen_static, using a static window - // and static_qiters. - DILATION(fast, win_c4p(), "fast", "fast\t\t"); - DILATION(fast_noaccu, win_c4p(), "fast_noaccu", "fast_noaccu\t"); - DILATION(faster, win_c4p(), "faster", "faster\t\t"); - DILATION(faster_noaccu, win_c4p(), "faster_noaccu", "faster_noaccu\t"); - - // Static windows and qixters. - const unsigned n = 5; - mln::dpoint2d dps[n] = { mln::dpoint2d( 0, -1), - mln::dpoint2d(-1, 0), - mln::dpoint2d( 0, 0), - mln::dpoint2d(+1, 0), - mln::dpoint2d( 0, +1) }; - mln::util::static_array<mln::dpoint2d, n> sa(dps, dps + n); - mln::static_window<mln::dpoint2d, n> static_win_c4p (sa); - - DILATION(fast_static, static_win_c4p, "fast_static", "fast_static\t"); - DILATION(faster_static, static_win_c4p, "faster_static", "faster_static\t"); - - std::cout << std::endl; -} - -int -main () -{ - unsigned niters = 10; - run(MLN_IMG_DIR "/lena.pgm", "512", niters); - run(MLN_APPS_DIR "/bench/lena1024.pgm", "1024", niters); - run(MLN_APPS_DIR "/bench/lena2048.pgm", "2048", niters); -} +#endif // ! APPS_BENCH_DILATION_LENA_HH -- 1.7.2.5
participants (1)
-
Roland Levillain