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_LABELING_RELABEL_HH
00028 # define MLN_LABELING_RELABEL_HH
00029
00033
00034
00035 # include <mln/core/concept/image.hh>
00036
00037 # include <mln/make/relabelfun.hh>
00038
00039 # include <mln/data/transform.hh>
00040 # include <mln/data/transform_inplace.hh>
00041
00042
00043
00044 namespace mln
00045 {
00046
00047 namespace labeling
00048 {
00049
00058
00059 template <typename I, typename F>
00060 mln_concrete(I)
00061 relabel(const Image<I>& label,
00062 const mln_value(I)& nlabels,
00063 mln_value(I)& new_nlabels,
00064 const Function_v2b<F>& fv2b);
00065
00066
00074
00075 template <typename I, typename F>
00076 mln_concrete(I)
00077 relabel(const Image<I>& label,
00078 const mln_value(I)& nlabels,
00079 const Function_v2v<F>& fv2v);
00080
00081
00087
00088 template <typename I, typename F>
00089 void
00090 relabel_inplace(Image<I>& label,
00091 const mln_value(I)& nlabels,
00092 const Function_v2b<F>& fv2b);
00093
00094
00100
00101 template <typename I, typename F>
00102 void
00103 relabel_inplace(Image<I>& label,
00104 const mln_value(I)& nlabels,
00105 const Function_v2v<F>& fv2v);
00106
00107
00108 # ifndef MLN_INCLUDE_ONLY
00109
00110
00111
00112 namespace internal
00113 {
00114
00115 template <typename I>
00116 void
00117 relabel_tests(const Image<I>& label,
00118 mln_value(I)& new_nlabels)
00119 {
00120
00121
00122 mln_precondition(exact(label).is_valid());
00123 (void) label;
00124 (void) new_nlabels;
00125 }
00126
00127 template <typename I, typename F>
00128 void
00129 relabel_tests(const Image<I>& label,
00130 const mln_value(I)& nlabels,
00131 mln_value(I)& new_nlabels,
00132 const Function<F>& f)
00133 {
00134
00135
00136 mln_precondition(exact(label).is_valid());
00137 (void) label;
00138 (void) nlabels;
00139 (void) new_nlabels;
00140 (void) f;
00141 }
00142
00143 template <typename I, typename F>
00144 void
00145 relabel_tests(const Image<I>& label,
00146 const mln_value(I)& nlabels,
00147 const Function<F>& f)
00148 {
00149
00150
00151 mln_precondition(exact(label).is_valid());
00152 (void) label;
00153 (void) nlabels;
00154 (void) f;
00155 }
00156
00157 template <typename I, typename F>
00158 inline
00159 void
00160 relabel_inplace_tests(Image<I>& label,
00161 const mln_value(I)& nlabels,
00162 const Function<F>& f)
00163 {
00164
00165
00166 mln_precondition(exact(label).is_valid());
00167 (void) label;
00168 (void) nlabels;
00169 (void) f;
00170 }
00171
00172 }
00173
00174
00175
00176 template <typename I, typename F>
00177 inline
00178 mln_concrete(I)
00179 relabel(const Image<I>& label,
00180 const mln_value(I)& nlabels,
00181 const Function_v2v<F>& fv2v)
00182 {
00183 trace::entering("labeling::relabel");
00184
00185
00186 mlc_not_equal(mln_result(F),bool)::check();
00187 internal::relabel_tests(label, nlabels, fv2v);
00188
00189 mln_concrete(I) output = data::transform(label, fv2v);
00190
00191 trace::exiting("labeling::relabel");
00192 return output;
00193 }
00194
00195
00196
00197 template <typename I, typename F>
00198 inline
00199 mln_concrete(I)
00200 relabel(const Image<I>& label,
00201 const mln_value(I)& nlabels,
00202 mln_value(I)& new_nlabels,
00203 const Function_v2b<F>& fv2b)
00204 {
00205 trace::entering("labeling::relabel");
00206
00207 internal::relabel_tests(label, nlabels, new_nlabels, fv2b);
00208
00209 typedef fun::i2v::array<mln_value(I)> fv2v_t;
00210 fv2v_t fv2v = make::relabelfun(fv2b, nlabels, new_nlabels);
00211 mln_concrete(I) output = labeling::relabel(label, new_nlabels, fv2v);
00212
00213 trace::exiting("labeling::relabel");
00214 return output;
00215 }
00216
00217
00218 template <typename I, typename F>
00219 inline
00220 void
00221 relabel_inplace(Image<I>& label,
00222 const mln_value(I)& nlabels,
00223 const Function_v2v<F>& fv2v)
00224 {
00225 trace::entering("labeling::relabel_inplace");
00226
00227 mlc_not_equal(mln_result(F),bool)::check();
00228 internal::relabel_inplace_tests(label, nlabels, fv2v);
00229
00230 data::transform_inplace(label, fv2v);
00231
00232 trace::exiting("labeling::relabel_inplace");
00233 }
00234
00235
00236
00237 template <typename I, typename F>
00238 inline
00239 void
00240 relabel_inplace(Image<I>& label,
00241 const mln_value(I)& nlabels,
00242 const Function_v2b<F>& fv2b)
00243 {
00244 trace::entering("labeling::relabel_inplace");
00245
00246 internal::relabel_inplace_tests(label, nlabels, fv2b);
00247
00248 typedef fun::i2v::array<mln_value(I)> fv2v_t;
00249 mln_value(I) tmp;
00250 fv2v_t fv2v = make::relabelfun(fv2b, nlabels, tmp);
00251 labeling::relabel_inplace(label, tmp, fv2v);
00252
00253 trace::exiting("labeling::relabel_inplace");
00254 }
00255
00256 # endif // ! MLN_INCLUDE_ONLY
00257
00258 }
00259
00260 }
00261
00262
00263 #endif // ! MLN_LABELING_RELABEL_HH