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