27 #ifndef SCRIBO_BINARIZATION_INTERNAL_WOLF_FUNCTOR_FAST_HH
28 # define SCRIBO_BINARIZATION_INTERNAL_WOLF_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/wolf_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;
69 const mln_value(I)& global_min,
70 double global_max_stddev);
75 void exec(
double mean,
double stddev);
85 const mln_value(I)*
pi;
91 double global_max_stddev_;
100 #ifndef MLN_INCLUDE_ONLY
102 template <
typename I>
105 const mln_value(I)& global_min,
106 double global_max_stddev)
107 : input(
exact(input_)),
108 pi(&input(input.domain().pmin())),
110 global_min_(global_min),
111 global_max_stddev_(global_max_stddev)
113 mln_precondition(
exact(input).is_valid());
114 mln_precondition(K > 0.);
117 template <
typename I>
119 wolf_functor_fast<I>::init()
128 int more_offset = - (3 - input.ncols() % 3);
129 if (more_offset == - 3)
132 next_line3 = input.delta_offset(
dpoint2d(+2,0))
133 + 2 * input.border() + more_offset;
135 offset1 = input.delta_offset(
dpoint2d(+1,0));
136 offset2 = input.delta_offset(
dpoint2d(+2,0));
139 po = &output(output.domain().pmin());
142 template <
typename I>
144 wolf_functor_fast<I>::exec(
double mean,
double stddev)
146 mln_assertion(input.border() == output.border());
148 double th = formula_(mean, stddev, K_,
149 global_max_stddev_, global_min_);
151 for (
int i = 0; i < step; ++i, ++po, ++
pi)
154 *(po + offset1) = (*(
pi + offset1) <= th);
155 *(po + offset2) = (*(
pi + offset2) <= th);
158 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
160 unsigned index =
pi - input.buffer();
162 debug_mean.element(index) = mean * mean_debug_factor;
163 debug_stddev.element(index) = stddev * stddev_debug_factor;
164 debug_threshold.element(index) = th;
166 double alpha = K_ * (1 - stddev / R_);
167 debug_alpham.element(index) = alpha * mean * alpham_debug_factor;
168 debug_alphacond.element(index) = (stddev < (alpha * mean / 2.));
169 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
173 template <
typename I>
175 wolf_functor_fast<I>::end_of_row(
int)
181 template <
typename I>
183 wolf_functor_fast<I>::finalize()
187 #endif // ! MLN_INCLUDE_ONLY
195 #endif // SCRIBO_BINARIZATION_INTERNAL_WOLF_FUNCTOR_FAST_HH