27 #ifndef MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_BASE_HH
28 # define MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_BASE_HH
34 # include <mln/core/image/dmorph/image_if.hh>
35 # include <mln/core/concept/function.hh>
36 # include <mln/core/internal/image_identity.hh>
37 # include <mln/core/site_set/box.hh>
39 # include <mln/accu/shape/bbox.hh>
41 # include <mln/labeling/relabel.hh>
43 # include <mln/util/array.hh>
44 # include <mln/value/next.hh>
46 # include <mln/pw/cst.hh>
47 # include <mln/pw/value.hh>
49 # include <mln/make/relabelfun.hh>
56 template <
typename I,
typename E>
57 class labeled_image_base;
66 template <
typename I,
typename E>
67 struct data< labeled_image_base<I,E> >
69 data(
const I& ima,
const mln_value(I)& nlabels);
70 data(
const I& ima,
const mln_value(I)& nlabels,
71 const util::array<mln_box(I)>& bboxes);
74 mln_value(I) nlabels_;
75 mutable util::array<
box<mln_psite(I)> > bboxes_;
85 template <
typename I,
typename E>
86 struct image_< labeled_image_base<I,E> > : image_< I >
89 typedef trait::image::category::identity_morpher category;
90 typedef mln_internal_trait_image_speed_from(I) speed;
91 typedef trait::image::value_access::indirect value_access;
93 typedef trait::image::value_io::read_only value_io;
94 typedef trait::image::pw_io::read pw_io;
97 typedef trait::image::ext_value::multiple ext_value;
98 typedef trait::image::ext_io::read_only ext_io;
117 template <typename I, typename E>
119 : public internal::image_identity< const I, mln_domain(I), E >
144 template <typename F>
149 template <typename F>
155 mln_value(I) nlabels() const;
161 const util::array<
bbox_t>& bboxes() const;
165 fun::eq_v2b_expr_<pw::value_<I>, pw::cst_<mln_value(I)> > >
166 subdomain(const mln_value(I)&
label) const;
170 void update_data(const fun::i2v::array<mln_value(I)>& relabel_fun);
172 template <typename F>
175 template <typename F>
181 void init_update_data_();
182 void prepare_update_data_(const mln_value(I)& lbl,
183 const mln_value(I)& new_lbl);
184 void update_data_(const fun::i2v::array<mln_value(I)>& relabel_fun);
192 # ifndef MLN_INCLUDE_ONLY
203 template <
typename I,
typename E>
206 : ima_(ima), nlabels_(nlabels)
210 template <
typename I,
typename E>
214 : ima_(ima), nlabels_(nlabels), bboxes_(bboxes)
222 template <
typename I,
typename E>
229 template <
typename I,
typename E>
230 template <
typename F>
235 const F& f =
exact(f_);
236 mln_value(I) new_nlabels;
238 fun::i2v::array<mln_value(I)>
239 packed_relabel_fun = make::relabelfun(f,
240 this->data_->nlabels_,
246 this->data_->nlabels_ = new_nlabels;
248 exact(this)->relabel_(f);
251 update_data(packed_relabel_fun);
255 template <typename I, typename E>
256 template <typename F>
259 labeled_image_base<I,E>::
relabel(const Function_v2b<F>& f_)
261 const F& f =
exact(f_);
264 typedef fun::i2v::array<mln_value(I)> fv2v_t;
266 this->data_->nlabels_,
267 this->data_->nlabels_);
271 exact(
this)->relabel_(f);
277 template <
typename I,
typename E>
280 labeled_image_base<I,E>::nlabels()
const
282 return this->data_->nlabels_;
286 template <
typename I,
typename E>
288 labeled_image_base<I,E>::update_data(
const fun::i2v::array<mln_value(I)>& relabel_fun)
290 util::array<accu::shape::bbox<mln_psite(I)> >
293 exact(
this)->init_update_data_();
295 for (
unsigned i = 1; i < this->data_->bboxes_.size(); ++i)
296 if (relabel_fun(i) != 0)
298 new_bboxes[relabel_fun(i)].take(this->data_->bboxes_[i]);
299 exact(
this)->prepare_update_data_(i, relabel_fun(i));
304 mln_assertion(new_bboxes.size() == this->data_->bboxes_.size());
306 exact(
this)->update_data_(relabel_fun);
310 template <
typename I,
typename E>
311 const typename labeled_image_base<I,E>::bbox_t&
314 return this->data_->bboxes_[label];
318 template <
typename I,
typename E>
319 const util::array<typename labeled_image_base<I,E>::bbox_t>&
320 labeled_image_base<I,E>::bboxes()
const
322 return this->data_->bboxes_;
326 template <
typename I,
typename E>
328 fun::eq_v2b_expr_<pw::value_<I>, pw::cst_<mln_value(I)> > >
329 labeled_image_base<I,E>::subdomain(
const mln_value(I)& label)
const
331 return ((this->data_->ima_ |
bbox(label))
337 template <
typename I,
typename E>
338 template <
typename F>
340 labeled_image_base<I,E>::relabel_(
const Function_v2v<F>& f)
346 template <
typename I,
typename E>
347 template <
typename F>
349 labeled_image_base<I,E>::relabel_(
const Function_v2b<F>& f)
355 template <
typename I,
typename E>
357 labeled_image_base<I,E>::update_data_(
358 const fun::i2v::array<mln_value(I)>& relabel_fun)
364 template <
typename I,
typename E>
366 labeled_image_base<I,E>::prepare_update_data_(
const mln_value(I)& lbl,
367 const mln_value(I)& new_lbl)
374 template <
typename I,
typename E>
376 labeled_image_base<I,E>::init_update_data_()
382 # endif // ! MLN_INCLUDE_ONLY
387 #endif // ! MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_BASE_HH