* scribo/binarization/internal/local_threshold_core.hh: Fix doc.
* scribo/binarization/internal/niblack_functor.hh,
* scribo/binarization/internal/niblack_functor_fast.hh,
* scribo/binarization/internal/niblack_threshold_functor.hh,
* scribo/binarization/internal/sauvola_functor.hh,
* scribo/binarization/internal/sauvola_ms_functor.hh,
* scribo/binarization/internal/sauvola_threshold_functor.hh,
* scribo/binarization/internal/singh_functor.hh,
* scribo/binarization/internal/wolf_functor.hh,
* scribo/binarization/internal/wolf_functor_fast.hh,
* scribo/binarization/wolf.hh,
* scribo/binarization/wolf_fast.hh: Add init() member and more assertions.
* scribo/canvas/integral_browsing.hh: Call init() function.
---
scribo/ChangeLog | 21 ++++++++++++++++++++
.../binarization/internal/local_threshold_core.hh | 10 ++++----
.../binarization/internal/niblack_functor.hh | 14 ++++++++++++-
.../binarization/internal/niblack_functor_fast.hh | 12 +++++++++++
.../internal/niblack_threshold_functor.hh | 12 +++++++++-
.../binarization/internal/sauvola_functor.hh | 18 +++++++++++++++++
.../binarization/internal/sauvola_ms_functor.hh | 18 +++++++++++++++-
.../internal/sauvola_threshold_functor.hh | 16 +++++++++++++-
.../scribo/binarization/internal/singh_functor.hh | 12 +++++++++++
.../scribo/binarization/internal/wolf_functor.hh | 17 +++++++++++++++-
.../binarization/internal/wolf_functor_fast.hh | 15 ++++++++++++++
scribo/scribo/binarization/wolf.hh | 7 +++++-
scribo/scribo/binarization/wolf_fast.hh | 4 +++
scribo/scribo/canvas/integral_browsing.hh | 2 +
14 files changed, 164 insertions(+), 14 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index a58900d..b1e4665 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,24 @@
+2013-03-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Fix an invalid initialization in several binarization algorithms.
+
+ * scribo/binarization/internal/local_threshold_core.hh: Fix doc.
+
+ * scribo/binarization/internal/niblack_functor.hh,
+ * scribo/binarization/internal/niblack_functor_fast.hh,
+ * scribo/binarization/internal/niblack_threshold_functor.hh,
+ * scribo/binarization/internal/sauvola_functor.hh,
+ * scribo/binarization/internal/sauvola_ms_functor.hh,
+ * scribo/binarization/internal/sauvola_threshold_functor.hh,
+ * scribo/binarization/internal/singh_functor.hh,
+ * scribo/binarization/internal/wolf_functor.hh,
+ * scribo/binarization/internal/wolf_functor_fast.hh,
+ * scribo/binarization/wolf.hh,
+ * scribo/binarization/wolf_fast.hh: Add init() member and more
+ assertions.
+
+ * scribo/canvas/integral_browsing.hh: Call init() function.
+
2013-03-19 Guillaume Lazzara <z(a)lrde.epita.fr>
* scribo/debug/links_image.hh: Make use of object_link interface.
diff --git a/scribo/scribo/binarization/internal/local_threshold_core.hh
b/scribo/scribo/binarization/internal/local_threshold_core.hh
index 90f0659..af8d4aa 100644
--- a/scribo/scribo/binarization/internal/local_threshold_core.hh
+++ b/scribo/scribo/binarization/internal/local_threshold_core.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2011, 2012 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2011, 2012, 2013 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -131,9 +131,9 @@ namespace scribo
int integral_scale_ratio = F::step;
- // Make sure the image sizes are a multiple of 3 in each
- // dimension. (browsing while binarizing relies on that
- // property).
+ // Make sure the image sizes are a multiple of
+ // integral_scale_ratio 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,
integral_scale_ratio);
diff --git a/scribo/scribo/binarization/internal/niblack_functor.hh
b/scribo/scribo/binarization/internal/niblack_functor.hh
index 6c4da98..8c502b7 100644
--- a/scribo/scribo/binarization/internal/niblack_functor.hh
+++ b/scribo/scribo/binarization/internal/niblack_functor.hh
@@ -64,6 +64,8 @@ namespace scribo
niblack_functor(const Image<I>& input, double K);
+ void init();
+
// Run every 4 pixels.
void exec(double mean, double stddev);
@@ -94,8 +96,16 @@ namespace scribo
pi(&input(input.domain().pmin())),
K_(K)
{
- next_line = 2 * input.border();
+ mln_precondition(exact(input).is_valid());
+ }
+ template <typename I>
+ void
+ niblack_functor<I>::init()
+ {
+ // This initialization MUST be done here since input image
+ // borders may have changed!
+ next_line = 2 * input.border();
initialize(output, input);
po = &output(output.domain().pmin());
}
@@ -104,6 +114,8 @@ namespace scribo
void
niblack_functor<I>::exec(double mean, double stddev)
{
+ mln_assertion(input.border() == output.border());
+
double th = formula_(mean, stddev, K_);
*po++ = (*pi++ <= th);
diff --git a/scribo/scribo/binarization/internal/niblack_functor_fast.hh
b/scribo/scribo/binarization/internal/niblack_functor_fast.hh
index fd36756..cfebbeb 100644
--- a/scribo/scribo/binarization/internal/niblack_functor_fast.hh
+++ b/scribo/scribo/binarization/internal/niblack_functor_fast.hh
@@ -65,6 +65,8 @@ namespace scribo
// values.
enum { step = 3 };
+ void init();
+
// Run every 4 pixels.
void exec(double mean, double stddev);
@@ -97,6 +99,16 @@ namespace scribo
pi(&input(input.domain().pmin())),
K_(K)
{
+ mln_precondition(exact(input).is_valid());
+ }
+
+ template <typename I>
+ void
+ niblack_functor_fast<I>::init()
+ {
+ // This initialization MUST be done here since input image
+ // borders may have changed!
+
// Since we iterate from a smaller image in the largest ones
// and image at scale 1 does not always have a size which can
// be divided by 3, some sites in the border may not be
diff --git a/scribo/scribo/binarization/internal/niblack_threshold_functor.hh
b/scribo/scribo/binarization/internal/niblack_threshold_functor.hh
index d2f82c9..fab5f7b 100644
--- a/scribo/scribo/binarization/internal/niblack_threshold_functor.hh
+++ b/scribo/scribo/binarization/internal/niblack_threshold_functor.hh
@@ -94,9 +94,16 @@ namespace scribo
double K)
: K_(K)
{
- const I& input = exact(input_);
- mln_precondition(input.is_valid());
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(K > 0.);
+ }
+ template <typename I>
+ void
+ niblack_threshold_functor<I>::init()
+ {
+ // This initialization MUST be done here since input image
+ // borders may have changed!
next_line3 = input.delta_offset(dpoint2d(+2,0)) + 2 * input.border() - 1;
offset1 = input.delta_offset(dpoint2d(+1,0));
@@ -110,6 +117,7 @@ namespace scribo
void
niblack_threshold_functor<I>::exec(double mean, double stddev)
{
+ mln_assertion(input.border() == output.border());
static point2d p(0,0);
typedef mln_value(I) V;
diff --git a/scribo/scribo/binarization/internal/sauvola_functor.hh
b/scribo/scribo/binarization/internal/sauvola_functor.hh
index 613b3e5..4aca8ca 100644
--- a/scribo/scribo/binarization/internal/sauvola_functor.hh
+++ b/scribo/scribo/binarization/internal/sauvola_functor.hh
@@ -65,6 +65,8 @@ namespace scribo
sauvola_functor(const Image<I>& input, double K, double R);
+ void init();
+
// Run every 4 pixels.
void exec(double mean, double stddev);
@@ -99,6 +101,19 @@ namespace scribo
K_(K),
R_(R)
{
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(K > 0.);
+ mln_precondition(R > 0.);
+ }
+
+
+ template <typename I>
+ void
+ sauvola_functor<I>::init()
+ {
+ // This initialization MUST be done here since input image
+ // borders may have changed!
+
// Since we iterate from a smaller image in the largest ones
// and image at scale 1 does not always have a size which can
// be divided by 3, some sites in the border may not be
@@ -117,10 +132,13 @@ namespace scribo
po = &output(output.domain().pmin());
}
+
template <typename I>
void
sauvola_functor<I>::exec(double mean, double stddev)
{
+ mln_assertion(input.border() == output.border());
+
double th = formula_(mean, stddev, K_, R_);
for (int i = 0; i < step; ++i, ++po, ++pi)
diff --git a/scribo/scribo/binarization/internal/sauvola_ms_functor.hh
b/scribo/scribo/binarization/internal/sauvola_ms_functor.hh
index 84a205c..10733ab 100644
--- a/scribo/scribo/binarization/internal/sauvola_ms_functor.hh
+++ b/scribo/scribo/binarization/internal/sauvola_ms_functor.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010, 2011, 2012 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2009, 2010, 2011, 2012, 2013 EPITA Research and
+// Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -95,6 +95,7 @@ namespace scribo
const image2d<value::int_u8>&e_2,
unsigned i, unsigned q);
+ void init();
void exec(double mean, double stddev);
void end_of_row(int row);
void finalize();
@@ -137,6 +138,12 @@ namespace scribo
R_(R),
i_(i)
{
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(R > 0.);
+ mln_precondition(e_2.is_valid());
+ mln_precondition(q > 0);
+ mln_precondition(i > 1);
+
res = 0;
pxl.start();
@@ -170,6 +177,13 @@ namespace scribo
template <typename I>
void
+ sauvola_ms_functor<I>::init()
+ {
+ }
+
+
+ template <typename I>
+ void
sauvola_ms_functor<I>::exec(double mean, double stddev)
{
mln_precondition(pxl.is_valid());
diff --git a/scribo/scribo/binarization/internal/sauvola_threshold_functor.hh
b/scribo/scribo/binarization/internal/sauvola_threshold_functor.hh
index fd5eac8..19b7bf3 100644
--- a/scribo/scribo/binarization/internal/sauvola_threshold_functor.hh
+++ b/scribo/scribo/binarization/internal/sauvola_threshold_functor.hh
@@ -66,6 +66,8 @@ namespace scribo
sauvola_threshold_functor(const Image<I>& input,
double K, double R);
+ init();
+
// Run every 4 pixels.
void exec(double mean, double stddev);
@@ -96,8 +98,17 @@ namespace scribo
: K_(K),
R_(R)
{
- const I& input = exact(input_);
- mln_precondition(input.is_valid());
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(K > 0.);
+ mln_precondition(R > 0.);
+ }
+
+ template <typename I>
+ void
+ sauvola_threshold_functor<I>::init()
+ {
+ // This initialization MUST be done here since input image
+ // borders may have changed!
next_line3 = input.delta_offset(dpoint2d(+2,0)) + 2 * input.border() - 1;
@@ -112,6 +123,7 @@ namespace scribo
void
sauvola_threshold_functor<I>::exec(double mean, double stddev)
{
+ mln_assertion(input.border() == output.border());
static point2d p(0,0);
typedef mln_value(I) V;
diff --git a/scribo/scribo/binarization/internal/singh_functor.hh
b/scribo/scribo/binarization/internal/singh_functor.hh
index fb8f525..8a93c44 100644
--- a/scribo/scribo/binarization/internal/singh_functor.hh
+++ b/scribo/scribo/binarization/internal/singh_functor.hh
@@ -98,6 +98,17 @@ namespace scribo
pi(&input(input.domain().pmin())),
K_(K)
{
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(K > 0.);
+ }
+
+ template <typename I>
+ void
+ niblack_functor<I>::init()
+ {
+ // This initialization MUST be done here since input image
+ // borders may have changed!
+
// Since we iterate from a smaller image in the largest ones
// and image at scale 1 does not always have a size which can
// be divided by 3, some sites in the border may not be
@@ -120,6 +131,7 @@ namespace scribo
void
singh_functor<I>::exec(double mean, double stddev)
{
+ mln_precondition(input.border() == output.border());
(void) stddev;
diff --git a/scribo/scribo/binarization/internal/wolf_functor.hh
b/scribo/scribo/binarization/internal/wolf_functor.hh
index 399b92a..f7947b4 100644
--- a/scribo/scribo/binarization/internal/wolf_functor.hh
+++ b/scribo/scribo/binarization/internal/wolf_functor.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012, 2013 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -68,6 +69,8 @@ namespace scribo
const mln_value(I)& global_min,
double global_max_stddev);
+ void init();
+
// Run every 4 pixels.
void exec(double mean, double stddev);
@@ -105,6 +108,16 @@ namespace scribo
global_min_(global_min),
global_max_stddev_(global_max_stddev)
{
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(K > 0.);
+ }
+
+ template <typename I>
+ void
+ wolf_functor<I>::init()
+ {
+ // This initialization MUST be done here since input image
+ // borders may have changed!
next_line = 2 * input.border();
initialize(output, input);
@@ -115,6 +128,8 @@ namespace scribo
void
wolf_functor<I>::exec(double mean, double stddev)
{
+ mln_assertion(input.border() == output.border());
+
double th = formula_(mean, stddev, K_,
global_max_stddev_, global_min_);
diff --git a/scribo/scribo/binarization/internal/wolf_functor_fast.hh
b/scribo/scribo/binarization/internal/wolf_functor_fast.hh
index a61bead..118157c 100644
--- a/scribo/scribo/binarization/internal/wolf_functor_fast.hh
+++ b/scribo/scribo/binarization/internal/wolf_functor_fast.hh
@@ -69,6 +69,8 @@ namespace scribo
const mln_value(I)& global_min,
double global_max_stddev);
+ void init();
+
// Run every 4 pixels.
void exec(double mean, double stddev);
@@ -108,6 +110,17 @@ namespace scribo
global_min_(global_min),
global_max_stddev_(global_max_stddev)
{
+ mln_precondition(exact(input).is_valid());
+ mln_precondition(K > 0.);
+ }
+
+ template <typename I>
+ void
+ wolf_functor_fast<I>::init()
+ {
+ // This initialization MUST be done here since input image
+ // borders may have changed!
+
// Since we iterate from a smaller image in the largest ones
// and image at scale 1 does not always have a size which can
// be divided by 3, some sites in the border may not be
@@ -130,6 +143,8 @@ namespace scribo
void
wolf_functor_fast<I>::exec(double mean, double stddev)
{
+ mln_assertion(input.border() == output.border());
+
double th = formula_(mean, stddev, K_,
global_max_stddev_, global_min_);
diff --git a/scribo/scribo/binarization/wolf.hh b/scribo/scribo/binarization/wolf.hh
index 376c486..aadf2af 100644
--- a/scribo/scribo/binarization/wolf.hh
+++ b/scribo/scribo/binarization/wolf.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012, 2013 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -99,6 +100,10 @@ namespace scribo
{
}
+ void init()
+ {
+ }
+
// Run every 4 pixels.
void exec(double mean, double stddev)
{
diff --git a/scribo/scribo/binarization/wolf_fast.hh
b/scribo/scribo/binarization/wolf_fast.hh
index 10e9d28..e0cf56d 100644
--- a/scribo/scribo/binarization/wolf_fast.hh
+++ b/scribo/scribo/binarization/wolf_fast.hh
@@ -98,6 +98,10 @@ namespace scribo
{
}
+ void init()
+ {
+ }
+
// Run every 4 pixels.
void exec(double mean, double stddev)
{
diff --git a/scribo/scribo/canvas/integral_browsing.hh
b/scribo/scribo/canvas/integral_browsing.hh
index c554eaf..c293ba9 100644
--- a/scribo/scribo/canvas/integral_browsing.hh
+++ b/scribo/scribo/canvas/integral_browsing.hh
@@ -108,6 +108,8 @@ namespace scribo
" was larger than image width.");
}
+ // Initialization
+ functor.init();
const int
nrows = ima.nrows(),
--
1.7.2.5