27 #ifndef MLN_CANVAS_LABELING_VIDEO_HH
28 # define MLN_CANVAS_LABELING_VIDEO_HH
37 # include <mln/core/concept/image.hh>
38 # include <mln/data/fill.hh>
39 # include <mln/literal/zero.hh>
40 # include <mln/extension/adjust_fill.hh>
42 # include <mln/canvas/labeling/internal/tests.hh>
43 # include <mln/canvas/labeling/internal/find_root_fastest.hh>
44 # include <mln/canvas/labeling/generic.hh>
60 template <
typename I,
typename N,
typename L,
typename F>
62 video(const Image<I>& input, const Neighborhood<N>& nbh,
63 L& nlabels, F& functor);
66 # ifndef MLN_INCLUDE_ONLY
74 template <
typename I,
typename N,
typename L,
typename F>
76 video_fastest(const Image<I>& input_,
77 const Neighborhood<N>& nbh_,
80 mln_trace(
"canvas::impl::video_fastest");
84 const I& input =
exact(input_);
85 const N& nbh =
exact(nbh_);
90 mln_ch_value(I,
bool) deja_vu;
91 mln_ch_value(I,
unsigned) parent;
94 mln_ch_value(I, L) output;
113 util::array<int>
dp = positive_offsets_wrt(input, nbh);
114 const unsigned n_nbhs = dp.nelements();
116 mln_bkd_pixter(
const I) px(input);
119 unsigned p = px.offset();
124 parent.element(p) =
p;
126 for (
unsigned i = 0; i < n_nbhs; ++i)
128 unsigned n = p + dp[i];
129 if (deja_vu.element(n))
137 parent.element(r) =
p;
142 f.do_no_union_(n, p);
150 mln_fwd_pixter(
const I) px(input);
153 unsigned p = px.offset();
156 if (parent.element(p) ==
p)
160 if (nlabels == mln_max(L))
162 mln_trace_warning(
"labeling aborted! Too many labels for \
163 this label type: nlabels > \
167 output.element(p) = ++nlabels;
168 f.set_new_label_(p, nlabels);
173 L lbl = output.element(parent.element(p));
174 output.element(p) = lbl;
175 f.set_label_(p, lbl);
193 template <
typename I,
typename N,
typename L,
typename F>
196 video_dispatch(metal::false_,
197 const Image<I>& input,
198 const Neighborhood<N>& nbh, L& nlabels,
205 template <
typename I,
typename N,
typename L,
typename F>
208 video_dispatch(metal::true_,
209 const Image<I>& input,
210 const Neighborhood<N>& nbh, L& nlabels,
213 return impl::video_fastest(input, nbh, nlabels, functor);
216 template <
typename I,
typename N,
typename L,
typename F>
219 video_dispatch(const Image<I>& input,
220 const Neighborhood<N>& nbh, L& nlabels,
224 test = mlc_equal(mln_trait_image_speed(I),
225 trait::image::speed::fastest)::
value
227 mln_is_simple_neighborhood(N)::
value
229 return video_dispatch(metal::bool_<test>(),
242 template <
typename I,
typename N,
typename L,
typename F>
245 video(const Image<I>& input, const Neighborhood<N>& nbh,
246 L& nlabels, F& functor)
248 mln_trace(
"canvas::video");
252 mln_ch_value(I, L) output;
253 output = internal::video_dispatch(input, nbh, nlabels,
259 # endif // ! MLN_INCLUDE_ONLY
268 #endif // ! MLN_CANVAS_LABELING_VIDEO_HH