40 #include <mln/core/image/complex_image.hh>
41 #include <mln/core/image/complex_neighborhoods.hh>
43 #include <mln/morpho/closing/area.hh>
44 #include <mln/morpho/watershed/flooding.hh>
46 #include <mln/math/pi.hh>
47 #include <mln/math/max.hh>
48 #include <mln/math/sqr.hh>
50 #include <mln/literal/white.hh>
52 #include <mln/io/off/load.hh>
53 #include <mln/io/off/save.hh>
58 int main(
int argc,
char* argv[])
62 std::cerr <<
"usage: " << argv[0] <<
" input.off lambda output.off"
67 std::string input_filename = argv[1];
68 unsigned lambda = atoi(argv[2]);
69 std::string output_filename = argv[3];
78 static const unsigned D = float_ima_t::dim;
80 typedef mln_geom_(float_ima_t) G;
82 mln::bin_2complex_image3df bin_input;
83 mln::io::off::
load(bin_input, input_filename);
84 std::pair<float_ima_t, float_ima_t> curv =
85 mln::geom::mesh_curvature(bin_input.domain());
88 float_ima_t float_ima(bin_input.domain());
89 mln::p_n_faces_fwd_piter<D, G> v(float_ima.domain(), 0);
92 float h = (curv.first(v) + curv.second(v)) / 2;
102 adj_vertices_nbh_t adj_vertices_nbh;
103 mln_niter_(adj_vertices_nbh_t) adj_v(adj_vertices_nbh, e);
112 s += float_ima(adj_v);
115 float_ima(e) = s / n;
117 mln_invariant(n <= 2);
127 ima_t ima(float_ima.domain());
128 mln_piter_(ima_t) p(float_ima.domain());
130 ima(p) = 1000 * float_ima(p);
138 mln::complex_higher_dim_connected_n_face_neighborhood<D, G>
140 adj_edges_nbh_t adj_edges_nbh;
142 ima_t closed_ima = mln::morpho::closing::
area(ima, adj_edges_nbh, lambda);
157 typedef
unsigned wst_val_t;
159 typedef mln::unsigned_2complex_image3df wst_ima_t;
161 mln::morpho::watershed::
flooding(closed_ima, adj_edges_nbh, nbasins);
162 std::cout << "nbasins = " << nbasins << std::endl;
165 typedef mln::complex_higher_neighborhood<D, G> adj_polygons_nbh_t;
166 adj_polygons_nbh_t adj_polygons_nbh;
167 mln_niter_(adj_polygons_nbh_t) adj_p(adj_polygons_nbh, e);
171 wshed(adj_p) = wshed(e);
177 mln::rgb8_2complex_image3df output(wshed.domain());
178 mln::
data::
fill(output, mln::literal::white);
182 std::vector<mln::
value::rgb8> basin_color (nbasins + 1);
183 for (
unsigned i = 0; i <= nbasins; ++i)
184 basin_color[i] = mln::
value::rgb8(random() % 256,
187 mln_piter_(ima_t) f(wshed.domain());
189 output(f) = basin_color[wshed(f)];
191 mln::io::off::
save(output, output_filename);