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>
Add a new test for object_image.
......
......@@ -61,640 +61,648 @@ namespace scribo
using value::int_u8;
unsigned my_find_root(image2d<unsigned>& parent, unsigned x)
namespace internal
{
if (parent.element(x) == x)
return x;
return parent.element(x) = my_find_root(parent,
parent.element(x));
}
template <typename V>
V my_find_root(image2d<V>& parent, const V& x)
{
if (parent.element(x) == x)
return x;
return parent.element(x) = my_find_root(parent,
parent.element(x));
}
image2d<int_u8>
compute_t_n_and_e_2(const image2d<int_u8>& sub, image2d<int_u8>& e_2,
unsigned lambda_min, unsigned lambda_max,
unsigned s,
unsigned q, unsigned i, unsigned w,
const image2d<util::couple<double,double> >& integral_sum_sum_2)
{
typedef image2d<int_u8> I;
typedef point2d P;
unsigned ratio = std::pow(q, i - 2); // Ratio in comparison to e_2
image2d<int_u8>
compute_t_n_and_e_2(const image2d<int_u8>& sub, image2d<int_u8>& e_2,
unsigned lambda_min, unsigned lambda_max,
unsigned s,
unsigned q, unsigned i, unsigned w,
const image2d<util::couple<double,double> >& integral_sum_sum_2)
{
typedef image2d<int_u8> I;
typedef point2d P;
unsigned
w_local = w * ratio,
w_local_h = w_local,
w_local_w = w_local;
unsigned ratio = std::pow(q, i - 2); // Ratio in comparison to e_2
if (! (w_local % 2))
{
--w_local_w;
++w_local_h;
}
unsigned
w_local = w * ratio,
w_local_h = w_local,
w_local_w = w_local;
// 1st pass
scribo::binarization::internal::first_pass_functor< image2d<int_u8> >
f(sub);
scribo::canvas::integral_browsing(integral_sum_sum_2,
ratio,
w_local_w, w_local_h,
s,
f);
if (! (w_local % 2))
{
--w_local_w;
++w_local_h;
}
// 2nd pass
{
util::array<mln_value_(I) *> ptr(ratio);
unsigned nrows = geom::nrows(e_2);
// 1st pass
scribo::binarization::internal::first_pass_functor< image2d<int_u8> >
f(sub);
scribo::canvas::integral_browsing(integral_sum_sum_2,
ratio,
w_local_w, w_local_h,
s,
f);
mln_box_runend_piter_(I) sp(sub.domain()); // Backward.
unsigned ncols = sp.run_length();
for_all(sp)
// 2nd pass
{
unsigned p = &sub(sp) - sub.buffer(); // Offset
P site = sp;
util::array<mln_value_(I) *> ptr(ratio);
unsigned nrows = geom::nrows(e_2);
mln_box_runend_piter_(I) sp(sub.domain()); // Backward.
unsigned ncols = sp.run_length();
for_all(sp)
{
P tmp = site * ratio;
// FIXME: to be removed!
if (tmp.row() + ratio >= nrows)
ptr.resize(nrows - tmp.row());
unsigned p = &sub(sp) - sub.buffer(); // Offset
P site = sp;
ptr(0) = &e_2(tmp);
// FIXME: pointers could just be updated with an offset.
for (unsigned j = 1; j < ptr.size(); ++j)
{
tmp[0] += 1;
ptr(j) = & e_2(tmp);
}
}
P tmp = site * ratio;
for (unsigned j = 0; j < ncols; ++j)
{
if (f.msk.element(p))
{
// FIXME: to be removed!
if (tmp.row() + ratio >= nrows)
ptr.resize(nrows - tmp.row());
mln_site_(I) sq = site * ratio;
ptr(0) = &e_2(tmp);
// FIXME: pointers could just be updated with an offset.
for (unsigned j = 1; j < ptr.size(); ++j)
{
tmp[0] += 1;
ptr(j) = & e_2(tmp);
}
}
if (f.parent.element(p) == p)
for (unsigned j = 0; j < ncols; ++j)
{
if (f.msk.element(p))
{
// test over the component cardinality
f.msk.element(p) = f.card.element(p) > lambda_min
&& f.card.element(p) < lambda_max;
if (f.msk.element(p) && e_2(sq) == 0u)
mln_site_(I) sq = site * ratio;
if (f.parent.element(p) == p)
{
for (unsigned l = 0; l < ptr.size(); ++l)
std::memset(ptr(l), i, ratio * sizeof(mln_value_(I)));
}
// test over the component cardinality
f.msk.element(p) = f.card.element(p) > lambda_min
&& f.card.element(p) < lambda_max;
}
else
{
// Propagation
f.msk.element(p) = f.msk.element(f.parent.element(p));
if (f.msk.element(p) && e_2(sq) == 0u)
{
for (unsigned l = 0; l < ptr.size(); ++l)
std::memset(ptr(l), i, ratio * sizeof(mln_value_(I)));
}
if (f.msk.element(p) && e_2(sq) == 0u)
{
for (unsigned l = 0; l < ptr.size(); ++l)
std::memset(ptr(l), i, ratio * sizeof(mln_value_(I)));
}
else
{
// Propagation
f.msk.element(p) = f.msk.element(f.parent.element(p));
if (f.msk.element(p) && e_2(sq) == 0u)
{
for (unsigned l = 0; l < ptr.size(); ++l)
std::memset(ptr(l), i, ratio * sizeof(mln_value_(I)));
}
}
}
}
for (unsigned l = 0; l < ptr.size(); ++l)
ptr(l) -= ratio;
for (unsigned l = 0; l < ptr.size(); ++l)
ptr(l) -= ratio;
--site[1];
--p;
}
--site[1];
--p;
}
}
} // end of 2nd pass
}
} // end of 2nd pass
return f.t_sub;
}
return f.t_sub;
}
template <typename I, typename J, typename K>
mln_ch_value(I, bool)
multi_scale_binarization(const I& in, const J& e2,
const util::array<K>& t_ima,
unsigned s)
{
mln_ch_value(I,bool) out;
initialize(out, in);
template <typename I, typename J, typename K>
mln_ch_value(I, bool)
multi_scale_binarization(const I& in, const J& e2,
const util::array<K>& t_ima,
unsigned s)
{
mln_ch_value(I,bool) out;
initialize(out, in);
typedef const mln_value(K)* ptr_type;
typedef const mln_value(K)* ptr_type;
ptr_type ptr_t[5];
ptr_t[2] = & t_ima[2].at_(0, 0);
ptr_t[3] = & t_ima[3].at_(0, 0);
ptr_t[4] = & t_ima[4].at_(0, 0);
ptr_type ptr_t[5];
ptr_t[2] = & t_ima[2].at_(0, 0);
ptr_t[3] = & t_ima[3].at_(0, 0);
ptr_t[4] = & t_ima[4].at_(0, 0);
const mln_value(J)* ptr_e2 = & e2.at_(0, 0);
const mln_value(I)* ptr__in = & in.at_(0, 0);
bool* ptr__out = & out.at_(0, 0);
const mln_value(J)* ptr_e2 = & e2.at_(0, 0);
const mln_value(I)* ptr__in = & in.at_(0, 0);
bool* ptr__out = & out.at_(0, 0);
// 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 (4*s), some sites in the border may not be processed
// and we must skip them.
int more_offset = - ((4 * s) - in.ncols() % (4 * s));
// 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 (4*s), some sites in the border may not be processed
// and we must skip them.
int more_offset = - ((4 * s) - in.ncols() % (4 * s));
if (more_offset == - (static_cast<int>(4*s)))
more_offset = 0; // No offset needed.
if (more_offset == - (static_cast<int>(4*s)))
more_offset = 0; // No offset needed.
const int
nrows4 = t_ima[4].nrows(), ncols4 = t_ima[4].ncols(),
const int
nrows4 = t_ima[4].nrows(), ncols4 = t_ima[4].ncols(),
delta1 = in.delta_index(dpoint2d(+1, -(s - 1))),
delta1b = in.delta_index(dpoint2d(+1, -(s + s - 1))),
delta1c = in.delta_index(dpoint2d(-(s + s - 1), +1)),
delta1d = in.delta_index(dpoint2d(+1, -(s * 4 - 1))),
delta1e = in.delta_index(dpoint2d(-(s * 4 - 1), +1)),
delta1f = in.delta_index(dpoint2d(-(s - 1), +1)),
delta1 = in.delta_index(dpoint2d(+1, -(s - 1))),
delta1b = in.delta_index(dpoint2d(+1, -(s + s - 1))),
delta1c = in.delta_index(dpoint2d(-(s + s - 1), +1)),
delta1d = in.delta_index(dpoint2d(+1, -(s * 4 - 1))),
delta1e = in.delta_index(dpoint2d(-(s * 4 - 1), +1)),
delta1f = in.delta_index(dpoint2d(-(s - 1), +1)),
delta2 = t_ima[2].delta_index(dpoint2d(+1, -1)),
delta2b = t_ima[2].delta_index(dpoint2d(+1, -3)),
delta2c = t_ima[2].delta_index(dpoint2d(-3, +1)),
delta2 = t_ima[2].delta_index(dpoint2d(+1, -1)),
delta2b = t_ima[2].delta_index(dpoint2d(+1, -3)),
delta2c = t_ima[2].delta_index(dpoint2d(-3, +1)),
delta3 = t_ima[3].delta_index(dpoint2d(+1, -1)),
delta3 = t_ima[3].delta_index(dpoint2d(+1, -1)),
eor1 = in.delta_index(dpoint2d(+4 * s, - in.ncols())) + more_offset,
eor2 = t_ima[2].delta_index(dpoint2d(+4,- t_ima[2].ncols())),
eor3 = t_ima[3].delta_index(dpoint2d(+2,- t_ima[3].ncols())),
eor4 = t_ima[4].delta_index(dpoint2d(+1,- t_ima[4].ncols()));
eor1 = in.delta_index(dpoint2d(+4 * s, - in.ncols())) + more_offset,
eor2 = t_ima[2].delta_index(dpoint2d(+4,- t_ima[2].ncols())),
eor3 = t_ima[3].delta_index(dpoint2d(+2,- t_ima[3].ncols())),
eor4 = t_ima[4].delta_index(dpoint2d(+1,- t_ima[4].ncols()));
mln_value(J) threshold;
for (int row4 = 0; row4 < nrows4; ++row4)
{
for (int col4 = 0; col4 < ncols4; ++col4)
mln_value(J) threshold;
for (int row4 = 0; row4 < nrows4; ++row4)
{
// top left 1
for (int col4 = 0; col4 < ncols4; ++col4)
{
threshold = *ptr_t[*ptr_e2];
// top left 1
{
for (unsigned i = 1; i < s; ++i)
threshold = *ptr_t[*ptr_e2];
{
for (unsigned j = 1; j < s; ++j)
for (unsigned i = 1; i < s; ++i)
{
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
ptr__out += delta1; ptr__in += delta1;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
}
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1f; ptr__in += delta1f;
}
++ptr_t[2]; ++ptr_e2;
threshold = *ptr_t[*ptr_e2];
{
for (unsigned i = 1; i < s; ++i)
{
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
ptr__out += delta1f; ptr__in += delta1f;
}
for (unsigned j = 1; j < s; ++j)
++ptr_t[2]; ++ptr_e2;
threshold = *ptr_t[*ptr_e2];
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1b; ptr__in += delta1b;
}
for (unsigned i = 1; i < s; ++i)
{
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
}
ptr_t[2] += delta2; ptr_e2 += delta2;
threshold = *ptr_t[*ptr_e2];
{
for (unsigned i = 1; i < s; ++i)
{
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
ptr__out += delta1b; ptr__in += delta1b;
}
for (unsigned j = 1; j < s; ++j)
ptr_t[2] += delta2; ptr_e2 += delta2;
threshold = *ptr_t[*ptr_e2];
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1f; ptr__in += delta1f;
for (unsigned i = 1; i < s; ++i)
{
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
}
++ptr_t[2]; ++ptr_e2;
threshold = *ptr_t[*ptr_e2];
{
for (unsigned i = 1; i < s; ++i)
{
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
ptr__out += delta1f; ptr__in += delta1f;
}
for (unsigned j = 1; j < s; ++j)
++ptr_t[2]; ++ptr_e2;
threshold = *ptr_t[*ptr_e2];
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1c; ptr__in += delta1c;
}
for (unsigned i = 1; i < s; ++i)
{
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
ptr_t[2] -= delta2; ptr_e2 -= delta2;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
}
// top right 1
ptr_t[3] += 1;
{
threshold = *ptr_t[*ptr_e2];
{
for (unsigned i = 1; i < s; ++i)
{
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
ptr__out += delta1c; ptr__in += delta1c;
}
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1f; ptr__in += delta1f;
ptr_t[2] -= delta2; ptr_e2 -= delta2;
}
++ptr_t[2]; ++ptr_e2;
threshold = *ptr_t[*ptr_e2];
// top right 1
ptr_t[3] += 1;
{
for (unsigned i = 1; i < s; ++i)
threshold = *ptr_t[*ptr_e2];
{
for (unsigned i = 1; i < s; ++i)
{
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
}
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
ptr__out += delta1f; ptr__in += delta1f;
}
for (unsigned j = 1; j < s; ++j)
++ptr_t[2]; ++ptr_e2;
threshold = *ptr_t[*ptr_e2];
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1b; ptr__in += delta1b;
}
for (unsigned i = 1; i < s; ++i)
{
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
}
ptr_t[2] += delta2; ptr_e2 += delta2;
threshold = *ptr_t[*ptr_e2];
{
for (unsigned i = 1; i < s; ++i)
{
for (unsigned j = 1; j < s; ++j)
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}
*ptr__out = *ptr__in < threshold;
ptr__out += delta1; ptr__in += delta1;
ptr__out += delta1b; ptr__in += delta1b;
}
for (unsigned j = 1; j < s; ++j)
ptr_t[2] += delta2; ptr_e2 += delta2;
threshold = *ptr_t[*ptr_e2];
{
*ptr__out = *ptr__in < threshold;
++ptr__out; ++ptr__in;
}