27 #ifndef SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_THRESHOLD_FUNCTOR_HH
28 # define SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_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/sauvola_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);
94 #ifndef MLN_INCLUDE_ONLY
103 mln_precondition(
exact(input).is_valid());
104 mln_precondition(K > 0.);
105 mln_precondition(R > 0.);
108 template <
typename I>
110 sauvola_threshold_functor<I>::init()
115 next_line3 = input.delta_offset(
dpoint2d(+2,0)) + 2 * input.border() - 1;
117 offset1 = input.delta_offset(
dpoint2d(+1,0));
118 offset2 = input.delta_offset(
dpoint2d(+2,0));
121 po = &output(output.domain().pmin());
124 template <
typename I>
126 sauvola_threshold_functor<I>::exec(
double mean,
double stddev)
128 mln_assertion(input.border() == output.border());
131 typedef mln_value(I) V;
132 V th = static_cast<V>(formula_(mean, stddev, K_, R_));
134 for (
int i = 0; i < step; ++i, ++po)
137 *(po + offset1) = th;
138 *(po + offset2) = th;
141 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
143 unsigned index = po - output.buffer();
145 internal::debug_mean.element(index) = mean * internal::mean_debug_factor;
146 internal::debug_stddev.element(index) = stddev * internal::stddev_debug_factor;
147 internal::debug_threshold.element(index) = t;
149 double alpha = K * (1 - stddev / R);
150 internal::debug_alpham.element(index) = alpha * mean * internal::alpham_debug_factor;
151 internal::debug_alphacond.element(index) = (stddev < (alpha * mean / 2.));
152 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
156 template <
typename I>
158 sauvola_threshold_functor<I>::end_of_row(
int)
163 template <
typename I>
165 sauvola_threshold_functor<I>::finalize()
169 #endif // ! MLN_INCLUDE_ONLY
177 #endif // SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_THRESHOLD_FUNCTOR_HH