27 #ifndef SCRIBO_BINARIZATION_INTERNAL_NIBLACK_THRESHOLD_FUNCTOR_HH
28 # define SCRIBO_BINARIZATION_INTERNAL_NIBLACK_THRESHOLD_FUNCTOR_HH
34 # include <mln/core/image/image2d.hh>
35 # include <mln/core/alias/neighb2d.hh>
36 # include <mln/extension/fill.hh>
38 # include <scribo/binarization/internal/niblack_formula.hh>
40 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
41 # include <scribo/binarization/internal/local_threshold_debug.hh>
42 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
72 void exec(
double mean,
double stddev);
93 #ifndef MLN_INCLUDE_ONLY
101 mln_precondition(
exact(input_).is_valid());
102 mln_precondition(K > 0.);
105 template <
typename I>
107 niblack_threshold_functor<I>::init()
111 next_line3 = input.delta_offset(
dpoint2d(+2,0)) + 2 * input.border() - 1;
113 offset1 = input.delta_offset(
dpoint2d(+1,0));
114 offset2 = input.delta_offset(
dpoint2d(+2,0));
117 po = &output(output.domain().pmin());
120 template <
typename I>
122 niblack_threshold_functor<I>::exec(
double mean,
double stddev)
124 mln_assertion(input.border() == output.border());
127 typedef mln_value(I) V;
128 V th = static_cast<V>(formula_(mean, stddev, K_));
130 for (
int i = 0; i < step; ++i, ++po)
133 *(po + offset1) = th;
134 *(po + offset2) = th;
137 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
139 unsigned index = po - output.buffer();
141 internal::debug_mean.element(index) = mean * internal::mean_debug_factor;
142 internal::debug_stddev.element(index) = stddev * internal::stddev_debug_factor;
143 internal::debug_threshold.element(index) = t;
144 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
148 template <
typename I>
150 niblack_threshold_functor<I>::end_of_row(
int)
155 template <
typename I>
157 niblack_threshold_functor<I>::finalize()
161 #endif // ! MLN_INCLUDE_ONLY
169 #endif // SCRIBO_BINARIZATION_INTERNAL_NIBLACK_THRESHOLD_FUNCTOR_HH