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 
00029 
00030 #include <iostream>
00031 
00032 #include <mln/value/int_u8.hh>
00033 #include <mln/core/alias/point2d.hh>
00034 
00035 #include <mln/core/site_set/p_faces.hh>
00036 #include <mln/core/image/complex_image.hh>
00037 
00038 
00039 #include <mln/core/image/complex_windows.hh>
00040 #include <mln/core/image/complex_window_piter.hh>
00041 
00042 #include <mln/debug/iota.hh>
00043 
00044 #include <mln/morpho/erosion.hh>
00045 #include <mln/morpho/dilation.hh>
00046 
00047 
00048 
00049 
00050 
00051 template <typename I, typename W>
00052 void test_morpho(const mln::Image<I>& ima, const mln::Window<W> win,
00053                  const std::string& comment);
00054 
00055 
00056 int main()
00057 {
00058   using namespace mln;
00059 
00060   
00061 
00062 
00063 
00064   
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084   const unsigned D = 2;
00085 
00086   topo::complex<D> c;
00087 
00088   
00089   topo::n_face<0, D> v0 = c.add_face();
00090   topo::n_face<0, D> v1 = c.add_face();
00091   topo::n_face<0, D> v2 = c.add_face();
00092   topo::n_face<0, D> v3 = c.add_face();
00093 
00094   
00095   topo::n_face<1, D> e0 = c.add_face(v0 + v1);
00096   topo::n_face<1, D> e1 = c.add_face(v0 + v2);
00097   topo::n_face<1, D> e2 = c.add_face(v1 + v2);
00098   topo::n_face<1, D> e3 = c.add_face(v0 + v3);
00099   topo::n_face<1, D> e4 = c.add_face(v2 + v3);
00100 
00101   
00102   topo::n_face<2, D> t0 = c.add_face(e0 + e1 + e2);
00103   topo::n_face<2, D> t1 = c.add_face(e1 + e3 + e4);
00104 
00105 
00106   
00107 
00108 
00109 
00110   typedef point2d P;
00111   typedef geom::complex_geometry<D, P> G;
00112   G geom;
00113   geom.add_location(point2d(0,1)); 
00114   geom.add_location(point2d(2,0)); 
00115   geom.add_location(point2d(2,2)); 
00116   geom.add_location(point2d(0,3)); 
00117   p_complex<D, G> pc(c, geom);
00118 
00119 
00120   
00121 
00122 
00123 
00124   using mln::value::int_u8;
00125 
00126   
00127   
00128   typedef complex_image<D, G, int_u8> ima_t;
00129   ima_t ima(pc);
00130   
00131   debug::iota(ima);
00132 
00133   
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147   
00148   mln_piter_(ima_t) p(ima.domain());
00149   for_all (p)
00150     std::cout << "ima (" << p << ") = " << ima(p) << std::endl;
00151   std::cout << std::endl << std::endl;
00152 
00153   
00154 
00155 
00156 
00157   test_morpho(ima, complex_lower_window_p<D, G>(),
00158               "lower-dimension faces");
00159   test_morpho(ima, complex_higher_window_p<D, G>(),
00160               "higher-dimension faces");
00161   test_morpho(ima, complex_lower_higher_window_p<D, G>(),
00162               "lower- and higer-dimension faces");
00163 
00164   test_morpho(ima, complex_lower_dim_connected_n_face_window_p<D, G>(),
00165               "lower-dimension connected n-faces");
00166   test_morpho(ima, complex_higher_dim_connected_n_face_window_p<D, G>(),
00167               "higher-dimension connected n-faces");
00168 
00169   
00170 
00171 }
00172 
00173 
00174 template <typename I, typename W>
00175 void
00176 test_morpho(const mln::Image<I>& ima_, const mln::Window<W> win,
00177             const std::string& comment)
00178 {
00179   const I& ima = exact(ima_);
00180   mln_assertion(ima.is_valid());
00181   mln_piter(I) p(ima.domain());
00182 
00183   mln_concrete(I) ima_dil = mln::morpho::dilation(ima, win);
00184   
00185   std::cout << "Dilation using " << comment << ":" << std::endl;
00186   for_all (p)
00187     std::cout << "  ima_dil (" << p << ") = " << ima_dil(p) << std::endl;
00188   std::cout << std::endl;
00189 
00190   std::cout << "Erosion using " << comment  << ":" << std::endl;
00191   mln_concrete(I) ima_ero = mln::morpho::erosion(ima, win);
00192   
00193   for_all (p)
00194     std::cout << "  ima_ero (" << p << ") = " << ima_ero(p) << std::endl;
00195   std::cout << std::endl << std::endl;
00196 }