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/max.hh>
47 #include <mln/math/sqr.hh>
49 #include <mln/literal/white.hh>
51 #include <mln/io/off/load.hh>
52 #include <mln/io/off/save.hh>
57 int main(
int argc,
char* argv[])
61 std::cerr <<
"usage: " << argv[0] <<
" input.off lambda output.off"
66 std::string input_filename = argv[1];
67 unsigned lambda = atoi(argv[2]);
68 std::string output_filename = argv[3];
77 static const unsigned D = float_ima_t::dim;
79 typedef mln_geom_(float_ima_t) G;
81 mln::bin_2complex_image3df bin_input;
82 mln::io::off::
load(bin_input, input_filename);
83 std::pair<float_ima_t, float_ima_t> curv =
84 mln::geom::mesh_curvature(bin_input.domain());
87 float_ima_t float_ima(bin_input.domain());
88 mln::p_n_faces_fwd_piter<D, G> v(float_ima.domain(), 0);
99 adj_vertices_nbh_t adj_vertices_nbh;
100 mln_niter_(adj_vertices_nbh_t) adj_v(adj_vertices_nbh, e);
109 s += float_ima(adj_v);
112 float_ima(e) = s / n;
114 mln_invariant(n <= 2);
124 ima_t ima(float_ima.domain());
125 mln_piter_(ima_t) p(float_ima.domain());
127 ima(p) = 1000 * float_ima(p);
135 mln::complex_higher_dim_connected_n_face_neighborhood<D, G>
137 adj_edges_nbh_t adj_edges_nbh;
139 ima_t closed_ima = mln::morpho::closing::
area(ima, adj_edges_nbh, lambda);
154 typedef
unsigned wst_val_t;
156 typedef mln::unsigned_2complex_image3df wst_ima_t;
158 mln::morpho::watershed::
flooding(closed_ima, adj_edges_nbh, nbasins);
159 std::cout << "nbasins = " << nbasins << std::endl;
162 typedef mln::complex_higher_neighborhood<D, G> adj_polygons_nbh_t;
163 adj_polygons_nbh_t adj_polygons_nbh;
164 mln_niter_(adj_polygons_nbh_t) adj_p(adj_polygons_nbh, e);
168 wshed(adj_p) = wshed(e);
174 mln::rgb8_2complex_image3df output(wshed.domain());
175 mln::
data::
fill(output, mln::literal::white);
179 std::vector<mln::
value::rgb8> basin_color (nbasins + 1);
180 for (
unsigned i = 0; i <= nbasins; ++i)
181 basin_color[i] = mln::
value::rgb8(random() % 256,
184 mln_piter_(ima_t) f(wshed.domain());
186 output(f) = basin_color[wshed(f)];
188 mln::io::off::
save(output, output_filename);