Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 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 // std::cout << "-----------------------" << std::endl; 00159 // std::cout << "-----With hline 10" << std::endl; 00160 // std::cout << "-----------------------" << std::endl; 00161 00162 // win::hline2d win(10); 00163 // border::thickness = 50; 00164 00165 // image2d<int_u8> lena; 00166 // io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm"); 00167 // image2d<int_u8> out(lena.domain()); 00168 00169 // tests(lena, win, out); 00170 // io::pgm::save(out, "out_oct.pgm"); 00171 // } 00172 00173 }