Commit ca034dd5 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Cleanup and avoid warnings in Sauvola related files.

	* scribo/binarization/sauvola_ms.hh,
	* scribo/binarization/sauvola_threshold.hh,
	* scribo/canvas/integral_browsing.hh,
	* scribo/src/binarization/sauvola_ms.cc,
	* scribo/src/binarization/sauvola_pgm.cc,x
	* scribo/subsampling/integral_single_image.hh: Cleanup and avoir
	warnings.
parent 7c60810a
2010-02-19 Guillaume Lazzara <z@lrde.epita.fr>
Cleanup and avoid warnings in Sauvola related files.
* scribo/binarization/sauvola_ms.hh,
* scribo/binarization/sauvola_threshold.hh,
* scribo/canvas/integral_browsing.hh,
* scribo/src/binarization/sauvola_ms.cc,
* scribo/src/binarization/sauvola_pgm.cc,x
* scribo/subsampling/integral_single_image.hh: Cleanup and avoir
warnings.
2009-12-15 Guillaume Lazzara <z@lrde.epita.fr> 2009-12-15 Guillaume Lazzara <z@lrde.epita.fr>
Add a new test for object_image. Add a new test for object_image.
......
...@@ -61,7 +61,11 @@ namespace scribo ...@@ -61,7 +61,11 @@ namespace scribo
using value::int_u8; using value::int_u8;
unsigned my_find_root(image2d<unsigned>& parent, unsigned x) namespace internal
{
template <typename V>
V my_find_root(image2d<V>& parent, const V& x)
{ {
if (parent.element(x) == x) if (parent.element(x) == x)
return x; return x;
...@@ -696,6 +700,10 @@ namespace scribo ...@@ -696,6 +700,10 @@ namespace scribo
return out; return out;
} }
} // end of namespace scribo::binarization::internal
template <typename I> template <typename I>
mln_ch_value(I,bool) mln_ch_value(I,bool)
sauvola_ms(const Image<I>& input_1_, unsigned w_1, sauvola_ms(const Image<I>& input_1_, unsigned w_1,
...@@ -743,7 +751,7 @@ namespace scribo ...@@ -743,7 +751,7 @@ namespace scribo
} }
util::array<util::couple<box2d, unsigned> > util::array<util::couple<box2d, unsigned> >
sub_domains = compute_sub_domains(input_1, nb_subscale, s); sub_domains = internal::compute_sub_domains(input_1, nb_subscale, s);
border::adjust(input_1, sub_domains(1).second()); border::adjust(input_1, sub_domains(1).second());
border::mirror(input_1); border::mirror(input_1);
...@@ -776,11 +784,12 @@ namespace scribo ...@@ -776,11 +784,12 @@ namespace scribo
{ {
int i = sub_ima.size() - 1; int i = sub_ima.size() - 1;
unsigned ratio = std::pow(q, i - 2); // Ratio compared to e_2 unsigned ratio = std::pow(q, i - 2); // Ratio compared to e_2
t_ima[i] = compute_t_n_and_e_2(sub_ima[i], e_2, t_ima[i] = internal::compute_t_n_and_e_2(sub_ima[i], e_2,
lambda_min_2 / ratio, lambda_min_2 / ratio,
mln_max(unsigned), mln_max(unsigned),
s, s,
q, i, w_work, integral_sum_sum_2); q, i, w_work,
integral_sum_sum_2);
} }
// Other scales -> maximum and minimum component size. // Other scales -> maximum and minimum component size.
...@@ -788,18 +797,21 @@ namespace scribo ...@@ -788,18 +797,21 @@ namespace scribo
for (int i = sub_ima.size() - 2; i > 2; --i) for (int i = sub_ima.size() - 2; i > 2; --i)
{ {
unsigned ratio = std::pow(q, i - 2); // Ratio compared to e_2 unsigned ratio = std::pow(q, i - 2); // Ratio compared to e_2
t_ima[i] = compute_t_n_and_e_2(sub_ima[i], e_2, t_ima[i] = internal::compute_t_n_and_e_2(sub_ima[i], e_2,
lambda_min_2 / ratio, lambda_min_2 / ratio,
lambda_max_2 / ratio, lambda_max_2 / ratio,
s, s,
q, i, w_work, integral_sum_sum_2); q, i, w_work,
integral_sum_sum_2);
} }
} }
// Lowest scale -> no minimum component size. // Lowest scale -> no minimum component size.
{ {
t_ima[2] = compute_t_n_and_e_2(sub_ima[2], e_2, 0, lambda_max_2, t_ima[2] = internal::compute_t_n_and_e_2(sub_ima[2], e_2, 0,
s, 1, 2, w_work, integral_sum_sum_2); lambda_max_2,
s, 1, 2, w_work,
integral_sum_sum_2);
} }
...@@ -808,7 +820,8 @@ namespace scribo ...@@ -808,7 +820,8 @@ namespace scribo
// Binarize // Binarize
image2d<bool> output = multi_scale_binarization(input_1, e_2, t_ima, s); image2d<bool>
output = internal::multi_scale_binarization(input_1, e_2, t_ima, s);
trace::exiting("scribo::binarization::sauvola_ms"); trace::exiting("scribo::binarization::sauvola_ms");
return output; return output;
......
...@@ -48,9 +48,6 @@ ...@@ -48,9 +48,6 @@
# include <scribo/core/init_integral_image.hh> # include <scribo/core/init_integral_image.hh>
#include <mln/io/pgm/save.hh>
namespace scribo namespace scribo
{ {
...@@ -476,8 +473,6 @@ namespace scribo ...@@ -476,8 +473,6 @@ namespace scribo
exact(simple), exact(simple),
exact(squared)); exact(squared));
// std::cout << std::endl << " ------- " << std::endl;
io::pgm::save(output, "ref_2_t.pgm");
trace::exiting("scribo::text::ppm2pbm"); trace::exiting("scribo::text::ppm2pbm");
return output; return output;
} }
......
...@@ -63,7 +63,11 @@ namespace scribo ...@@ -63,7 +63,11 @@ namespace scribo
// std::cout << "(" << mean << " - " << stddev << " - " << n << "),"; // std::cout << "(" << mean << " - " << stddev << " - " << n << "),";
// unbias version: // unbias version:
stddev = std::sqrt((sum_2 - sum * sum / n) / (n - 1)); double num = (sum_2 - sum * sum / n);
if (num > 0)
stddev = std::sqrt(num / (n - 1));
else
stddev = 0;
} }
...@@ -83,18 +87,21 @@ namespace scribo ...@@ -83,18 +87,21 @@ namespace scribo
typedef const V* Ptr; typedef const V* Ptr;
Ptr a_ima, b_ima, c_ima, d_ima; Ptr a_ima, b_ima, c_ima, d_ima;
const unsigned // mln_precondition((h/2) < ima.nrows());
// mln_precondition((w/2) < ima.ncols());
const int
nrows = ima.nrows(), nrows = ima.nrows(),
ncols = ima.ncols(), ncols = ima.ncols(),
row_0 = step / 2, row_0 = step / 2,
col_0 = step / 2; col_0 = step / 2;
const unsigned const int
offset_down = ima.delta_index(dpoint2d(step, 0)), offset_down = ima.delta_index(dpoint2d(step, 0)),
offset_ante = ima.delta_index(dpoint2d(0, -w)), offset_ante = ima.delta_index(dpoint2d(0, -w)),
offset_below = ima.delta_index(dpoint2d(+h, 0)); offset_below = ima.delta_index(dpoint2d(+h, 0));
const unsigned const int
max_row_top = h/2, max_row_top = h/2,
max_row_mid = nrows - 1 - h/2, max_row_mid = nrows - 1 - h/2,
max_col_left = w/2, max_col_left = w/2,
...@@ -105,10 +112,11 @@ namespace scribo ...@@ -105,10 +112,11 @@ namespace scribo
h_top = row_0 + h/2 + 1, h_top = row_0 + h/2 + 1,
w_left = col_0 + w/2 + 1; w_left = col_0 + w/2 + 1;
unsigned row, col;
int row, col;
for (col = col_0; col <= max_col_mid; col += step) ; for (col = col_0; col <= max_col_mid; col += step) ;
unsigned w_right = ncols - col + w/2; int w_right = ncols - col + w/2;
Ptr Ptr
d_tl_start, d_tr_start, d_tl_start, d_tr_start,
...@@ -119,6 +127,18 @@ namespace scribo ...@@ -119,6 +127,18 @@ namespace scribo
unsigned s_2 = s * s; unsigned s_2 = s * s;
// Make sure the window fits in the image domain.
if (w >= static_cast<const unsigned>(ncols))
{
w = ncols - 1;
trace::warning("integral_browsing - Adjusting window width since it was larger than image width.");
}
if (h >= static_cast<const unsigned>(nrows))
{
h = nrows - 1;
trace::warning("integral_browsing - Adjusting window height since it was larger than image height.");
}
// ------------------------------- // -------------------------------
// T (top) // T (top)
...@@ -128,7 +148,7 @@ namespace scribo ...@@ -128,7 +148,7 @@ namespace scribo
delta_start_left = step * w_left, delta_start_left = step * w_left,
delta_start_right = step * w_right, delta_start_right = step * w_right,
step_w = step * w; step_w = step * w;
unsigned int
size_tl_start = h_top * w_left, size_tl_start = h_top * w_left,
size_tl, size_tl,
delta_size_tl = h_top * step, delta_size_tl = h_top * step,
...@@ -209,7 +229,6 @@ namespace scribo ...@@ -209,7 +229,6 @@ namespace scribo
} }
// ------------------------------- // -------------------------------
// (M) middle // (M) middle
// ------------------------------- // -------------------------------
...@@ -266,25 +285,6 @@ namespace scribo ...@@ -266,25 +285,6 @@ namespace scribo
{ {
// D + A - B - C // D + A - B - C
// if (row == 3 && col == 3)
// std::cout << "p(" << row << "," << col << ") - "
// << "A" << ima.point_at_index(a_ima - ima.buffer())
// << "=" << a_ima->first() << " - "
// << "B" << ima.point_at_index(b_ima - ima.buffer())
// << "=" << b_ima->first() << " - "
// << "C" << ima.point_at_index(c_ima - ima.buffer())
// << "=" << c_ima->first() << " - "
// << "D" << ima.point_at_index(d_ima - ima.buffer())
// << "=" << d_ima->first() << " - "
// << "n =" << size_mc << " - "
// << "n*s_2 =" << size_mc * s_2
// << std::endl;
internal::compute_stats((d_ima->first() - b_ima->first()) + (a_ima->first() - c_ima->first()), internal::compute_stats((d_ima->first() - b_ima->first()) + (a_ima->first() - c_ima->first()),
(d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second()), (d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second()),
size_mc * s_2, size_mc * s_2,
...@@ -292,13 +292,6 @@ namespace scribo ...@@ -292,13 +292,6 @@ namespace scribo
functor.exec(mean, stddev); functor.exec(mean, stddev);
// std::cout << " - " << mean
// << " - " << stddev
// << " - " << (d_ima->first() - b_ima->first()) + (a_ima->first() - c_ima->first())
// << " - " << (d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second())
// << std::endl;
a_ima += step; a_ima += step;
b_ima += step; b_ima += step;
c_ima += step; c_ima += step;
...@@ -332,7 +325,6 @@ namespace scribo ...@@ -332,7 +325,6 @@ namespace scribo
} }
// ------------------------------- // -------------------------------
// B (bottom) // B (bottom)
// ------------------------------- // -------------------------------
...@@ -342,6 +334,7 @@ namespace scribo ...@@ -342,6 +334,7 @@ namespace scribo
size_bl, size_bl,
delta_size_bl = (nrows - row + h/2) * step, delta_size_bl = (nrows - row + h/2) * step,
size_bc = (nrows - row + h/2) * w, size_bc = (nrows - row + h/2) * w,
size_br_start = (nrows - row + h/2) * w_right, size_br_start = (nrows - row + h/2) * w_right,
delta_size_br = (nrows - row + h/2) * step, delta_size_br = (nrows - row + h/2) * step,
size_br; size_br;
...@@ -392,12 +385,6 @@ namespace scribo ...@@ -392,12 +385,6 @@ namespace scribo
(d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second()), (d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second()),
size_bc * s_2, size_bc * s_2,
mean, stddev); mean, stddev);
// std::cout << (d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second()) << std::endl;
// std::cout << d_ima->second() << " - " << b_ima->second() << " - "
// << a_ima->second() << " - " << c_ima->second() << std::endl;
// std::cout << d_ima->first() << " - " << b_ima->first() << " - "
// << a_ima->first() << " - " << c_ima->first() << std::endl;
functor.exec(mean, stddev); functor.exec(mean, stddev);
a_ima += step; a_ima += step;
b_ima += step; b_ima += step;
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
#include <scribo/binarization/sauvola_ms.hh> #include <scribo/binarization/sauvola_ms.hh>
#include <scribo/debug/usage.hh> #include <scribo/debug/usage.hh>
bool check_args(int argc, char * argv[]) bool check_args(int argc, char * argv[])
{ {
if (argc < 5 || argc > 6) if (argc < 5 || argc > 6)
...@@ -88,21 +87,20 @@ int main(int argc, char *argv[]) ...@@ -88,21 +87,20 @@ int main(int argc, char *argv[])
image2d<value::int_u8> input_1; image2d<value::int_u8> input_1;
io::pgm::load(input_1, argv[1]); io::pgm::load(input_1, argv[1]);
{ // {
unsigned max_dim = math::max(input_1.ncols(), // unsigned max_dim = math::min(input_1.ncols() / s,
input_1.nrows()); // input_1.nrows() / s);
if (w_1 > max_dim) // if ((w_1 / s * 4) > max_dim)
{ // {
std::cout << "------------------" << std::endl; // std::cout << "------------------" << std::endl;
std::cout << "The window is too large! Image size is only " // std::cout << "The window is too large! Image size is only "
<< input_1.nrows() << "x" << input_1.ncols() // << input_1.nrows() << "x" << input_1.ncols()
<< std::endl // << std::endl
<< "Window size must not exceed " << max_dim // << "Window size must not exceed " << max_dim * s / 4
<< std::endl; // << std::endl;
return 1; // return 1;
} // }
} // }
image2d<bool> image2d<bool>
output = scribo::binarization::sauvola_ms(input_1, w_1, s, lambda_min_1); output = scribo::binarization::sauvola_ms(input_1, w_1, s, lambda_min_1);
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <scribo/binarization/sauvola.hh> #include <scribo/binarization/sauvola.hh>
#include <scribo/debug/usage.hh> #include <scribo/debug/usage.hh>
#include <mln/util/timer.hh>
const char *args_desc[][2] = const char *args_desc[][2] =
{ {
...@@ -56,7 +57,14 @@ int main(int argc, char *argv[]) ...@@ -56,7 +57,14 @@ int main(int argc, char *argv[])
image2d<int_u8> input; image2d<int_u8> input;
io::pgm::load(input, argv[1]); io::pgm::load(input, argv[1]);
io::pbm::save(scribo::binarization::sauvola(input, w), argv[3]); util::timer t;
t.start();
image2d<bool> out = scribo::binarization::sauvola(input, w);
t.stop();
std::cout << t << std::endl;
io::pbm::save(out, argv[3]);
trace::exiting("main"); trace::exiting("main");
......
...@@ -123,7 +123,7 @@ namespace scribo ...@@ -123,7 +123,7 @@ namespace scribo
integral_sum_sum_2.init_(output_domain, border_thickness); integral_sum_sum_2.init_(output_domain, border_thickness);
V2* p_integ = integral_sum_sum_2.buffer(); V2* p_integ = integral_sum_sum_2.buffer();
const unsigned up = sub.delta_index(dpoint2d(-1, 0)); const int up = sub.delta_index(dpoint2d(-1, 0));
const unsigned nrows = 3 * output_domain.nrows(); const unsigned nrows = 3 * output_domain.nrows();
const unsigned ncols = 3 * output_domain.ncols(); const unsigned ncols = 3 * output_domain.ncols();
...@@ -242,7 +242,7 @@ namespace scribo ...@@ -242,7 +242,7 @@ namespace scribo
integral_sum_sum_2.init_(output_domain, border_thickness); integral_sum_sum_2.init_(output_domain, border_thickness);
V2* p_integ = integral_sum_sum_2.buffer(); V2* p_integ = integral_sum_sum_2.buffer();
const unsigned up = sub.delta_index(dpoint2d(-1, 0)); const int up = sub.delta_index(dpoint2d(-1, 0));
const unsigned nrows = 2 * output_domain.nrows(); const unsigned nrows = 2 * output_domain.nrows();
const unsigned ncols = 2 * output_domain.ncols(); const unsigned ncols = 2 * output_domain.ncols();
......
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