51 #include <mln/util/ord.hh>
53 #include <mln/core/image/image2d.hh>
54 #include <mln/core/alias/point2d.hh>
55 #include <mln/core/alias/window2d.hh>
56 #include <mln/core/alias/neighb2d.hh>
58 #include <mln/convert/to_window.hh>
61 #include <mln/core/image/edge_image.hh>
62 #include <mln/core/var.hh>
63 #include <mln/fun/i2v/array.hh>
64 #include <mln/util/graph.hh>
66 #include <mln/morpho/gradient.hh>
67 #include <mln/morpho/closing/area.hh>
68 #include <mln/morpho/meyer_wst.hh>
70 #include <mln/value/int_u8.hh>
71 #include <mln/value/rgb8.hh>
72 #include <mln/literal/black.hh>
73 #include <mln/literal/colors.hh>
75 #include <mln/io/pgm/load.hh>
76 #include <mln/io/ppm/save.hh>
78 #include <mln/math/max.hh>
79 #include <mln/math/abs.hh>
81 #include <mln/util/site_pair.hh>
83 #include "tests/data.hh"
97 typedef int_u8 input_val_t;
108 work = morpho::closing::area(gradient,
c4(), 10);
125 equiv_vertex(p) = g.add_vertex();
129 next_c4_win.insert(0, 1).insert(1, 0);
130 typedef fun::i2v::
array<
int> edge_values_t;
131 typedef fun::i2v::
array< util::site_pair<
point2d> > edge_sites_t;
132 edge_values_t edge_values;
133 edge_sites_t edge_sites;
134 mln_fwd_qiter_(
window2d) q(next_c4_win, p);
137 if (work.domain().has(q))
139 g.add_edge(equiv_vertex(p), equiv_vertex(q));
140 edge_values.append(math::max(work(p), work(q)));
146 lg_ima_t lg_ima(g, edge_sites, edge_values);
152 typedef lg_ima_t::nbh_t nbh_t;
159 mln_assertion(nbasins == 5u);
170 typedef rgb8 output_val_t;
172 point2d output_pmin = input.domain().pmin();
173 point2d output_pmax(input.domain().pmax()[0] * 2,
174 input.domain().pmax()[1] * 2);
175 output_t output(
box2d(output_pmin, output_pmax));
182 input_val_t v = input(p);
185 output(q) = output_val_t(v, v, v);
188 mln_piter_(output_t) p_out(output.domain());
192 if (p_out[0] % 2 == 0 && p_out[1] % 2 == 1)
193 output(p_out) = (output(p_out + left) + output(p_out + right)) / 2;
195 if (p_out[0] % 2 == 1 && p_out[1] % 2 == 0)
196 output(p_out) = (output(p_out +
up) + output(p_out + down)) / 2;
198 if (p_out[0] % 2 == 1 && p_out[1] % 2 == 1)
203 output(p_out +
dpoint2d(+1, +1))) / 4;
209 mln_piter_(wshed_t) pw(wshed.domain());
214 mln_psite_(lg_ima_t) pp(pw);
216 int row1 = pp.first()[0] * 2;
217 int col1 = pp.first()[1] * 2;
218 int row2 = pp.second()[0] * 2;
219 int col2 = pp.second()[1] * 2;
220 point2d q((row1 + row2) / 2, (col1 + col2) / 2);
222 output(q) = literal::red;
236 if (p_out[0] % 2 == 1 && p_out[1] % 2 == 1)
244 (output.has(p_out + down ) && output(p_out + down ) ==
literal::red) +
245 (output.has(p_out + left ) && output(p_out + right) ==
literal::red) +
246 (output.has(p_out + right) && output(p_out + left ) ==
literal::red);