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