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;
85 psite find_root(const psite& x);
87 void do_union(const psite& n, const psite& p);
93 labeling<F>::labeling(F& f)
96 trace::entering(
"canvas::labeling");
103 trace::exiting(
"canvas::labeling");
106 template <
typename F>
118 template <
typename F>
120 labeling<F>::pass_1()
122 mln_fwd_piter(S) p(f.s);
123 mln_niter(N) n(f.nbh, p);
124 for_all(p) if (f.handles(p))
128 if (f.input.domain().has(n) && deja_vu(n))
139 template <
typename F>
141 labeling<F>::pass_2()
143 mln_bkd_piter(S) p(f.s);
144 for_all(p) if (f.handles(p))
150 if (nlabels == mln_max(L))
155 output(p) = ++nlabels;
159 output(p) = output(parent(p));
164 template <
typename F>
166 labeling<F>::make_set(
const psite& p)
172 template <
typename F>
174 labeling<F>::is_root(
const psite& p)
const
176 return parent(p) == p;
179 template <
typename F>
180 typename labeling<F>::psite
181 labeling<F>::find_root(
const psite& x)
186 return parent(x) = find_root(parent(x));
189 template <
typename F>
191 labeling<F>::do_union(
const psite& n,
const psite& p)
193 psite r = find_root(n);
206 namespace old_labeling
210 template <
typename I_,
typename N_,
typename L_>
213 typedef mln_psite(I_) P;
220 typedef mln_pset(I) S;
226 bool handles(const P& p)
const {
return input(p) == val; }
227 bool equiv(
const P& n,
const P&)
const {
return input(n) == val; }
230 bool labels(
const P&)
const {
return true; }
231 void do_no_union(
const P&,
const P&) {}
232 void init_attr(
const P&) {}
233 void merge_attr(
const P&,
const P&) {}
237 const mln_value(I_)& val;
239 level_functor(
const I& input,
const mln_value(I)& val,
const N& nbh)
249 template <
typename I,
typename N,
typename L>
251 level(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
254 trace::entering(
"labeling::value");
256 typedef level_functor<I,N,L> F;
257 F f(exact(input), val, exact(nbh));
258 old_canvas::labeling<F> run(f);
260 nlabels = run.nlabels;
262 trace::exiting(
"labeling::value");
285 for (
unsigned l = 0; l <= 255; ++l)
286 old_labeling::value(lena, l,
c4(), n);
287 std::cout <<
"canvas as class: " << t.read() << std::endl;
294 for (
unsigned l = 0; l <= 255; ++l)
295 labeling::impl::generic::data(lena, l,
c4(), n);
296 std::cout <<
"canvas as proc.: " << t.read() << std::endl;