$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
median_bench.cc
1 // Copyright (C) 2007, 2008 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 <stdio.h>
27 #include <time.h>
28 
29 #include <mln/core/image/image2d.hh>
30 #include <mln/win/all.hh>
31 
32 #include <mln/io/pgm/load.hh>
33 #include <mln/io/pgm/save.hh>
34 
35 #include <mln/value/int_u8.hh>
36 #include <mln/debug/iota.hh>
37 #include <mln/debug/println.hh>
38 
39 #include <mln/data/approx/median.hh>
40 #include <mln/data/fast_median.hh>
41 #include <mln/data/median.hh>
42 
43 #include <mln/core/dpoints_pixter.hh>
44 #include <mln/core/pixel.hh>
45 
46 #include "tests/data.hh"
47 
48 using namespace mln;
49 using value::int_u8;
50 
51 class timer
52 {
53 public:
54  void start()
55  {
56  start_ = clock();
57  }
58 
59  void stop()
60  {
61  end_ = clock();
62  len = float(end_ - start_) / CLOCKS_PER_SEC;
63  }
64 
65  float lenght()
66  {
67  return len;
68  }
69 
70 private:
71  clock_t start_;
72  clock_t end_;
73  float len;
74 };
75 
76 
77 std::ostream& operator<<(std::ostream& ostr, timer t)
78 {
79  return ostr << t.lenght() << "s";
80 }
81 
82 template <typename I, typename W, typename O>
83 void tests(const Image<I>& input, const Window<W>& win,
84  Image<O>& output)
85 {
86  timer chrono;
87 
88  chrono.start();
89  data::fast_median(input, win, output);
90  chrono.stop();
91  std::cout << "Fast median : " << chrono << std::endl;
92 
93  chrono.start();
94  data::median(input, win, output);
95  chrono.stop();
96  std::cout << "Median : " << chrono << std::endl;
97 
98  chrono.start();
99  data::approx::median(input, exact(win), output);
100  chrono.stop();
101  std::cout << "Approx median : " << chrono << std::endl;
102 
103 }
104 
105 int main()
106 {
107  {
108  std::cout << "-----------------------" << std::endl;
109  std::cout << "-----With rectangle 21x21" << std::endl;
110  std::cout << "-----------------------" << std::endl;
111 
112  win::rectangle2d rect(21, 21);
113  border::thickness = 50;
114 
115  image2d<int_u8> lena;
116  io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
117  image2d<int_u8> out(lena.domain());
118 
119  tests(lena, rect, out);
120  io::pgm::save(out, "out.pgm");
121 
122  }
123 
124  {
125  std::cout << "-----------------------" << std::endl;
126  std::cout << "-----With octogone 13" << std::endl;
127  std::cout << "-----------------------" << std::endl;
128 
129  win::octagon2d oct(13);
130  border::thickness = 50;
131 
132  image2d<int_u8> lena;
133  io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
134  image2d<int_u8> out(lena.domain());
135 
136  tests(lena, oct, out);
137  io::pgm::save(out, "out_oct.pgm");
138  }
139 
140 
141  {
142  std::cout << "-----------------------" << std::endl;
143  std::cout << "-----With disk2d 10" << std::endl;
144  std::cout << "-----------------------" << std::endl;
145 
146  win::disk2d win(10);
147  border::thickness = 50;
148 
149  image2d<int_u8> lena;
150  io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
151  image2d<int_u8> out(lena.domain());
152 
153  tests(lena, win, out);
154  io::pgm::save(out, "out_oct.pgm");
155  }
156 
157 // {
158 // std::cout << "-----------------------" << std::endl;
159 // std::cout << "-----With hline 10" << std::endl;
160 // std::cout << "-----------------------" << std::endl;
161 
162 // win::hline2d win(10);
163 // border::thickness = 50;
164 
165 // image2d<int_u8> lena;
166 // io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
167 // image2d<int_u8> out(lena.domain());
168 
169 // tests(lena, win, out);
170 // io::pgm::save(out, "out_oct.pgm");
171 // }
172 
173 }