00001 // Copyright (C) 2007, 2008 EPITA Research and Development Laboratory 00002 // (LRDE) 00003 // 00004 // This file is part of the Milena Library. This library is free 00005 // software; you can redistribute it and/or modify it under the terms 00006 // of the GNU General Public License version 2 as published by the 00007 // Free Software Foundation. 00008 // 00009 // This library 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 this library; see the file COPYING. If not, write to 00016 // the Free Software Foundation, 51 Franklin Street, Fifth Floor, 00017 // Boston, MA 02111-1307, USA. 00018 // 00019 // As a special exception, you may use this file as part of a free 00020 // software library without restriction. Specifically, if other files 00021 // instantiate templates or use macros or inline functions from this 00022 // file, or you compile this file and link it with other files to 00023 // produce an executable, this file does not by itself cause the 00024 // resulting executable to be covered by the GNU General Public 00025 // License. This exception does not however invalidate any other 00026 // reasons why the executable file might be covered by the GNU General 00027 // Public License. 00028 00034 #include <mln/core/image/image2d.hh> 00035 #include <mln/win/all.hh> 00036 00037 #include <mln/debug/iota.hh> 00038 00039 #include <mln/io/pgm/load.hh> 00040 #include <mln/io/pgm/save.hh> 00041 00042 #include <mln/value/int_u8.hh> 00043 #include <mln/morpho/erosion.hh> 00044 #include <mln/arith/diff_abs.hh> 00045 00046 #include "tests/data.hh" 00047 #include "tests/timer.hh" 00048 00049 00050 int main() 00051 { 00052 using namespace mln; 00053 using value::int_u8; 00054 00055 // unsigned 00056 // l_oct = 11, L_oct = 6 * l_oct + 1, 00057 // l_rec = 29, L_rec = 2 * l_rec + 1; 00058 00059 // l_ 00060 // oct rec err 00061 // 0 0 3 00062 // 0 1 5 00063 // 1 2 15 00064 // 1 3 9 00065 // 2 5 11 00066 // 3 8 9 00067 // 5 13 15 00068 // 8 21 11 00069 // 11 29 1 00070 // 25 66 15 00071 00072 border::thickness = 20; 00073 image2d<int_u8> lena; 00074 io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm"); 00075 00076 win::rectangle2d rec(21, 21); 00077 win::hline2d hline(31); 00078 win::vline2d vline(31); 00079 win::diag2d diag2d(31); 00080 win::backdiag2d backdiag2d(31); 00081 win::octagon2d oct(6 * 3 + 1); 00082 win::disk2d disk(6 * 3 + 1); 00083 image2d<int_u8> out; 00084 image2d<int_u8> ref; 00085 // trace::quiet = false; 00086 timer t; 00087 00088 /* 00089 // Rectangle 00090 std::cout << "-------------------------- Rectangle: " << std::endl; 00091 00092 { 00093 t.start(); 00094 ref = morpho::impl::generic::erosion_on_function(lena, rec); 00095 std::cout << "generic on rectangle2d: " << t << std::endl; 00096 } 00097 00098 { 00099 t.start(); 00100 out = morpho::erosion(lena, rec); 00101 std::cout << "dispach on rectangle2d: " << t << std::endl; 00102 bool test = out == ref; 00103 mln_assertion(test); 00104 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00105 } 00106 00107 { 00108 t.start(); 00109 out = morpho::impl::erosion_arbitrary_2d_fastest(lena, rec); 00110 std::cout << "erosion_arbitrary_2d_fastest on rectangle2d: " << t << std::endl; 00111 bool test = out == ref; 00112 mln_assertion(test); 00113 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00114 } 00115 00116 { 00117 t.start(); 00118 out = morpho::impl::erosion_arbitrary_2d(lena, rec); 00119 std::cout << "erosion_arbitrary_2d on rectangle2d: " << t << std::endl; 00120 bool test = out == ref; 00121 mln_assertion(test); 00122 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00123 } 00124 00125 //Hline 00126 00127 std::cout << "-------------------------- Hline2d: " << std::endl; 00128 00129 { 00130 t.start(); 00131 ref = morpho::impl::generic::erosion_on_function(lena, hline); 00132 std::cout << "generic on hline2d: " << t << std::endl; 00133 } 00134 00135 { 00136 t.start(); 00137 out = morpho::erosion(lena, hline); 00138 std::cout << "dispach on hline2d : " << t << std::endl; 00139 bool test = out == ref; 00140 mln_assertion(test); 00141 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00142 } 00143 00144 { 00145 t.start(); 00146 out = morpho::impl::erosion_arbitrary_2d_fastest(lena, hline); 00147 std::cout << "erosion_arbitrary_2d_fastest on hline2d: " << t << std::endl; 00148 bool test = out == ref; 00149 mln_assertion(test); 00150 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00151 } 00152 00153 00154 { 00155 t.start(); 00156 out = morpho::impl::erosion_arbitrary_2d(lena, hline); 00157 std::cout << "erosion_arbitrary_2d on hline2d: " << t << std::endl; 00158 bool test = out == ref; 00159 mln_assertion(test); 00160 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00161 } 00162 00163 std::cout << "-------------------------- Vline2d: "<< std::endl; 00164 00165 //Vline 00166 { 00167 t.start(); 00168 ref = morpho::impl::generic::erosion_on_function(lena, vline); 00169 std::cout << "generic on vline2d: " << t << std::endl; 00170 } 00171 00172 { 00173 t.start(); 00174 out = morpho::erosion(lena, vline); 00175 std::cout << "dispach on vline2d : " << t << std::endl; 00176 bool test = out == ref; 00177 mln_assertion(test); 00178 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00179 } 00180 00181 00182 { 00183 t.start(); 00184 out = morpho::impl::erosion_arbitrary_2d_fastest(lena, vline); 00185 std::cout << "erosion_arbitrary_2d_fastest on vline2d: " << t << std::endl; 00186 bool test = out == ref; 00187 mln_assertion(test); 00188 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00189 } 00190 00191 00192 { 00193 t.start(); 00194 out = morpho::impl::erosion_arbitrary_2d(lena, vline); 00195 std::cout << "erosion_arbitrary_2d on vline2d: " << t << std::endl; 00196 bool test = out == ref; 00197 mln_assertion(test); 00198 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00199 } 00200 00201 00202 //Diag2d 00203 std::cout << "-------------------------- Diag2d: "<< std::endl; 00204 { 00205 t.start(); 00206 ref = morpho::impl::generic::erosion_on_function(lena, diag2d); 00207 std::cout << "generic on diag2d: " << t << std::endl; 00208 } 00209 00210 { 00211 t.start(); 00212 out = morpho::erosion(lena, diag2d); 00213 std::cout << "dispach on diag2d : " << t << std::endl; 00214 bool test = out == ref; 00215 mln_assertion(test); 00216 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00217 } 00218 00219 00220 { 00221 t.start(); 00222 out = morpho::impl::erosion_arbitrary_2d_fastest(lena, diag2d); 00223 std::cout << "erosion_arbitrary_2d_fastest on diag2d: " << t << std::endl; 00224 bool test = out == ref; 00225 mln_assertion(test); 00226 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00227 } 00228 00229 00230 { 00231 t.start(); 00232 out = morpho::impl::erosion_arbitrary_2d(lena, diag2d); 00233 std::cout << "erosion_arbitrary_2d on diag2d: " << t << std::endl; 00234 bool test = out == ref; 00235 mln_assertion(test); 00236 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00237 } 00238 00239 //Backdiag2d 00240 std::cout << "-------------------------- Backdiag2d: "<< std::endl; 00241 { 00242 t.start(); 00243 ref = morpho::impl::generic::erosion_on_function(lena, backdiag2d); 00244 std::cout << "generic on backdiag2d: " << t << std::endl; 00245 } 00246 00247 { 00248 t.start(); 00249 out = morpho::erosion(lena, backdiag2d); 00250 std::cout << "dispach on backdiag2d : " << t << std::endl; 00251 bool test = out == ref; 00252 mln_assertion(test); 00253 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00254 } 00255 00256 00257 { 00258 t.start(); 00259 out = morpho::impl::erosion_arbitrary_2d_fastest(lena, backdiag2d); 00260 std::cout << "erosion_arbitrary_2d_fastest on backdiag2d: " << t << std::endl; 00261 bool test = out == ref; 00262 mln_assertion(test); 00263 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00264 } 00265 00266 00267 { 00268 t.start(); 00269 out = morpho::impl::erosion_arbitrary_2d(lena, backdiag2d); 00270 std::cout << "erosion_arbitrary_2d on backdiag2d: " << t << std::endl; 00271 bool test = out == ref; 00272 mln_assertion(test); 00273 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00274 } 00275 */ 00276 std::cout << "-------------------------- Octagon: " << std::endl; 00277 border::thickness = 0; 00278 // Octagon 00279 { 00280 t.start(); 00281 ref = morpho::impl::generic::erosion_on_function(lena, oct); 00282 std::cout << "generic on octagon: " << t << std::endl; 00283 io::pgm::save(ref, "out_oct_ref.pgm"); 00284 } 00285 00286 { 00287 t.start(); 00288 out = morpho::erosion(lena, oct); 00289 std::cout << "dispach on octagon: " << t << std::endl; 00290 io::pgm::save(out, "out_oct.pgm"); 00291 io::pgm::save(arith::diff_abs(out, ref), "diff.pgm"); 00292 00293 bool test = out == ref; 00294 mln_assertion(test); 00295 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00296 } 00297 00298 00299 std::cout << "-------------------------- Disk: " << std::endl; 00300 00301 // Disk 00302 { 00303 t.start(); 00304 ref = morpho::impl::generic::erosion_on_function(lena, disk); 00305 std::cout << "generic on disk: " << t << std::endl; 00306 io::pgm::save(ref, "out_disk_ref.pgm"); 00307 } 00308 00309 { 00310 t.start(); 00311 out = morpho::erosion(lena, disk); 00312 std::cout << "dispach on disk: " << t << std::endl; 00313 bool test = out == ref; 00314 mln_assertion(test); 00315 std::cout << " " << (test ? "OK" : "KO!!!") << std::endl; 00316 } 00317 00318 }