27 #ifndef SCRIBO_BINARIZATION_INTERNAL_LOCAL_THRESHOLD_CORE_HH
28 # define SCRIBO_BINARIZATION_INTERNAL_LOCAL_THRESHOLD_CORE_HH
34 # include <mln/core/concept/image.hh>
35 # include <mln/data/transform.hh>
36 # include <mln/value/int_u8.hh>
38 # include <mln/border/mirror.hh>
39 # include <mln/border/adjust.hh>
41 # include <scribo/canvas/integral_browsing.hh>
43 # include <scribo/util/init_integral_image.hh>
44 # include <scribo/util/integral_sum_sum2_functor.hh>
45 # include <scribo/util/compute_sub_domains.hh>
47 # include <scribo/debug/logger.hh>
48 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
49 # include <scribo/binarization/internal/local_threshold_debug.hh>
50 # include <mln/io/pgm/save.hh>
51 # include <mln/io/pbm/save.hh>
52 # include <mln/data/saturate.hh>
53 # include <mln/debug/filename.hh>
54 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
77 template <
typename I,
typename F>
79 local_threshold_core(
const Image<I>& input, F& f,
80 unsigned window_size);
82 template <
typename I,
typename F>
84 local_threshold_core(
const Image<I>& input, F& f,
85 unsigned window_size);
91 template <
typename I,
typename F>
93 local_threshold_core(
const Image<I>& input, F& f);
96 # ifndef MLN_INCLUDE_ONLY
109 template <
typename I,
typename F>
111 local_threshold_core(
const Image<I>& ,
114 mln_trace(
"scribo::binarization::internal::impl::generic::local_threshold_core");
117 mlc_abort(I)::check();
124 template <
typename I,
typename F>
126 local_threshold_core_fastest(
const Image<I>& input, F& f,
unsigned window_size)
128 mln_trace(
"scribo::binarization::internal::impl::generic::local_threshold_core");
129 mln_precondition(
exact(input).is_valid());
133 int integral_scale_ratio = F::step;
139 sub_domains = scribo::util::compute_sub_domains(input, 1,
140 integral_scale_ratio);
147 integral = scribo::util::init_integral_image(input, integral_scale_ratio,
149 sub_domains[2].first(),
150 sub_domains[2].second());
154 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
161 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
165 window_size /= integral_scale_ratio;
171 scribo::canvas::integral_browsing(integral, 1, window_size,
172 window_size, integral_scale_ratio,
189 template <
typename I,
typename F>
191 local_threshold_core_dispatch(
const mln_value(I)&,
193 unsigned window_size)
195 impl::generic::local_threshold_core(input, f, window_size);
198 template <
typename I,
typename F>
200 local_threshold_core_dispatch(mln::trait::image::speed::fastest,
203 unsigned window_size)
205 impl::local_threshold_core_fastest(input, f, window_size);
209 template <
typename I,
typename F>
211 local_threshold_core_dispatch(
const Image<I>& input, F& f,
212 unsigned window_size)
214 typedef mln_value(I) V;
215 local_threshold_core_dispatch(mln_trait_image_speed(I)(),
216 V(), input, f, window_size);
225 template <typename I, typename F>
227 local_threshold_core(const
Image<I>& input, F& f,
unsigned window_size)
229 mln_trace(
"scribo::binarization::internal::local_threshold_core");
231 mln_precondition(
exact(input).is_valid());
233 internal::local_threshold_core_dispatch(input, f, window_size);
235 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
236 if (stddev_image_output)
239 if (mean_image_output)
242 if (threshold_image_output)
246 if (alpham_image_output)
249 if (alphacond_image_output)
252 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
256 template <
typename I,
typename F>
258 local_threshold_core(
const Image<I>& input, F& f)
260 local_threshold_core(input, f, 11);
264 # endif // ! MLN_INCLUDE_ONLY
273 #endif // ! SCRIBO_BINARIZATION_INTERNAL_LOCAL_THRESHOLD_CORE_HH