27 #ifndef MLN_CANVAS_LABELING_BLOBS_HH
28 # define MLN_CANVAS_LABELING_BLOBS_HH
35 # include <mln/core/concept/image.hh>
36 # include <mln/core/concept/neighborhood.hh>
37 # include <mln/data/fill.hh>
38 # include <mln/core/site_set/p_queue_fast.hh>
40 # include <mln/extension/fill.hh>
42 # include <mln/util/pix.hh>
71 template <
typename I,
typename N,
typename L,
typename F>
73 blobs(const Image<I>& input, const Neighborhood<N>& nbh,
74 L& nlabels, F& functor);
78 # ifndef MLN_INCLUDE_ONLY
91 template <
typename I,
typename N,
typename L,
typename F>
93 blobs(const Image<I>& input_, const N& nbh, L& nlabels, F& functor)
95 const I& input =
exact(input_);
97 typedef mln_psite(I) P;
100 mln_niter(N) n(nbh, cur);
102 const L zero = literal::zero;
105 nlabels = literal::zero;
106 typedef mln_ch_value(I, L) out_t;
111 extension::
fill(input, false);
116 mln_piter(I)
p(input.domain());
118 if (input(
p) && output(
p) == zero)
121 if (nlabels == mln_max(L))
123 mln_trace_warning(
"labeling aborted! Too many labels \
124 for this label type: nlabels > max(label_type).");
129 functor.new_label(nlabels);
130 mln_invariant(qu.is_empty());
133 functor.process_p(
p);
139 for_all(n) if (input.has(n))
140 if (input(n) && output(n) == zero)
142 mln_invariant(! qu.compute_has(n));
145 functor.process_n(n);
149 while (! qu.is_empty());
166 template <
typename I,
typename N,
typename L,
typename F>
169 blobs(const Image<I>& input_, const Neighborhood<N>& nbh_,
170 L& nlabels, F& functor)
172 mln_trace(
"labeling::blobs");
173 mlc_equal(mln_trait_image_kind(I),
174 mln::trait::image::kind::binary)::check();
175 const I& input =
exact(input_);
176 const N& nbh =
exact(nbh_);
177 mln_precondition(input.is_valid());
181 output = impl::generic::
blobs(input, nbh, nlabels, functor);
187 # endif // ! MLN_INCLUDE_ONLY
196 #endif // ! MLN_CANVAS_LABELING_BLOBS_HH