* scribo/binarization/internal/sauvola_core.hh: Remove.
* scribo/binarization/internal/local_threshold_core.hh: New.
* scribo/binarization/internal/niblack_threshold_functor.hh,
* scribo/binarization/internal/sauvola_functor.hh,
* scribo/binarization/internal/sauvola_threshold_functor.hh,
* scribo/binarization/niblack.hh,
* scribo/binarization/niblack_threshold.hh,
* scribo/binarization/sauvola.hh,
* scribo/binarization/sauvola_threshold.hh: Make use of
local_threshold_core.
---
scribo/ChangeLog | 17 +++
.../{sauvola_core.hh => local_threshold_core.hh} | 46 +++---
.../internal/niblack_threshold_functor.hh | 7 +-
.../binarization/internal/sauvola_functor.hh | 3 +-
.../internal/sauvola_threshold_functor.hh | 10 +-
scribo/scribo/binarization/niblack.hh | 4 +-
scribo/scribo/binarization/niblack_threshold.hh | 141 +-------------------
scribo/scribo/binarization/sauvola.hh | 4 +-
scribo/scribo/binarization/sauvola_threshold.hh | 142 +-------------------
9 files changed, 67 insertions(+), 307 deletions(-)
rename scribo/scribo/binarization/internal/{sauvola_core.hh =>
local_threshold_core.hh} (81%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 758b824..8cc3cd6 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,22 @@
2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Revamp *_threshold functions.
+
+ * scribo/binarization/internal/sauvola_core.hh: Remove.
+
+ * scribo/binarization/internal/local_threshold_core.hh: New.
+
+ * scribo/binarization/internal/niblack_threshold_functor.hh,
+ * scribo/binarization/internal/sauvola_functor.hh,
+ * scribo/binarization/internal/sauvola_threshold_functor.hh,
+ * scribo/binarization/niblack.hh,
+ * scribo/binarization/niblack_threshold.hh,
+ * scribo/binarization/sauvola.hh,
+ * scribo/binarization/sauvola_threshold.hh: Make use of
+ local_threshold_core.
+
+2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Refactor local threshold binarization algorithms.
* scribo/binarization/internal/compute_local_threshold.hh,
diff --git a/scribo/scribo/binarization/internal/sauvola_core.hh
b/scribo/scribo/binarization/internal/local_threshold_core.hh
similarity index 81%
rename from scribo/scribo/binarization/internal/sauvola_core.hh
rename to scribo/scribo/binarization/internal/local_threshold_core.hh
index 9e3592f..f2c9cb1 100644
--- a/scribo/scribo/binarization/internal/sauvola_core.hh
+++ b/scribo/scribo/binarization/internal/local_threshold_core.hh
@@ -23,8 +23,8 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_CORE_HH
-# define SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_CORE_HH
+#ifndef SCRIBO_BINARIZATION_INTERNAL_LOCAL_THRESHOLD_CORE_HH
+# define SCRIBO_BINARIZATION_INTERNAL_LOCAL_THRESHOLD_CORE_HH
/// \file
///
@@ -74,7 +74,7 @@ namespace scribo
*/
template <typename I, typename F>
void
- sauvola_core(const Image<I>& input, F& f,
+ local_threshold_core(const Image<I>& input, F& f,
unsigned window_size);
@@ -83,7 +83,7 @@ namespace scribo
//
template <typename I, typename F>
void
- sauvola_core(const Image<I>& input, F& f);
+ local_threshold_core(const Image<I>& input, F& f);
# ifndef MLN_INCLUDE_ONLY
@@ -101,14 +101,14 @@ namespace scribo
template <typename I, typename F>
void
- sauvola_core(const Image<I>& input, unsigned window_size)
+ local_threshold_core(const Image<I>& input, unsigned window_size)
{
-
trace::entering("scribo::binarization::internal::impl::generic::sauvola_core");
+
trace::entering("scribo::binarization::internal::impl::generic::local_threshold_core");
// Not implemented
mlc_abort(I)::check();
-
trace::exiting("scribo::binarization::internal::impl::generic::sauvola_core");
+
trace::exiting("scribo::binarization::internal::impl::generic::local_threshold_core");
}
} // end of namespace scribo::binarization::internal::impl::generic
@@ -116,9 +116,9 @@ namespace scribo
template <typename I, typename F>
void
- sauvola_core_fastest(const Image<I>& input, F& f, unsigned window_size)
+ local_threshold_core_fastest(const Image<I>& input, F& f, unsigned
window_size)
{
-
trace::entering("scribo::binarization::internal::impl::generic::sauvola_core");
+
trace::entering("scribo::binarization::internal::impl::generic::local_threshold_core");
mln_precondition(exact(input).is_valid());
mln::util::timer t;
@@ -157,7 +157,7 @@ namespace scribo
t.stop();
std::cout << "Binarization - " << t << std::endl;
-
trace::exiting("scribo::binarization::internal::impl::generic::sauvola_core");
+
trace::exiting("scribo::binarization::internal::impl::generic::local_threshold_core");
}
@@ -172,31 +172,31 @@ namespace scribo
template <typename I, typename F>
void
- sauvola_core_dispatch(const mln_value(I)&,
+ local_threshold_core_dispatch(const mln_value(I)&,
const Image<I>& input, F& f,
unsigned window_size)
{
- impl::generic::sauvola_core(input, f, window_size);
+ impl::generic::local_threshold_core(input, f, window_size);
}
template <typename I, typename F>
void
- sauvola_core_dispatch(mln::trait::image::speed::fastest,
+ local_threshold_core_dispatch(mln::trait::image::speed::fastest,
const mln_value(I)&,
const Image<I>& input, F& f,
unsigned window_size)
{
- impl::sauvola_core_fastest(input, f, window_size);
+ impl::local_threshold_core_fastest(input, f, window_size);
}
template <typename I, typename F>
void
- sauvola_core_dispatch(const Image<I>& input, F& f,
+ local_threshold_core_dispatch(const Image<I>& input, F& f,
unsigned window_size)
{
typedef mln_value(I) V;
- sauvola_core_dispatch(mln_trait_image_speed(I)(),
+ local_threshold_core_dispatch(mln_trait_image_speed(I)(),
V(), input, f, window_size);
}
@@ -208,13 +208,13 @@ namespace scribo
template <typename I, typename F>
void
- sauvola_core(const Image<I>& input, F& f, unsigned window_size)
+ local_threshold_core(const Image<I>& input, F& f, unsigned
window_size)
{
- trace::entering("scribo::binarization::internal::sauvola_core");
+ trace::entering("scribo::binarization::internal::local_threshold_core");
mln_precondition(exact(input).is_valid());
- internal::sauvola_core_dispatch(input, f, window_size);
+ internal::local_threshold_core_dispatch(input, f, window_size);
# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
if (stddev_image_output)
@@ -234,14 +234,14 @@ namespace scribo
io::pbm::save(debug_alphacond, alphacond_image_output);
# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
- trace::exiting("scribo::binarization::internal::sauvola_core");
+ trace::exiting("scribo::binarization::internal::local_threshold_core");
}
template <typename I, typename F>
void
- sauvola_core(const Image<I>& input, F& f)
+ local_threshold_core(const Image<I>& input, F& f)
{
- sauvola_core(input, f, 11);
+ local_threshold_core(input, f, 11);
}
@@ -254,4 +254,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_BINARIZATION_INTERNAL_SAUVOLA_CORE_HH
+#endif // ! SCRIBO_BINARIZATION_INTERNAL_LOCAL_THRESHOLD_CORE_HH
diff --git a/scribo/scribo/binarization/internal/niblack_threshold_functor.hh
b/scribo/scribo/binarization/internal/niblack_threshold_functor.hh
index b6d6aae..979bb67 100644
--- a/scribo/scribo/binarization/internal/niblack_threshold_functor.hh
+++ b/scribo/scribo/binarization/internal/niblack_threshold_functor.hh
@@ -56,7 +56,7 @@ namespace scribo
template <typename I>
struct niblack_threshold_functor
{
- niblack_threshold_functor(const I& input,
+ niblack_threshold_functor(const Image<I>& input,
double K);
// Run every 4 pixels.
@@ -84,10 +84,13 @@ namespace scribo
#ifndef MLN_INCLUDE_ONLY
template <typename I>
- niblack_threshold_functor<I>::niblack_threshold_functor(const I& input,
+ niblack_threshold_functor<I>::niblack_threshold_functor(const
Image<I>& input_,
double K)
: K_(K)
{
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
step_ = 3;
next_line3 = input.delta_index(dpoint2d(+2,0)) + 2 * input.border() - 1;
diff --git a/scribo/scribo/binarization/internal/sauvola_functor.hh
b/scribo/scribo/binarization/internal/sauvola_functor.hh
index bff8b6f..5363215 100644
--- a/scribo/scribo/binarization/internal/sauvola_functor.hh
+++ b/scribo/scribo/binarization/internal/sauvola_functor.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
diff --git a/scribo/scribo/binarization/internal/sauvola_threshold_functor.hh
b/scribo/scribo/binarization/internal/sauvola_threshold_functor.hh
index d7eaf4a..bb38696 100644
--- a/scribo/scribo/binarization/internal/sauvola_threshold_functor.hh
+++ b/scribo/scribo/binarization/internal/sauvola_threshold_functor.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -57,7 +56,7 @@ namespace scribo
template <typename I>
struct sauvola_threshold_functor
{
- sauvola_threshold_functor(const I& input,
+ sauvola_threshold_functor(const Image<I>& input,
double K, double R);
// Run every 4 pixels.
@@ -86,11 +85,14 @@ namespace scribo
#ifndef MLN_INCLUDE_ONLY
template <typename I>
- sauvola_threshold_functor<I>::sauvola_threshold_functor(const I& input,
+ sauvola_threshold_functor<I>::sauvola_threshold_functor(const
Image<I>& input_,
double K, double R)
: K_(K),
R_(R)
{
+ const I& input = exact(input_);
+ mln_precondition(input.is_valid());
+
step_ = 3;
next_line3 = input.delta_index(dpoint2d(+2,0)) + 2 * input.border() - 1;
diff --git a/scribo/scribo/binarization/niblack.hh
b/scribo/scribo/binarization/niblack.hh
index 00e6ab6..7561525 100644
--- a/scribo/scribo/binarization/niblack.hh
+++ b/scribo/scribo/binarization/niblack.hh
@@ -33,7 +33,7 @@
# include <mln/core/concept/image.hh>
# include <scribo/binarization/internal/niblack_functor.hh>
-# include <scribo/binarization/internal/sauvola_core.hh>
+# include <scribo/binarization/internal/local_threshold_core.hh>
namespace scribo
{
@@ -96,7 +96,7 @@ namespace scribo
mln_precondition(exact(input).is_valid());
internal::niblack_functor<I> f(input, K);
- internal::sauvola_core(input, f, window_size);
+ internal::local_threshold_core(input, f, window_size);
trace::exiting("scribo::binarization::niblack");
return f.output;
diff --git a/scribo/scribo/binarization/niblack_threshold.hh
b/scribo/scribo/binarization/niblack_threshold.hh
index 34517cb..a6b2dbf 100644
--- a/scribo/scribo/binarization/niblack_threshold.hh
+++ b/scribo/scribo/binarization/niblack_threshold.hh
@@ -36,23 +36,9 @@
# include <algorithm>
# include <cmath>
-# include <mln/core/image/image2d.hh>
-# include <mln/value/int_u.hh>
-# include <mln/value/int_u8.hh>
-
-# include <mln/border/mirror.hh>
-# include <mln/border/adjust.hh>
-
-# include <scribo/core/init_integral_image.hh>
-# include <scribo/binarization/internal/niblack_formula.hh>
+# include <mln/core/concept/image.hh>
# include <scribo/binarization/internal/niblack_threshold_functor.hh>
-
-# include <scribo/util/init_integral_image.hh>
-# include <scribo/util/integral_sum_sum2_functor.hh>
-# include <scribo/util/compute_sub_domains.hh>
-
-# include <scribo/canvas/integral_browsing.hh>
-
+# include <scribo/binarization/internal/local_threshold_core.hh>
namespace scribo
@@ -97,119 +83,6 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
-
- // Implementation
-
-
- namespace impl
- {
-
- namespace generic
- {
-
- template <typename I>
- inline
- mln_concrete(I)
- niblack_threshold(const Image<I>& input_, unsigned window_size,
- double K)
- {
- trace::entering("scribo::binarization::impl::generic::niblack_threshold");
-
- // Not implemented
- mlc_abort(I)::check();
-
- typedef mln_concrete(I) output_t;
- trace::exiting("scribo::binarization::impl::generic::niblack_threshold");
- return output_t();
- }
-
- } // end of namespace scribo::binarization::impl::generic
-
-
- template <typename I>
- inline
- mln_concrete(I)
- niblack_threshold_gl(const Image<I>& input_, unsigned window_size,
- double K)
- {
- trace::entering("scribo::binarization::impl::niblack_threshold_gl");
-
- const I& input = exact(input_);
-
- mln_precondition(exact(input).is_valid());
-
- // Make sure the image sizes are a multiple of 3 in each
- // dimension. (browsing while binarizing relies on that
- // property).
- mln::util::array<mln::util::couple<box2d, unsigned> >
- sub_domains = scribo::util::compute_sub_domains(input, 1, 3);
-
- border::adjust(input, sub_domains(1).second());
- border::mirror(input);
-
- typedef mln::util::couple<double,double> V_i;
- scribo::util::integral_sum_sum2_functor<mln_value(I), double> fi;
- mln_ch_value(I,V_i)
- integral = scribo::util::init_integral_image(input, 3, fi);
-
-# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
- initialize(internal::debug_mean, input);
- initialize(internal::debug_stddev, input);
-
- initialize(internal::debug_threshold, input);
- initialize(internal::debug_alpham, input);
- initialize(internal::debug_alphacond, input);
-# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
-
- internal::niblack_threshold_functor<I> f(input, K);
- scribo::canvas::integral_browsing(integral, 1, window_size / 3,
- window_size / 3, 3, f);
-
- trace::exiting("scribo::binarization::impl::niblack_threshold_gl");
- return f.output;
- }
-
-
- } // end of namespace scribo::binarization::impl
-
-
-
-
- // Dispatch
-
- namespace internal
- {
-
- template <unsigned n, typename I>
- inline
- mln_ch_value(I, value::int_u<n>)
- niblack_threshold_dispatch(const value::int_u<n>&, const I& input,
- unsigned window_size,
- double K)
- {
- return impl::niblack_threshold_gl(input, window_size, K);
- }
-
-
- template <typename I>
- inline
- mln_ch_value(I, value::int_u8)
- niblack_threshold_dispatch(const mln_value(I)&, const I& input,
- unsigned window_size,
- double K)
- {
- // No dispatch for this kind of value type.
- mlc_abort(I)::check();
-
- typedef mln_ch_value(I,bool) output_t;
- return output_t();
- }
-
-
- } // end of namespace scribo::binarization::internal
-
-
-
template <typename I>
mln_ch_value(I, value::int_u8)
niblack_threshold(const Image<I>& input, unsigned window_size,
@@ -220,15 +93,11 @@ namespace scribo
mln_precondition(mln_site_(I)::dim == 2);
mln_precondition(exact(input).is_valid());
- typedef mln_value(I) value_t;
- mln_ch_value(I, value::int_u8)
- output = internal::niblack_threshold_dispatch(value_t(),
- exact(input),
- window_size,
- K);
+ internal::niblack_threshold_functor<I> f(input, K);
+ internal::local_threshold_core(input, f, window_size);
trace::exiting("scribo::binarization::niblack_threshold");
- return output;
+ return f.output;
}
diff --git a/scribo/scribo/binarization/sauvola.hh
b/scribo/scribo/binarization/sauvola.hh
index ce95526..7022680 100644
--- a/scribo/scribo/binarization/sauvola.hh
+++ b/scribo/scribo/binarization/sauvola.hh
@@ -33,7 +33,7 @@
# include <mln/core/concept/image.hh>
# include <scribo/binarization/internal/sauvola_functor.hh>
-# include <scribo/binarization/internal/sauvola_core.hh>
+# include <scribo/binarization/internal/local_threshold_core.hh>
namespace scribo
{
@@ -95,7 +95,7 @@ namespace scribo
mln_precondition(exact(input).is_valid());
internal::sauvola_functor<I> f(input, K, SCRIBO_DEFAULT_SAUVOLA_R);
- internal::sauvola_core(input, f, window_size);
+ internal::local_threshold_core(input, f, window_size);
trace::exiting("scribo::binarization::sauvola");
return f.output;
diff --git a/scribo/scribo/binarization/sauvola_threshold.hh
b/scribo/scribo/binarization/sauvola_threshold.hh
index f93edae..564aaa7 100644
--- a/scribo/scribo/binarization/sauvola_threshold.hh
+++ b/scribo/scribo/binarization/sauvola_threshold.hh
@@ -36,23 +36,10 @@
# include <algorithm>
# include <cmath>
-# include <mln/core/image/image2d.hh>
-# include <mln/value/int_u.hh>
-# include <mln/value/int_u8.hh>
-
-# include <mln/border/mirror.hh>
-# include <mln/border/adjust.hh>
-
-# include <scribo/core/init_integral_image.hh>
-# include <scribo/binarization/internal/sauvola_formula.hh>
+# include <mln/core/concept/image.hh>
+# include <scribo/binarization/internal/local_threshold_core.hh>
# include <scribo/binarization/internal/sauvola_threshold_functor.hh>
-# include <scribo/util/init_integral_image.hh>
-# include <scribo/util/integral_sum_sum2_functor.hh>
-# include <scribo/util/compute_sub_domains.hh>
-
-# include <scribo/canvas/integral_browsing.hh>
-
namespace scribo
@@ -98,121 +85,8 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
- // Implementation
-
-
- namespace impl
- {
-
- namespace generic
- {
-
- template <typename I>
- inline
- mln_concrete(I)
- sauvola_threshold(const Image<I>& input_, unsigned window_size,
- double K)
- {
- trace::entering("scribo::binarization::impl::generic::sauvola_threshold");
-
- // Not implemented
- mlc_abort(I)::check();
-
- typedef mln_concrete(I) output_t;
- trace::exiting("scribo::binarization::impl::generic::sauvola_threshold");
- return output_t();
- }
-
- } // end of namespace scribo::binarization::impl::generic
-
-
- template <typename I>
- inline
- mln_concrete(I)
- sauvola_threshold_gl(const Image<I>& input_, unsigned window_size,
- double K)
- {
- trace::entering("scribo::binarization::impl::sauvola_threshold_gl");
-
- const I& input = exact(input_);
-
- mln_precondition(exact(input).is_valid());
-
- // Make sure the image sizes are a multiple of 3 in each
- // dimension. (browsing while binarizing relies on that
- // property).
- mln::util::array<mln::util::couple<box2d, unsigned> >
- sub_domains = scribo::util::compute_sub_domains(input, 1, 3);
-
- border::adjust(input, sub_domains(1).second());
- border::mirror(input);
-
- typedef mln::util::couple<double,double> V_i;
- scribo::util::integral_sum_sum2_functor<mln_value(I), double> fi;
- mln_ch_value(I,V_i)
- integral = scribo::util::init_integral_image(input, 3, fi);
-
-# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
- initialize(internal::debug_mean, input);
- initialize(internal::debug_stddev, input);
-
- initialize(internal::debug_threshold, input);
- initialize(internal::debug_alpham, input);
- initialize(internal::debug_alphacond, input);
-# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
-
- internal::sauvola_threshold_functor<I> f(input, K,
- SCRIBO_DEFAULT_SAUVOLA_R);
- scribo::canvas::integral_browsing(integral, 1, window_size / 3,
- window_size / 3, 3, f);
-
- trace::exiting("scribo::binarization::impl::sauvola_threshold_gl");
- return f.output;
- }
-
-
- } // end of namespace scribo::binarization::impl
-
-
-
-
- // Dispatch
-
- namespace internal
- {
-
- template <unsigned n, typename I>
- inline
- mln_ch_value(I, value::int_u<n>)
- sauvola_threshold_dispatch(const value::int_u<n>&, const I& input,
- unsigned window_size,
- double K)
- {
- return impl::sauvola_threshold_gl(input, window_size, K);
- }
-
-
- template <typename I>
- inline
- mln_ch_value(I, value::int_u8)
- sauvola_threshold_dispatch(const mln_value(I)&, const I& input,
- unsigned window_size,
- double K)
- {
- // No dispatch for this kind of value type.
- mlc_abort(I)::check();
-
- typedef mln_ch_value(I,bool) output_t;
- return output_t();
- }
-
-
- } // end of namespace scribo::binarization::internal
-
-
-
template <typename I>
- mln_ch_value(I, value::int_u8)
+ mln_concrete(I)
sauvola_threshold(const Image<I>& input, unsigned window_size,
double K)
{
@@ -221,15 +95,11 @@ namespace scribo
mln_precondition(mln_site_(I)::dim == 2);
mln_precondition(exact(input).is_valid());
- typedef mln_value(I) value_t;
- mln_ch_value(I, value::int_u8)
- output = internal::sauvola_threshold_dispatch(value_t(),
- exact(input),
- window_size,
- K);
+ internal::sauvola_threshold_functor<I> f(input, K,
SCRIBO_DEFAULT_SAUVOLA_R);
+ internal::local_threshold_core(input, f, window_size);
trace::exiting("scribo::binarization::sauvola_threshold");
- return output;
+ return f.output;
}
--
1.7.2.5