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

general.cc

00001 // Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
00002 // Laboratory (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 
00027 #include <mln/core/image/image2d.hh>
00028 #include <mln/value/int_u8.hh>
00029 #include <mln/io/pgm/load.hh>
00030 #include <mln/io/pbm/load.hh>
00031 
00032 #include <mln/win/all.hh>
00033 #include <mln/morpho/erosion.hh>
00034 #include <mln/morpho/dilation.hh>
00035 
00036 #include "tests/data.hh"
00037 
00038 
00039 int main()
00040 {
00041   using namespace mln;
00042   using value::int_u8;
00043 
00044 
00045   // Windows.
00046   win::rectangle2d rec(5, 5);
00047   win::hline2d     hline(7);
00048   win::vline2d     vline(7);
00049   win::diag2d      diag2d(7);
00050   win::backdiag2d  backdiag2d(7);
00051   win::octagon2d   oct(2 * 3 + 1);
00052 
00053   morpho::erosion_op  ero;
00054   morpho::dilation_op dil;
00055 
00056   {
00057     image2d<int_u8> lena, out, ref;
00058     io::pgm::load(lena, MLN_IMG_DIR "/small.pgm");
00059 
00060 
00061     // Rectangle (erosion).
00062 
00063     ref = morpho::impl::generic::general_on_function(ero, lena, rec);
00064 
00065     out = morpho::impl::general_rectangle2d(ero, lena, rec);
00066     mln_assertion(out == ref);
00067 
00068     out = morpho::impl::general_arbitrary_2d(ero, lena, rec);
00069     mln_assertion(out == ref);
00070 
00071     out = morpho::impl::general_directional(ero, lena, rec, 0);
00072     mln_assertion(out == ref);
00073 
00074     out = morpho::impl::general_directional(ero, lena, rec, 1);
00075     mln_assertion(out == ref);
00076 
00077 
00078     // Rectangle (dilation).
00079 
00080     ref = morpho::impl::generic::general_on_function(dil, lena, rec);
00081 
00082     out = morpho::impl::general_rectangle2d(dil, lena, rec);
00083     mln_assertion(out == ref);
00084 
00085     out = morpho::impl::general_arbitrary_2d(dil, lena, rec);
00086     mln_assertion(out == ref);
00087 
00088     out = morpho::impl::general_directional(dil, lena, rec, 0);
00089     mln_assertion(out == ref);
00090 
00091     out = morpho::impl::general_directional(dil, lena, rec, 1);
00092     mln_assertion(out == ref);
00093 
00094 
00095     // Hline.
00096     ref = morpho::impl::generic::general_on_function(ero, lena, hline);
00097 
00098     out = morpho::impl::general_directional(ero, lena, hline, 1);
00099     mln_assertion(out == ref);
00100 
00101     out = morpho::impl::general_line(ero, lena, hline);
00102     mln_assertion(out == ref);
00103 
00104 
00105     // Vline.
00106     ref = morpho::impl::generic::general_on_function(ero, lena, vline);
00107 
00108     out = morpho::impl::general_directional(ero, lena, vline, 0);
00109     mln_assertion(out == ref);
00110 
00111     out = morpho::impl::general_line(ero, lena, vline);
00112     mln_assertion(out == ref);
00113 
00114     /*
00115 
00116     // Diag2d.
00117     ref = morpho::impl::generic::erosion_on_function(lena, diag2d);
00118 
00119     // Backdiag2d.
00120     ref = morpho::impl::generic::erosion_on_function(lena, backdiag2d);
00121 
00122     // Octagon
00123     ref = morpho::impl::generic::erosion_on_function(lena, oct);
00124     // io::pgm::save(ref, "general-out_oct_ref.pgm");
00125 
00126     */
00127   }
00128 
00129 
00130   /*
00131 
00132   {
00133     trace::quiet = false;
00134 
00135     image2d<bool> pic;
00136     io::pbm::load(pic, MLN_IMG_DIR "/small.pbm");
00137 
00138     // morpho::impl::general_on_set_centered_fastest(ero, pic, win::rectangle2d(3,3));
00139     morpho::general(ero, pic, win::rectangle2d(3,3));
00140     morpho::general(dil, pic, win::rectangle2d(3,3));
00141 
00142     trace::quiet = true;
00143   }
00144 
00145   */
00146 
00147 
00148   {
00149     image2d<bool> pic, out, ref;
00150     io::pbm::load(pic, MLN_IMG_DIR "/small.pbm");
00151 
00152     // Rectangle (erosion).
00153 
00154     ref = morpho::impl::generic::general_on_set(ero, pic, rec);
00155 
00156     out = morpho::impl::general_on_set_centered(ero, pic, rec);
00157     mln_assertion(out == ref);
00158 
00159     out = morpho::impl::general_on_set_centered_fastest(ero, pic, rec);
00160     mln_assertion(out == ref);
00161 
00162     out = morpho::impl::general_rectangle2d(ero, pic, rec);
00163     mln_assertion(out == ref);
00164 
00165     out = morpho::impl::general_arbitrary_2d(ero, pic, rec);
00166     mln_assertion(out == ref);
00167 
00168     out = morpho::impl::general_directional(ero, pic, rec, 0);
00169     mln_assertion(out == ref);
00170 
00171     out = morpho::impl::general_directional(ero, pic, rec, 1);
00172     mln_assertion(out == ref);
00173 
00174 
00175     // Rectangle (dilation).
00176 
00177     ref = morpho::impl::generic::general_on_set(dil, pic, rec);
00178 
00179     out = morpho::impl::general_on_set_centered(dil, pic, rec);
00180     mln_assertion(out == ref);
00181 
00182     out = morpho::impl::general_on_set_centered_fastest(dil, pic, rec);
00183     mln_assertion(out == ref);
00184 
00185     out = morpho::impl::general_rectangle2d(dil, pic, rec);
00186     mln_assertion(out == ref);
00187 
00188     out = morpho::impl::general_arbitrary_2d(dil, pic, rec);
00189     mln_assertion(out == ref);
00190 
00191     out = morpho::impl::general_directional(dil, pic, rec, 0);
00192     mln_assertion(out == ref);
00193 
00194     out = morpho::impl::general_directional(dil, pic, rec, 1);
00195     mln_assertion(out == ref);
00196   }
00197 
00198 }

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