27 #ifndef SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_MS_FUNCTOR_HH
28 # define SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_MS_FUNCTOR_HH
34 # include <mln/core/image/image2d.hh>
35 # include <mln/core/alias/neighb2d.hh>
36 # include <mln/extension/fill.hh>
37 # include <mln/value/int_u8.hh>
38 # include <mln/data/fill.hh>
40 # include <scribo/binarization/internal/sauvola_formula.hh>
42 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
43 # include <scribo/binarization/internal/local_threshold_debug.hh>
44 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
46 #include <mln/value/int_u8.hh>
74 mln_fwd_pixter(
const I) pxl;
81 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
83 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
96 unsigned i,
unsigned q);
99 void exec(
double mean,
double stddev);
100 void end_of_row(
int row);
106 # ifndef MLN_INCLUDE_ONLY
109 # ifndef MLN_WO_GLOBAL_VARS
111 double k2 = SCRIBO_DEFAULT_SAUVOLA_K;
112 double k3 = SCRIBO_DEFAULT_SAUVOLA_K;
113 double k4 = SCRIBO_DEFAULT_SAUVOLA_K;
115 # endif // ! MLN_WO_GLOBAL_VARS
123 return parent.
element(x) = my_find_root(parent,
128 template <
typename I>
129 sauvola_ms_functor<I>::sauvola_ms_functor(
const I& input,
132 unsigned i,
unsigned q)
141 mln_precondition(
exact(input).is_valid());
142 mln_precondition(R > 0.);
144 mln_precondition(q > 0);
145 mln_precondition(i > 1);
154 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
159 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
166 dp = negative_offsets_wrt(input,
c8());
170 K_ = binarization::internal::k2;
172 K_ = binarization::internal::k3;
174 K_ = binarization::internal::k4;
178 template <
typename I>
180 sauvola_ms_functor<I>::init()
185 template <
typename I>
187 sauvola_ms_functor<I>::exec(
double mean,
double stddev)
189 mln_precondition(pxl.is_valid());
191 unsigned p = pxl.offset();
196 msk.element(p) = input.element(p) < t_p;
198 # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
199 full_msk.element(p) = msk.element(p);
200 # endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
202 t_sub.element(p) = t_p;
203 if (! msk.element(p))
209 for (
unsigned i = 0; i < n_nbhs; ++i)
211 unsigned n = p +
dp[i];
212 if (! msk.element(n))
214 unsigned r = my_find_root(parent, n);
226 template <
typename I>
228 sauvola_ms_functor<I>::end_of_row(
int row)
233 template <
typename I>
234 void sauvola_ms_functor<I>::finalize()
236 mln_assertion(! pxl.is_valid());
239 #endif // ! MLN_INCLUDE_ONLY
247 #endif // SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_MS_FUNCTOR_HH