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