27 #ifndef SCRIBO_BINARIZATION_INTERNAL_NIBLACK_FUNCTOR_FAST_HH
28 # define SCRIBO_BINARIZATION_INTERNAL_NIBLACK_FUNCTOR_FAST_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
71 void exec(
double mean,
double stddev);
81 const mln_value(I)*
pi;
93 #ifndef MLN_INCLUDE_ONLY
98 : input(
exact(input_)),
99 pi(&input(input.domain().pmin())),
102 mln_precondition(
exact(input).is_valid());
105 template <
typename I>
107 niblack_functor_fast<I>::init()
116 int more_offset = - (3 - input.ncols() % 3);
117 if (more_offset == - 3)
120 next_line3 = input.delta_offset(
dpoint2d(+2,0))
121 + 2 * input.border() + more_offset;
123 offset1 = input.delta_offset(
dpoint2d(+1,0));
124 offset2 = input.delta_offset(
dpoint2d(+2,0));
127 po = &output(output.domain().pmin());
130 template <
typename I>
132 niblack_functor_fast<I>::exec(
double mean,
double stddev)
134 double th = formula_(mean, stddev, K_);
136 for (
int i = 0; i < step; ++i, ++po, ++
pi)
139 *(po + offset1) = (*(
pi + offset1) <= th);
140 *(po + offset2) = (*(
pi + offset2) <= th);
143 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
145 unsigned index =
pi - input.buffer();
147 debug_mean.element(index) = mean * mean_debug_factor;
148 debug_stddev.element(index) = stddev * stddev_debug_factor;
149 debug_threshold.element(index) = th;
150 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
154 template <
typename I>
156 niblack_functor_fast<I>::end_of_row(
int)
162 template <
typename I>
164 niblack_functor_fast<I>::finalize()
168 #endif // ! MLN_INCLUDE_ONLY
176 #endif // SCRIBO_BINARIZATION_INTERNAL_NIBLACK_FUNCTOR_FAST_HH