00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH
00027 # define MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH
00028
00032
00033 # include <mln/core/internal/labeled_image_base.hh>
00034
00035 # include <mln/core/routine/duplicate.hh>
00036
00037 # include <mln/util/array.hh>
00038
00039 # include <mln/accu/center.hh>
00040 # include <mln/accu/shape/bbox.hh>
00041 # include <mln/accu/stat/max.hh>
00042
00043 # include <mln/data/compute.hh>
00044
00045 # include <mln/labeling/compute.hh>
00046
00047 namespace mln
00048 {
00049
00050
00051 template <typename I> struct labeled_image;
00052 namespace accu
00053 {
00054 template <typename T> struct nil;
00055 template <typename T> struct bbox;
00056 }
00057
00058
00059 namespace internal
00060 {
00061
00063 template <typename I>
00064 struct data< labeled_image<I> >
00065 : data< labeled_image_base<I, labeled_image<I> > >
00066 {
00067 typedef data< labeled_image_base<I, labeled_image<I> > > super_;
00068
00069 data(const I& ima, const mln_value(I)& nlabels);
00070 data(const I& ima, const mln_value(I)& nlabels,
00071 const util::array<mln_box(I)>& bboxes);
00072 };
00073
00074 }
00075
00076
00077 namespace trait
00078 {
00079
00080 template <typename I>
00081 struct image_< labeled_image<I> >
00082 : image_< labeled_image_base<I, labeled_image<I> > >
00083 {
00084 };
00085
00086 }
00087
00088
00089
00101
00102 template <typename I>
00103 class labeled_image
00104 : public labeled_image_base<I, labeled_image<I> >
00105 {
00106 typedef labeled_image_base<I, labeled_image<I> > super_;
00107
00108 public:
00109
00111 typedef labeled_image< tag::image_<I> > skeleton;
00112
00116 labeled_image();
00117
00119 labeled_image(const I& ima, const mln_value(I)& nlabels);
00120
00123 labeled_image(const I& ima, const mln_value(I)& nlabels,
00124 const util::array<mln_box(I)>& bboxes);
00126
00129 void init_(const I& ima, const mln_value(I)& nlabels);
00130
00132 void init_from_(const labeled_image<I>& model);
00133
00134 };
00135
00136
00137
00138
00139
00140
00141 template <typename I, typename J>
00142 void init_(tag::image_t, labeled_image<I>& target,
00143 const labeled_image<J>& model);
00144
00145
00146
00147 namespace make
00148 {
00149
00150 template <typename I>
00151 mln::labeled_image<I>
00152 labeled_image(const Image<I>& ima, const mln_value(I)& nlabels);
00153
00154 }
00155
00156
00157
00158
00159 # ifndef MLN_INCLUDE_ONLY
00160
00161
00162
00163
00164 namespace internal
00165 {
00166
00167
00168
00169
00170 template <typename I>
00171 inline
00172 data< labeled_image<I> >::data(const I& ima, const mln_value(I)& nlabels)
00173 : super_(ima, nlabels)
00174 {
00175 }
00176
00177 template <typename I>
00178 inline
00179 data< labeled_image<I> >::data(const I& ima, const mln_value(I)& nlabels,
00180 const util::array<mln_box(I)>& bboxes)
00181 : super_(ima, nlabels, bboxes)
00182 {
00183 }
00184
00185
00186 }
00187
00188
00189 template <typename I>
00190 inline
00191 labeled_image<I>::labeled_image()
00192 {
00193 }
00194
00195 template <typename I>
00196 inline
00197 labeled_image<I>::labeled_image(const I& ima, const mln_value(I)& nlabels)
00198 {
00199 init_(ima, nlabels);
00200 }
00201
00202 template <typename I>
00203 inline
00204 labeled_image<I>::labeled_image(const I& ima, const mln_value(I)& nlabels,
00205 const util::array<mln_box(I)>& bboxes)
00206 {
00207 mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels);
00208 this->data_ = new internal::data< labeled_image<I> >(ima, nlabels, bboxes);
00209 }
00210
00211
00212 template <typename I>
00213 inline
00214 void
00215 labeled_image<I>::init_(const I& ima, const mln_value(I)& nlabels)
00216 {
00217 mln_precondition(data::compute(accu::meta::stat::max(), ima) == nlabels);
00218 this->data_ = new internal::data< labeled_image<I> >(ima, nlabels);
00219 this->data_->bboxes_ = labeling::compute(accu::meta::shape::bbox(),
00220 this->data_->ima_,
00221 this->data_->nlabels_);
00222 }
00223
00224 template <typename I>
00225 inline
00226 void
00227 labeled_image<I>::init_from_(const labeled_image<I>& model)
00228 {
00229 this->data_
00230 = new internal::data< labeled_image<I> >(duplicate(model.hook_data_()->ima_),
00231 model.nlabels());
00232 this->data_->bboxes_ = model.hook_data_()->bboxes_;
00233 }
00234
00235
00236
00237 template <typename I, typename J>
00238 void init_(tag::image_t, labeled_image<I>& target,
00239 const labeled_image<J>& model)
00240 {
00241 I ima;
00242 init_(tag::image, ima, model);
00243 target.init_(ima, model.nlabels());
00244 }
00245
00246
00247
00248
00249 namespace make
00250 {
00251
00252 template <typename I>
00253 mln::labeled_image<I>
00254 labeled_image(const Image<I>& ima, const mln_value(I)& nlabels)
00255 {
00256 mln_precondition(exact(ima).is_valid());
00257 mln::labeled_image<I> tmp(exact(ima), nlabels);
00258 return tmp;
00259 }
00260
00261 }
00262
00263
00264 # endif // ! MLN_INCLUDE_ONLY
00265
00266 }
00267
00268
00269 #endif // ! MLN_CORE_IMAGE_IMORPH_LABELED_IMAGE_HH