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