29 #include <mln/core/image/image2d.hh>
30 #include <mln/core/alias/window2d.hh>
32 #include <mln/io/pgm/load.hh>
33 #include <mln/io/pgm/save.hh>
35 #include <mln/value/int_u8.hh>
37 #include <mln/morpho/includes.hh>
38 #include <mln/morpho/general.hh>
40 #include <mln/accu/logic/lor.hh>
41 #include <mln/accu/logic/land.hh>
42 #include <mln/accu/logic/land_basic.hh>
43 #include <mln/accu/logic/lor_basic.hh>
44 #include <mln/accu/stat/max.hh>
45 #include <mln/accu/stat/min.hh>
46 #include <mln/accu/stat/max_h.hh>
47 #include <mln/accu/stat/min_h.hh>
49 #include "apps/bench/minus.hh"
50 #include "apps/bench/and_not.hh"
52 #include <mln/util/timer.hh>
54 #include "apps/data.hh"
59 gradient_spe_0(const mln::Image<I>& ima_)
62 typedef mln_value(I) V;
63 typedef mln_psite(I) P;
65 const I& ima =
exact(ima_);
67 mln_concrete(I) result;
70 mln_piter(I)
p(result.domain());
77 P q(p.row() - 1, p.col());
80 if (ima(q) > sup) sup = ima(q);
81 if (ima(q) < inf) inf = ima(q);
85 P q(p.row(), p.col() - 1);
88 if (ima(q) > sup) sup = ima(q);
89 if (ima(q) < inf) inf = ima(q);
93 P q(p.row(), p.col() + 1);
96 if (ima(q) > sup) sup = ima(q);
97 if (ima(q) < inf) inf = ima(q);
101 P q(p.row() + 1, p.col());
104 if (ima(q) > sup) sup = ima(q);
105 if (ima(q) < inf) inf = ima(q);
108 result(p) = sup - inf;
113 template <
typename I,
typename W>
115 gradient_spe_1(const mln::
Image<I>& ima_, const mln::
Window<W>& win_)
118 typedef mln_value(I) V;
120 const I& ima =
exact(ima_);
121 const W& win =
exact(win_);
123 mln_concrete(I) result;
126 mln_piter(I) p(result.domain());
127 mln_qiter(W) q(win, p);
141 result(p) = sup - inf;
146 template <
typename I,
typename W>
148 gradient_spe_2(const mln::
Image<I>& ima_, const mln::
Window<W>& win_)
151 typedef mln_value(I) V;
153 const I& ima =
exact(ima_);
154 const W& win =
exact(win_);
156 typedef mln_concrete(I) O;
160 mln_pixter(const I)
pi(ima);
161 mln_pixter(O) po(result);
164 mln_qixter(const I, W) q(
pi, win);
177 po.val() = sup - inf;
182 template <
typename I,
typename W>
184 gradient_spe_3(const mln::
Image<I>& ima_, const mln::
Window<W>& win_)
187 typedef mln_value(I) V;
189 const I& ima =
exact(ima_);
190 const W& win =
exact(win_);
192 typedef mln_concrete(I) O;
196 mln_pixter(const I) pi(ima);
197 mln_pixter(O) po(result);
200 mln_qixter(const I, W) q(pi, win);
206 bool global_sup_reached_p =
false;
207 bool global_inf_reached_p =
false;
210 if (!global_sup_reached_p && q.val() > sup)
213 if (sup == mln_max(V))
216 if (global_inf_reached_p)
218 global_sup_reached_p =
true;
221 if (!global_inf_reached_p && q.val() < inf)
224 if (inf == mln_min(V))
227 if (global_sup_reached_p)
229 global_inf_reached_p =
true;
233 po.val() = sup - inf;
266 template <
typename I>
267 mln_morpho_select_accu(I, lor_basic_minus_land_basic, max_minus_min)
270 mln_morpho_select_accu(I, lor_basic_minus_land_basic, max_minus_min) tmp;
274 template <
typename I>
275 mln_morpho_select_accu(I, lor_minus_land, max_h_minus_min_h)
278 mln_morpho_select_accu(I, lor_minus_land, max_h_minus_min_h) tmp;
283 template <
typename I>
284 mln_value(I) neutral(
const Image<I>&)
const
286 return internal::neutral<I>::infimum();
290 template <
typename I,
typename W>
295 mln_trace(
"morpho::dilation");
296 mln_precondition(
exact(input).is_valid());
297 mln_precondition(!
exact(win).is_empty());
299 mln_concrete(I) output =
general(gradient_op(), input, win);
324 g = gradient_spe_0(lena);
326 std::cout << t.read() << std::endl;
330 g = gradient_spe_1(lena,
win_c4p());
332 std::cout << t.read() << std::endl;
336 g = gradient_spe_2(lena,
win_c4p());
338 std::cout << t.read() << std::endl;
342 g = gradient_spe_3(lena,
win_c4p());
344 std::cout << t.read() << std::endl;
350 std::cout << t.read() << std::endl;