27 #ifndef SCRIBO_BINARIZATION_INTERNAL_SINGH_FUNCTOR_HH
28 # define SCRIBO_BINARIZATION_INTERNAL_SINGH_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/singh_formula.hh>
40 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
41 # include <scribo/binarization/internal/local_threshold_debug.hh>
42 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
60 typedef mln_value(I) V;
73 void exec(
double mean,
double stddev);
95 #ifndef MLN_INCLUDE_ONLY
99 : input(
exact(input_)),
100 pi(&input(input.domain().pmin())),
103 mln_precondition(
exact(input).is_valid());
104 mln_precondition(K > 0.);
107 template <
typename I>
109 singh_functor<I>::init()
118 int more_offset = - (3 - input.ncols() % 3);
119 if (more_offset == - 3)
122 next_line3 = input.delta_offset(
dpoint2d(+2,0))
123 + 2 * input.border() + more_offset;
125 offset1 = input.delta_offset(
dpoint2d(+1,0));
126 offset2 = input.delta_offset(
dpoint2d(+2,0));
129 po = &output(output.domain().pmin());
132 template <
typename I>
134 singh_functor<I>::exec(
double mean,
double stddev)
136 mln_precondition(input.border() == output.border());
140 for (
int i = 0; i < step; ++i, ++po, ++
pi)
142 double th = formula_(*
pi, mean, K_);
144 th = formula_(*(
pi + offset1), mean, K_);
145 *(po + offset1) = (*(
pi + offset1) <= th);
146 th = formula_(*(
pi + offset2), mean, K_);
147 *(po + offset2) = (*(
pi + offset2) <= th);
150 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
152 unsigned index =
pi - input.buffer();
154 debug_mean.element(index) = mean * mean_debug_factor;
155 debug_threshold.element(index) = th;
156 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
160 template <
typename I>
162 singh_functor<I>::end_of_row(
int)
168 template <
typename I>
170 singh_functor<I>::finalize()
174 #endif // ! MLN_INCLUDE_ONLY
182 #endif // SCRIBO_BINARIZATION_INTERNAL_SINGH_FUNCTOR_HH