00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdio.h>
00029 #include <time.h>
00030
00031 #include <mln/core/image/image2d.hh>
00032 #include <mln/win/all.hh>
00033
00034 #include <mln/io/pgm/load.hh>
00035 #include <mln/io/pgm/save.hh>
00036
00037 #include <mln/value/int_u8.hh>
00038 #include <mln/debug/iota.hh>
00039 #include <mln/debug/println.hh>
00040
00041 #include <mln/data/approx/median.hh>
00042 #include <mln/data/fast_median.hh>
00043 #include <mln/data/median.hh>
00044
00045 #include <mln/core/dpoints_pixter.hh>
00046 #include <mln/core/pixel.hh>
00047
00048 #include "tests/data.hh"
00049
00050 using namespace mln;
00051 using value::int_u8;
00052
00053 class timer
00054 {
00055 public:
00056 void start()
00057 {
00058 start_ = clock();
00059 }
00060
00061 void stop()
00062 {
00063 end_ = clock();
00064 len = float(end_ - start_) / CLOCKS_PER_SEC;
00065 }
00066
00067 float lenght()
00068 {
00069 return len;
00070 }
00071
00072 private:
00073 clock_t start_;
00074 clock_t end_;
00075 float len;
00076 };
00077
00078
00079 std::ostream& operator<<(std::ostream& ostr, timer t)
00080 {
00081 return ostr << t.lenght() << "s";
00082 }
00083
00084 template <typename I, typename W, typename O>
00085 void tests(const Image<I>& input, const Window<W>& win,
00086 Image<O>& output)
00087 {
00088 timer chrono;
00089
00090 chrono.start();
00091 data::fast_median(input, win, output);
00092 chrono.stop();
00093 std::cout << "Fast median : " << chrono << std::endl;
00094
00095 chrono.start();
00096 data::median(input, win, output);
00097 chrono.stop();
00098 std::cout << "Median : " << chrono << std::endl;
00099
00100 chrono.start();
00101 data::approx::median(input, exact(win), output);
00102 chrono.stop();
00103 std::cout << "Approx median : " << chrono << std::endl;
00104
00105 }
00106
00107 int main()
00108 {
00109 {
00110 std::cout << "-----------------------" << std::endl;
00111 std::cout << "-----With rectangle 21x21" << std::endl;
00112 std::cout << "-----------------------" << std::endl;
00113
00114 win::rectangle2d rect(21, 21);
00115 border::thickness = 50;
00116
00117 image2d<int_u8> lena;
00118 io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
00119 image2d<int_u8> out(lena.domain());
00120
00121 tests(lena, rect, out);
00122 io::pgm::save(out, "out.pgm");
00123
00124 }
00125
00126 {
00127 std::cout << "-----------------------" << std::endl;
00128 std::cout << "-----With octogone 13" << std::endl;
00129 std::cout << "-----------------------" << std::endl;
00130
00131 win::octagon2d oct(13);
00132 border::thickness = 50;
00133
00134 image2d<int_u8> lena;
00135 io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
00136 image2d<int_u8> out(lena.domain());
00137
00138 tests(lena, oct, out);
00139 io::pgm::save(out, "out_oct.pgm");
00140 }
00141
00142
00143 {
00144 std::cout << "-----------------------" << std::endl;
00145 std::cout << "-----With disk2d 10" << std::endl;
00146 std::cout << "-----------------------" << std::endl;
00147
00148 win::disk2d win(10);
00149 border::thickness = 50;
00150
00151 image2d<int_u8> lena;
00152 io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
00153 image2d<int_u8> out(lena.domain());
00154
00155 tests(lena, win, out);
00156 io::pgm::save(out, "out_oct.pgm");
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 }