27 #ifndef SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_FUNCTOR_HH
28 # define SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_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
71 void exec(
double mean,
double stddev);
81 const mln_value(I)*
pi;
94 #ifndef MLN_INCLUDE_ONLY
99 : input(
exact(input_)),
100 pi(&input(input.domain().pmin())),
104 mln_precondition(
exact(input).is_valid());
105 mln_precondition(K > 0.);
106 mln_precondition(R > 0.);
110 template <
typename I>
112 sauvola_functor<I>::init()
121 int more_offset = - (3 - input.ncols() % 3);
122 if (more_offset == - 3)
125 next_line3 = input.delta_offset(
dpoint2d(+2,0))
126 + 2 * input.border() + more_offset;
128 offset1 = input.delta_offset(
dpoint2d(+1,0));
129 offset2 = input.delta_offset(
dpoint2d(+2,0));
132 po = &output(output.domain().pmin());
136 template <
typename I>
138 sauvola_functor<I>::exec(
double mean,
double stddev)
140 mln_assertion(input.border() == output.border());
142 double th = formula_(mean, stddev, K_, R_);
144 for (
int i = 0; i < step; ++i, ++po, ++
pi)
147 *(po + offset1) = (*(
pi + offset1) <= th);
148 *(po + offset2) = (*(
pi + offset2) <= th);
151 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
153 unsigned index =
pi - input.buffer();
155 debug_mean.element(index) = mean * mean_debug_factor;
156 debug_stddev.element(index) = stddev * stddev_debug_factor;
157 debug_threshold.element(index) = th;
159 double alpha = K_ * (1 - stddev / R_);
160 debug_alpham.element(index) = alpha * mean * alpham_debug_factor;
161 debug_alphacond.element(index) = (stddev < (alpha * mean / 2.));
162 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
166 template <
typename I>
168 sauvola_functor<I>::end_of_row(
int)
174 template <
typename I>
176 sauvola_functor<I>::finalize()
180 #endif // ! MLN_INCLUDE_ONLY
188 #endif // SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_FUNCTOR_HH