* sauvola_fast.cc,
* scribo/binarization/internal/local_threshold_core.hh,
* tests/binarization/niblack.cc,
* tests/binarization/niblack.ref.pbm,
* tests/binarization/sauvola.cc,
* tests/binarization/sauvola.ref.pbm: Here.
---
scribo/ChangeLog | 11 ++
scribo/sauvola_fast.cc | 109 +++----------------
.../binarization/internal/local_threshold_core.hh | 11 ++-
scribo/tests/binarization/niblack.cc | 1 -
scribo/tests/binarization/niblack.ref.pbm | Bin 32884 -> 32884 bytes
scribo/tests/binarization/sauvola.cc | 1 -
scribo/tests/binarization/sauvola.ref.pbm | Bin 32884 -> 32884 bytes
7 files changed, 38 insertions(+), 95 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 8cc3cd6..f2268fb 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,16 @@
2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Fix binarization tests.
+
+ * sauvola_fast.cc,
+ * scribo/binarization/internal/local_threshold_core.hh,
+ * tests/binarization/niblack.cc,
+ * tests/binarization/niblack.ref.pbm,
+ * tests/binarization/sauvola.cc,
+ * tests/binarization/sauvola.ref.pbm: Here.
+
+2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Revamp *_threshold functions.
* scribo/binarization/internal/sauvola_core.hh: Remove.
diff --git a/scribo/sauvola_fast.cc b/scribo/sauvola_fast.cc
index 7eb41ca..f412bbe 100644
--- a/scribo/sauvola_fast.cc
+++ b/scribo/sauvola_fast.cc
@@ -5,96 +5,18 @@
#include <mln/util/couple.hh>
#include <mln/util/timer.hh>
#include <scribo/binarization/internal/sauvola_formula.hh>
+#include <scribo/binarization/internal/sauvola_functor.hh>
#include <scribo/util/init_integral_image.hh>
#include <scribo/util/integral_sum_sum2_functor.hh>
+#include <scribo/util/compute_sub_domains.hh>
-namespace mln
-{
-
- template <typename I>
- struct sauvola_functor
- {
-
- const I& input;
- typedef mln_ch_value(I,bool) bin_t;
- bin_t bin;
-
- image2d<double> th_;
-
- const mln_value(I)* pi;
- bool* po;
-
- double K_;
- double R_;
-
- scribo::binarization::internal::sauvola_formula formula_;
-
- int step_;
- unsigned next_line2;
- unsigned next_line3;
- unsigned offset1;
- unsigned offset2;
-
- sauvola_functor(const I& input_, mln_ch_value(I,bool)& bin_, double K, double
R)
- : input(input_),
- bin(bin_),
- pi(&input(input.domain().pmin())),
- po(&bin(bin.domain().pmin())),
- K_(K),
- R_(R)
- {
- step_ = 3;
- unsigned next_line1 = 2 * input.border();
- next_line2 = input.delta_index(dpoint2d(+1,0)) + next_line1;
- next_line3 = input.delta_index(dpoint2d(+2,0)) + next_line1;
-
- offset1 = input.delta_index(dpoint2d(+1,0));
- offset2 = input.delta_index(dpoint2d(+2,0));
- }
-
- // Run every 4 pixels.
- void exec(double mean, double stddev)
- {
- static point2d p(0,0);
-
- double th = formula_(p, mean, stddev, K_, R_);
-
- for (int i = 0; i < step_; ++i, ++po, ++pi)
- {
- *po = (*pi <= th);
- *(po + offset1) = (*(pi + offset1) <= th);
- *(po + offset2) = (*(pi + offset2) <= th);
- }
-
-# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
- // Store local mean
- unsigned index = pi - input.buffer();
-
- internal::debug_mean.element(index) = mean * internal::mean_debug_factor;
- internal::debug_stddev.element(index) = stddev * internal::stddev_debug_factor;
- internal::debug_threshold.element(index) = t;
-
- double alpha = K * (1 - stddev / R);
- internal::debug_alpham.element(index) = alpha * mean *
internal::alpham_debug_factor;
- internal::debug_alphacond.element(index) = (stddev < (alpha * mean / 2.));
-# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
-
- }
-
- void end_of_row(int)
- {
- po += next_line3;
- pi += next_line3;
- }
-
-
- void finalize()
- {
- }
-
- };
+#include <mln/io/dump/save.hh>
+#include <mln/border/mirror.hh>
+#include <mln/border/adjust.hh>
+namespace mln
+{
image2d<bool>
sauvola_fast(const image2d<value::int_u8>& input, unsigned win)
@@ -102,9 +24,16 @@ namespace mln
util::timer t;
t.start();
+ 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);
+
scribo::util::integral_sum_sum2_functor<value::int_u8, double> fi;
image2d<util::couple<double,double> >
- integral = scribo::util::init_integral_image(input, 3, fi);
+ integral = scribo::util::init_integral_image(input, 3, fi, sub_domains[2].first(),
+ sub_domains[2].second());
t.stop();
std::cout << "image integrale - " << t << std::endl;
@@ -119,11 +48,9 @@ namespace mln
# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
t.restart();
- image2d<bool> output;
- initialize(output, input);
- sauvola_functor<image2d<value::int_u8> > f(input, output,
- SCRIBO_DEFAULT_SAUVOLA_K,
- SCRIBO_DEFAULT_SAUVOLA_R);
+ scribo::binarization::internal::sauvola_functor<image2d<value::int_u8> >
f(input,
+ SCRIBO_DEFAULT_SAUVOLA_K,
+ SCRIBO_DEFAULT_SAUVOLA_R);
scribo::canvas::integral_browsing(integral, 1, win / 3, win / 3, 3, f);
t.stop();
std::cout << "Binarization - " << t << std::endl;
diff --git a/scribo/scribo/binarization/internal/local_threshold_core.hh
b/scribo/scribo/binarization/internal/local_threshold_core.hh
index f2c9cb1..9ea81f9 100644
--- a/scribo/scribo/binarization/internal/local_threshold_core.hh
+++ b/scribo/scribo/binarization/internal/local_threshold_core.hh
@@ -152,8 +152,15 @@ namespace scribo
# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
t.restart();
- scribo::canvas::integral_browsing(integral, 1, window_size / 3,
- window_size / 3, 3, f);
+
+ window_size /= 3;
+ if (window_size % 2)
+ window_size += 2;
+ else
+ window_size += 1;
+
+ scribo::canvas::integral_browsing(integral, 1, window_size,
+ window_size, 3, f);
t.stop();
std::cout << "Binarization - " << t << std::endl;
diff --git a/scribo/tests/binarization/niblack.cc b/scribo/tests/binarization/niblack.cc
index 99a58e2..0263c1e 100644
--- a/scribo/tests/binarization/niblack.cc
+++ b/scribo/tests/binarization/niblack.cc
@@ -30,7 +30,6 @@
#include <mln/value/int_u8.hh>
#include <mln/io/pgm/load.hh>
#include <mln/io/pbm/load.hh>
-#include <mln/io/pbm/save.hh>
#include <scribo/binarization/niblack.hh>
diff --git a/scribo/tests/binarization/niblack.ref.pbm
b/scribo/tests/binarization/niblack.ref.pbm
index 83cf4fb..225b1df 100644
Binary files a/scribo/tests/binarization/niblack.ref.pbm and
b/scribo/tests/binarization/niblack.ref.pbm differ
diff --git a/scribo/tests/binarization/sauvola.cc b/scribo/tests/binarization/sauvola.cc
index 33eb59f..99efce5 100644
--- a/scribo/tests/binarization/sauvola.cc
+++ b/scribo/tests/binarization/sauvola.cc
@@ -30,7 +30,6 @@
#include <mln/value/int_u8.hh>
#include <mln/io/pgm/load.hh>
#include <mln/io/pbm/load.hh>
-#include <mln/io/pbm/save.hh>
#include <scribo/binarization/sauvola.hh>
diff --git a/scribo/tests/binarization/sauvola.ref.pbm
b/scribo/tests/binarization/sauvola.ref.pbm
index 65d5a72..6eaf2fa 100644
Binary files a/scribo/tests/binarization/sauvola.ref.pbm and
b/scribo/tests/binarization/sauvola.ref.pbm differ
--
1.7.2.5