37 #include <mln/value/int_u8.hh>
38 #include <mln/value/rgb8.hh>
39 #include <mln/literal/black.hh>
40 #include <mln/literal/white.hh>
42 #include <mln/core/concept/function.hh>
43 #include <mln/core/alias/point2d.hh>
44 #include <mln/core/site_set/p_faces.hh>
45 #include <mln/core/image/complex_image.hh>
47 #include <mln/core/image/complex_neighborhoods.hh>
48 #include <mln/core/image/complex_neighborhood_piter.hh>
50 #include <mln/data/fill.hh>
52 #include <mln/norm/l2.hh>
54 #include <mln/morpho/closing/area.hh>
55 #include <mln/morpho/watershed/flooding.hh>
57 #include <mln/convert/to.hh>
59 #include <mln/debug/iota.hh>
69 for (
unsigned i = 1; i <=
max; ++i)
70 lut[i] = result(100 + std::rand() % 150,
71 100 + std::rand() % 150,
72 100 + std::rand() % 150);
74 result operator()(
unsigned i)
const
78 std::vector<result> lut;
111 const unsigned D = 1;
124 vertex v0 = c.add_face(); geom.add_location(
point2d(0,1));
125 vertex v1 = c.add_face(); geom.add_location(
point2d(2,0));
126 vertex v2 = c.add_face(); geom.add_location(
point2d(2,2));
127 vertex v3 = c.add_face(); geom.add_location(
point2d(0,3));
130 edge e0 = c.add_face(-v1 + v0);
131 edge e1 = c.add_face(-v2 + v0);
132 edge e2 = c.add_face(-v2 + v1);
133 edge e3 = c.add_face(-v0 + v3);
134 edge e4 = c.add_face(-v3 + v2);
151 dist_ima_t dist_ima(pc);
163 mln_niter_(v_nbh_t) v(v_nbh, e);
167 point2d p1 = v.to_site().front();
169 point2d p2 = v.to_site().front();
171 mln_invariant(!v.is_valid());
179 dist_ima(v_) = mln_max(mln_value_(dist_ima_t));
186 mln_niter_(nbh_t) ne(nbh, e);
189 std::cout <<
"dist_ima(" << e <<
") = " << dist_ima(e)
190 <<
" -- adjacent edges :" << std::endl;
192 std::cout << " " << ne << std::endl;
200 dist_ima_t closed_dist_ima = morpho::closing::
area(dist_ima, nbh, 1);
207 typedef
unsigned wst_val_t;
210 wst_ima_t wshed = morpho::watershed::
flooding(closed_dist_ima, nbh, nbasins);
237 wst_val_t actual_nbasins = nbasins - c.nfaces_of_static_dim<0>();
238 std::cout << "nbasins = " << actual_nbasins << std::endl;
243 std::ofstream g("complex_image_wst-wst.neato");
244 g << "graph wst" << std::endl
246 << " graph [bgcolor = \
"#000000\"]" << std::endl
247 <<
" edge [color = \"#FFFFFF\"]" << std::endl
248 <<
" node [color = \"#FFFFFF\", fontcolor = \"#FFFFFF\" ]" << std::endl;
253 mln_niter_(e_nbh_t) v_e(e_nbh, v_);
261 basin_color = color(wshed(v_e));
264 std::ostringstream basin_color_str;
265 basin_color_str <<
'#'
268 << std::setw(2) << basin_color.
red()
269 << std::setw(2) << basin_color.
green()
270 << std::setw(2) << basin_color.
blue()
273 g <<
" v" << v_.unproxy_().face_id()
275 << std::fixed << std::setprecision(1)
276 << (
float)v_.to_site().front()[1] <<
", "
277 << -(
float)v_.to_site().front()[0]
278 <<
"\", color = \"" << basin_color_str.str()
279 <<
"\", fillcolor = \"" << basin_color_str.str()
280 <<
"\", pin = \"true\", style=\"filled,setlinewidth(3)\"];"
287 std::ostringstream basin_color_str;
288 basin_color_str <<
'#'
291 << std::setw(2) << basin_color.
red()
292 << std::setw(2) << basin_color.
green()
293 << std::setw(2) << basin_color.
blue()
299 point2d p1 = v.to_site().front();
303 point2d p2 = v.to_site().front();
306 mln_invariant(!v.is_valid());
311 g <<
"[color = \"#FFFFFF\"];" << std::endl;
313 g <<
"[color = \"" << basin_color_str.str()
314 <<
"\", style=\"setlinewidth(3)\"];" << std::endl;
317 g <<
"}" << std::endl;