30 #include <mln/core/image/image2d.hh>
31 #include <mln/core/alias/neighb2d.hh>
32 #include <mln/value/int_u8.hh>
33 #include <mln/io/pgm/load.hh>
35 #include <mln/labeling/level.hh>
36 #include <mln/util/timer.hh>
52 typedef typename F::I I;
53 typedef typename F::N N;
54 typedef typename F::L L;
55 typedef typename F::S S;
58 typedef mln_psite(I)
psite;
61 mln_ch_value(I,
bool) deja_vu;
62 mln_ch_value(I,
psite) parent;
65 mln_ch_value(I, L) output;
81 void make_set(
const psite&
p);
83 bool is_root(
const psite& p)
const;
96 mln_trace(
"canvas::labeling");
105 template <
typename F>
117 template <
typename F>
119 labeling<F>::pass_1()
121 mln_fwd_piter(S)
p(f.s);
122 mln_niter(N) n(f.nbh,
p);
123 for_all(
p)
if (f.handles(
p))
127 if (f.input.domain().has(n) && deja_vu(n))
138 template <
typename F>
140 labeling<F>::pass_2()
142 mln_bkd_piter(S)
p(f.s);
143 for_all(
p)
if (f.handles(
p))
149 if (nlabels == mln_max(L))
154 output(
p) = ++nlabels;
158 output(
p) = output(parent(
p));
163 template <
typename F>
165 labeling<F>::make_set(
const psite&
p)
171 template <
typename F>
173 labeling<F>::is_root(
const psite& p)
const
175 return parent(p) ==
p;
178 template <
typename F>
179 typename labeling<F>::psite
180 labeling<F>::find_root(
const psite& x)
185 return parent(x) = find_root(parent(x));
188 template <
typename F>
190 labeling<F>::do_union(
const psite& n,
const psite& p)
192 psite r = find_root(n);
205 namespace old_labeling
209 template <
typename I_,
typename N_,
typename L_>
212 typedef mln_psite(I_) P;
219 typedef mln_pset(I) S;
225 bool handles(
const P&
p)
const {
return input(p) == val; }
226 bool equiv(
const P& n,
const P&)
const {
return input(n) == val; }
229 bool labels(
const P&)
const {
return true; }
230 void do_no_union(
const P&,
const P&) {}
231 void init_attr(
const P&) {}
232 void merge_attr(
const P&,
const P&) {}
236 const mln_value(I_)& val;
238 level_functor(
const I& input,
const mln_value(I)& val,
const N& nbh)
248 template <
typename I,
typename N,
typename L>
253 mln_trace(
"labeling::value");
255 typedef level_functor<I,N,L> F;
257 old_canvas::labeling<F> run(f);
259 nlabels = run.nlabels;
283 for (
unsigned l = 0; l <= 255; ++l)
285 std::cout <<
"canvas as class: " << t.
read() << std::endl;
292 for (
unsigned l = 0; l <= 255; ++l)
293 labeling::impl::generic::data(lena, l,
c4(), n);
294 std::cout <<
"canvas as proc.: " << t.
read() << std::endl;