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_LABELING_MEAN_VALUES_HH
00027 # define MLN_LABELING_MEAN_VALUES_HH
00028
00036
00037
00038 # include <mln/core/concept/image.hh>
00039 # include <mln/core/alias/vec3d.hh>
00040
00041 # include <mln/accu/stat/mean.hh>
00042
00043 # include <mln/data/transform.hh>
00044
00045 # include <mln/labeling/compute.hh>
00046
00047 # include <mln/literal/colors.hh>
00048
00049
00050 namespace mln
00051 {
00052
00053
00054 namespace value
00055 {
00056 template <unsigned n> struct rgb;
00057 }
00058
00059
00060 namespace labeling
00061 {
00062
00063 template <typename I, typename L>
00064 mln_concrete(I)
00065 mean_colors(const Image<I>& input,
00066 const Image<L>& lbl, mln_value(L) nlabels);
00067
00068
00069 # ifndef MLN_INCLUDE_ONLY
00070
00071 namespace internal
00072 {
00073
00074 template <typename I, typename L>
00075 void
00076 mean_values_tests(const Image<I>& input,
00077 const Image<L>& lbl, mln_value(L) nlabels)
00078 {
00079 mln_precondition(exact(input).is_valid());
00080 mln_precondition(exact(lbl).is_valid());
00081 (void) input;
00082 (void) lbl;
00083 (void) nlabels;
00084 }
00085
00086 }
00087
00088
00089 namespace impl
00090 {
00091
00092 namespace generic
00093 {
00094
00095 template <typename I, typename L>
00096 mln_concrete(I)
00097 mean_values(const Image<I>& input_,
00098 const Image<L>& lbl_, mln_value(L) nlabels)
00099 {
00100 trace::entering("mln::labeling::impl::generic::mean_values");
00101
00102 internal::mean_values_tests(input_, lbl_, nlabels);
00103
00104 const I& input = exact(input_);
00105 const L& lbl = exact(lbl_);
00106 typedef mln_value(L) LV;
00107 typedef mln_value(I) IV;
00108
00109 util::array<float> m_3f
00110 = labeling::compute(accu::stat::mean<IV>(),
00111 input,
00112 lbl,
00113 nlabels);
00114 m_3f[0] = 0.f;
00115
00116 util::array<IV> m;
00117 convert::from_to(m_3f, m);
00118 m[0] = 150u;
00119
00120 mln_concrete(I) output = data::transform(lbl, m);
00121
00122 trace::exiting("mln::labeling::impl::generic::mean_values");
00123 return output;
00124 }
00125
00126 }
00127
00128 template <typename I, typename L>
00129 mln_concrete(I)
00130 mean_values_rgb(const Image<I>& input_,
00131 const Image<L>& lbl_, mln_value(L) nlabels)
00132 {
00133 trace::entering("mln::labeling::impl::mean_values_rgb");
00134
00135 internal::mean_values_tests(input_, lbl_, nlabels);
00136
00137 const I& input = exact(input_);
00138 const L& lbl = exact(lbl_);
00139
00140 util::array<vec3d_f> m_3f = labeling::compute(accu::stat::mean<mln_value(I)>(),
00141 input,
00142 lbl,
00143 nlabels);
00144 m_3f[0] = literal::zero;
00145
00146 util::array<mln_value(I)> m;
00147 convert::from_to(m_3f, m);
00148 m[0] = literal::yellow;
00149
00150 mln_concrete(I) output = data::transform(lbl,
00151 convert::to< fun::i2v::array<mln_value(I)> >(m));
00152
00153
00154 trace::exiting("mln::labeling::impl::mean_values_rgb");
00155 return output;
00156 }
00157
00158 }
00159
00160
00161 namespace internal
00162 {
00163
00164 template <unsigned n, typename I, typename L>
00165 mln_concrete(I)
00166 mean_values_dispatch(const value::rgb<n>&,
00167 const Image<I>& input,
00168 const Image<L>& lbl, mln_value(L) nlabels)
00169 {
00170 return impl::mean_values_rgb(input, lbl, nlabels);
00171 }
00172
00173 template <typename I, typename L>
00174 mln_concrete(I)
00175 mean_values_dispatch(const mln_value(I)&,
00176 const Image<I>& input,
00177 const Image<L>& lbl, mln_value(L) nlabels)
00178 {
00179 return impl::generic::mean_values(input, lbl, nlabels);
00180 }
00181
00182 template <typename I, typename L>
00183 mln_concrete(I)
00184 mean_values_dispatch(const Image<I>& input,
00185 const Image<L>& lbl, mln_value(L) nlabels)
00186 {
00187 return mean_values_dispatch(mln_value(I)(), input, lbl, nlabels);
00188 }
00189
00190 }
00191
00192
00193
00194
00195
00196 template <typename I, typename L>
00197 mln_concrete(I)
00198 mean_values(const Image<I>& input,
00199 const Image<L>& lbl, mln_value(L) nlabels)
00200
00201 {
00202 trace::entering("mln::labeling::mean_values");
00203
00204 internal::mean_values_tests(input, lbl, nlabels);
00205
00206 mln_concrete(I) output = internal::mean_values_dispatch(input, lbl, nlabels);
00207
00208 trace::exiting("mln::labeling::mean_values");
00209 return output;
00210 }
00211
00212
00213 # endif // !MLN_INCLUDE_ONLY
00214
00215 }
00216
00217 }
00218
00219 #endif // ! MLN_LABELING_MEAN_VALUES_HH