26 #ifndef MLN_LABELING_MEAN_VALUES_HH
27 # define MLN_LABELING_MEAN_VALUES_HH
38 # include <mln/core/concept/image.hh>
39 # include <mln/core/alias/vec3d.hh>
41 # include <mln/accu/stat/mean.hh>
43 # include <mln/data/transform.hh>
45 # include <mln/labeling/compute.hh>
47 # include <mln/literal/colors.hh>
56 template <
unsigned n>
struct rgb;
63 template <
typename I,
typename L>
65 mean_colors(const Image<I>& input,
66 const Image<L>& lbl, mln_value(L) nlabels);
69 # ifndef MLN_INCLUDE_ONLY
74 template <
typename I,
typename L>
76 mean_values_tests(
const Image<I>& input,
77 const Image<L>& lbl, mln_value(L) nlabels)
79 mln_precondition(exact(input).is_valid());
80 mln_precondition(exact(lbl).is_valid());
95 template <
typename I,
typename L>
97 mean_values(const Image<I>& input_,
98 const Image<L>& lbl_, mln_value(L) nlabels)
100 trace::entering(
"mln::labeling::impl::generic::mean_values");
102 internal::mean_values_tests(input_, lbl_, nlabels);
104 const I& input = exact(input_);
105 const L& lbl = exact(lbl_);
106 typedef mln_value(L) LV;
107 typedef mln_value(I) IV;
109 util::array<
float> m_3f
110 = labeling::
compute(accu::stat::mean<IV>(),
117 convert::from_to(m_3f, m);
120 mln_concrete(I) output =
data::transform(lbl, m);
122 trace::exiting("mln::labeling::impl::generic::mean_values");
128 template <typename I, typename L>
130 mean_values_rgb(const Image<I>& input_,
131 const Image<L>& lbl_, mln_value(L) nlabels)
133 trace::entering(
"mln::labeling::impl::mean_values_rgb");
135 internal::mean_values_tests(input_, lbl_, nlabels);
137 const I& input = exact(input_);
138 const L& lbl = exact(lbl_);
146 util::array<mln_value(I)> m;
147 convert::from_to(m_3f, m);
150 mln_concrete(I) output =
data::transform(lbl,
151 convert::to< fun::i2v::array<mln_value(I)> >(m));
154 trace::exiting("mln::labeling::impl::mean_values_rgb");
164 template <
unsigned n,
typename I,
typename L>
166 mean_values_dispatch(const
value::rgb<n>&,
167 const Image<I>& input,
168 const Image<L>& lbl, mln_value(L) nlabels)
170 return impl::mean_values_rgb(input, lbl, nlabels);
173 template <
typename I,
typename L>
175 mean_values_dispatch(const mln_value(I)&,
176 const Image<I>& input,
177 const Image<L>& lbl, mln_value(L) nlabels)
179 return impl::generic::mean_values(input, lbl, nlabels);
182 template <
typename I,
typename L>
184 mean_values_dispatch(const Image<I>& input,
185 const Image<L>& lbl, mln_value(L) nlabels)
187 return mean_values_dispatch(mln_value(I)(), input, lbl, nlabels);
196 template <
typename I,
typename L>
198 mean_values(const Image<I>& input,
199 const Image<L>& lbl, mln_value(L) nlabels)
202 trace::entering(
"mln::labeling::mean_values");
204 internal::mean_values_tests(input, lbl, nlabels);
206 mln_concrete(I) output = internal::mean_values_dispatch(input, lbl, nlabels);
208 trace::exiting("mln::labeling::mean_values");
213 # endif // !MLN_INCLUDE_ONLY
219 #endif // ! MLN_LABELING_MEAN_VALUES_HH