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 
00026 #include <cstdlib>
00027 
00028 #include <string>
00029 
00030 #include <mln/core/image/complex_image.hh>
00031 #include <mln/core/image/complex_neighborhoods.hh>
00032 #include <mln/core/image/complex_windows.hh>
00033 
00034 #include <mln/value/int_u8.hh>
00035 #include <mln/value/label_16.hh>
00036 
00037 #include <mln/data/fill.hh>
00038 #include <mln/math/diff_abs.hh>
00039 #include <mln/literal/zero.hh>
00040 
00041 #include <mln/io/off/load.hh>
00042 #include <mln/io/off/save.hh>
00043 #include <mln/labeling/colorize.hh>
00044 
00045 #include "chain.hh"
00046 
00047 
00048 
00049 
00050 
00051 template <unsigned D, typename G, typename V>
00052 inline
00053 mln::complex_image<D, G, V>
00054 gradient_on_edges(const mln::complex_image<D, G, V>& input)
00055 {
00056   typedef mln::complex_image<D, G, V> ima_t;
00057   ima_t output (input.domain());
00058   mln::data::fill(output, mln::literal::zero);
00059 
00060   
00061   mln::p_n_faces_fwd_piter<D, G> e(input.domain(), 1);
00062   
00063   typedef mln::complex_higher_neighborhood<D, G> e2t_t;
00064   e2t_t e2t;
00065   mln_niter(e2t_t) t(e2t, e);
00066   
00067   for_all(e)
00068   {
00069     t.start();
00070     
00071     if (!t.is_valid())
00072       abort();
00073     V v1 = input(t);
00074     t.next();
00075     
00076     
00077     if (t.is_valid())
00078       {
00079         V v2 = input(t);
00080         output(e) = mln::math::diff_abs(v1, v2);
00081         
00082         t.next();
00083         mln_assertion(!t.is_valid());
00084       }
00085   }
00086   return output;
00087 }
00088 
00089 
00090 int main(int argc, char* argv[])
00091 {
00092   if (argc != 4)
00093     {
00094       std::cerr << "usage: " << argv[0] << " input.off lambda output.off"
00095                 << std::endl;
00096       std::exit(1);
00097     }
00098   std::string input_filename = argv[1];
00099   unsigned lambda = atoi(argv[2]);
00100   std::string output_filename = argv[3];
00101 
00102   using namespace mln;
00103 
00104   typedef float val;
00105   typedef value::label_16 label;
00106   
00107   typedef mln::float_2complex_image3df input;
00108   typedef mln_ch_value_(input, label) output;
00109   static const unsigned dim = input::dim;
00110   typedef mln_geom_(input) geom;
00111   complex_lower_dim_connected_n_face_neighborhood<dim, geom> nbh;
00112   complex_lower_dim_connected_n_face_window_p<dim, geom> win;
00113   label nbasins;
00114 
00115   
00116   
00117 
00118 
00119 
00120   input ima;
00121   io::off::load(ima, input_filename);
00122 
00123   
00124   input g = gradient_on_edges(ima);
00125   output s = chain(ima, nbh, lambda, nbasins);
00126   io::off::save(labeling::colorize(value::rgb8(), s, nbasins),
00127                 output_filename);
00128 }