$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dilation-lena.cc
1 // Copyright (C) 2010, 2011 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #include <iostream>
27 
28 #include "apps/bench/dilation-lena.hh"
29 #include "apps/data.hh"
30 
31 
32 // Shortcut macros for run.
33 
34 #define DILATION_WITH_BUILTIN_WINDOW(Namespace, Suffix, Headline) \
35  do \
36  { \
37  d = lena; \
38  t.start(); \
39  for (unsigned i = 0; i < niters; ++i) \
40  d = Namespace::dilation(d); \
41  t.stop(); \
42  std::cout << Headline << t.read() << " s" << std::endl; \
43  io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \
44  } \
45  while (0)
46 
47 #define DILATION(Namespace, Win, Suffix, Headline) \
48  do \
49  { \
50  d = lena; \
51  t.start(); \
52  for (unsigned i = 0; i < niters; ++i) \
53  d = Namespace::dilation(d, Win); \
54  t.stop(); \
55  std::cout << Headline << t.read() << " s" << std::endl; \
56  io::pgm::save(d, prefix + '-' + length + '-' + Suffix + ".pgm"); \
57  } \
58  while (0)
59 
60 
61 void
62 run(const std::string& filename, const std::string& length, unsigned niters)
63 {
64  using namespace mln;
65  using value::int_u8;
66 
68  image2d<int_u8> lena;
69  io::pgm::load(lena, filename);
70 
72  util::timer t;
73 
74  std::string prefix = "dilation-lena-out";
75  std::cout << "== " << filename << std::endl;
76 
77  DILATION_WITH_BUILTIN_WINDOW(nongen, "nongen", "nongen\t\t");
78  DILATION_WITH_BUILTIN_WINDOW(nongen_2ptr, "nongen_2ptr", "nongen_2ptr\t");
79  DILATION_WITH_BUILTIN_WINDOW(nongen_1ptr, "nongen_1ptr", "nongen_1ptr\t");
80 
81  DILATION(gen, win_c4p(), "gen", "gen\t\t");
82  // FIXME: Introduce a new test case, gen_static, using a static window
83  // and static_qiters.
84  DILATION(fast, win_c4p(), "fast", "fast\t\t");
85  DILATION(fast_noaccu, win_c4p(), "fast_noaccu", "fast_noaccu\t");
86  DILATION(faster, win_c4p(), "faster", "faster\t\t");
87  DILATION(faster_noaccu, win_c4p(), "faster_noaccu", "faster_noaccu\t");
88 
89  // Static windows and qixters.
90  const unsigned n = 5;
91  mln::dpoint2d dps[n] = { mln::dpoint2d( 0, -1),
92  mln::dpoint2d(-1, 0),
93  mln::dpoint2d( 0, 0),
94  mln::dpoint2d(+1, 0),
95  mln::dpoint2d( 0, +1) };
97  mln::static_window<mln::dpoint2d, n> static_win_c4p (sa);
98 
99  DILATION(fast_static, static_win_c4p, "fast_static", "fast_static\t");
100  DILATION(faster_static, static_win_c4p, "faster_static", "faster_static\t");
101 
102  std::cout << std::endl;
103 }
104 
105 int
106 main ()
107 {
108  unsigned niters = 10;
109  run(MLN_IMG_DIR "/lena.pgm", "512", niters);
110  run(MLN_APPS_DIR "/bench/lena1024.pgm", "1024", niters);
111  run(MLN_APPS_DIR "/bench/lena2048.pgm", "2048", niters);
112 }