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