• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

erosion.cc

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

Generated on Tue Oct 4 2011 15:23:45 for Milena (Olena) by  doxygen 1.7.1