Commit 9a540a39 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

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.
parent c621ab07
2013-03-20 Guillaume Lazzara <z@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@lrde.epita.fr>
* scribo/debug/links_image.hh: Make use of object_link interface.
......
// 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);
......
......@@ -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);
......
......@@ -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
......
......@@ -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;
......
......@@ -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)
......
// 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();
......@@ -168,6 +175,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)
......
......@@ -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;
......
......@@ -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;
......
// 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_);
......
......@@ -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_);
......
// 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)
{
......
......@@ -98,6 +98,10 @@ namespace scribo
{
}
void init()
{
}
// Run every 4 pixels.
void exec(double mean, double stddev)
{
......
......@@ -108,6 +108,8 @@ namespace scribo
" was larger than image width.");
}
// Initialization
functor.init();
const int
nrows = ima.nrows(),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment