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