27 #ifndef SCRIBO_BINARIZATION_LOCAL_THRESHOLD_HH
28 # define SCRIBO_BINARIZATION_LOCAL_THRESHOLD_HH
30 # include <mln/core/concept/image.hh>
31 # include <mln/value/concept/vectorial.hh>
60 template <
typename I,
typename T>
65 # ifndef MLN_INCLUDE_ONLY
72 template <
typename I,
typename T>
76 mln_precondition(
exact(input).is_valid());
77 mln_precondition(
exact(threshold).is_valid());
79 mlc_is_not_a(mln_value(I), value::Vectorial)::check();
96 template <
typename I,
typename T>
98 local_threshold(const
Image<I>& input_, const
Image<
T>& threshold_)
100 mln_trace(
"scribo::binarization::impl::generic::local_threshold");
102 internal::local_threshold_tests(input_, threshold_);
104 const I& input =
exact(input_);
105 const T& threshold =
exact(threshold_);
108 initialize(output, input);
110 mln_piter(I) p(input.domain());
112 output(p) = (input(p) <= threshold(p));
121 template <typename I, typename
T>
122 mln_ch_value(I,
bool)
123 local_threshold_fastest(const
Image<I>& input_,
124 const
Image<
T>& threshold_)
126 mln_trace(
"scribo::binarization::impl::generic::local_threshold_fastest");
127 internal::local_threshold_tests(input_, threshold_);
129 const I& input =
exact(input_);
130 const T& threshold =
exact(threshold_);
134 initialize(output, input);
136 mln_pixter(const I)
pi(input);
137 mln_pixter(const
T) pt(threshold);
138 mln_pixter(O) po(output);
140 for_all_3(
pi, pt, po)
141 po.val() = (pi.val() <= pt.val());
157 template <
typename I,
typename T>
159 local_threshold_dispatch(trait::image::speed::any,
160 trait::image::speed::any,
163 return binarization::impl::generic::local_threshold(input, threshold);
167 template <
typename I,
typename T>
169 local_threshold_dispatch(trait::image::speed::fastest,
170 trait::image::speed::fastest,
173 return binarization::impl::local_threshold_fastest(input, threshold);
176 template <
typename I,
typename T>
178 local_threshold_dispatch(const
Image<I>& input,
179 const
Image<
T>& threshold)
181 return local_threshold_dispatch(mln_trait_image_speed(I)(),
182 mln_trait_image_speed(
T)(),
192 template <
typename I,
typename T>
194 local_threshold(const
Image<I>& input, const
Image<
T>& threshold)
196 mln_trace(
"scribo::binarization::local_threshold");
198 internal::local_threshold_tests(input, threshold);
201 output = internal::local_threshold_dispatch(input, threshold);
207 # endif // ! MLN_INCLUDE_ONLY
214 #endif // ! SCRIBO_BINARIZATION_LOCAL_THRESHOLD_HH