---
.../{pgm_color_diff.cc => pbm_color_diff.cc} | 17 +++--
scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc | 2 +-
.../binarization/internal/local_threshold_debug.hh | 3 +
.../binarization/internal/sauvola_ms_functor.hh | 55 ++++++++++++++++-
scribo/scribo/binarization/sauvola_ms.hh | 63 +++++++++++++++++---
scribo/src/binarization/sauvola_ms_debug.cc | 1 +
6 files changed, 122 insertions(+), 19 deletions(-)
copy scribo/sandbox/z/sauvola_ms_rv/{pgm_color_diff.cc => pbm_color_diff.cc} (72%)
diff --git a/scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc
b/scribo/sandbox/z/sauvola_ms_rv/pbm_color_diff.cc
similarity index 72%
copy from scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc
copy to scribo/sandbox/z/sauvola_ms_rv/pbm_color_diff.cc
index 7474c46..b49f40b 100644
--- a/scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc
+++ b/scribo/sandbox/z/sauvola_ms_rv/pbm_color_diff.cc
@@ -2,10 +2,11 @@
#include <mln/core/image/image2d.hh>
#include <mln/value/rgb8.hh>
#include <mln/value/int_u8.hh>
-#include <mln/io/pgm/load.hh>
+#include <mln/io/pbm/load.hh>
#include <mln/io/ppm/save.hh>
#include <mln/data/transform.hh>
#include <mln/arith/minus.hh>
+#include <mln/data/convert.hh>
namespace mln
{
@@ -21,7 +22,7 @@ namespace mln
int v_d2 = std::abs(v / 2);
if (v >= -threshold_ && v <= threshold_)
- return value::rgb8(255, 255, 255);
+ return value::rgb8(0, 0, 0);
else if (v > threshold_)
return value::rgb8(v_d2, 128 + v_d2, v_d2);
else
@@ -42,16 +43,18 @@ int main(int argc, char *argv[])
if (argc != 5)
{
- std::cout << "Usage: " << argv[0] << " in.pgm
ref.pgm threshold out.ppm" << std::endl;
+ std::cout << "Usage: " << argv[0] << " in.pbm
ref.pbm threshold out.ppm" << std::endl;
return 1;
}
- image2d<value::int_u8> input, ref;
+ image2d<bool> input, ref;
- io::pgm::load(input, argv[1]);
- io::pgm::load(ref, argv[2]);
+ io::pbm::load(input, argv[1]);
+ io::pbm::load(ref, argv[2]);
- image2d<int> diff = input - ref;
+ image2d<int>
+ diff = data::convert(value::int_u8(), input)
+ - data::convert(value::int_u8(), ref);
color_diff f(atoi(argv[3]));
image2d<value::rgb8> result = data::transform(diff, f);
diff --git a/scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc
b/scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc
index 7474c46..d9c677a 100644
--- a/scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc
+++ b/scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc
@@ -21,7 +21,7 @@ namespace mln
int v_d2 = std::abs(v / 2);
if (v >= -threshold_ && v <= threshold_)
- return value::rgb8(255, 255, 255);
+ return value::rgb8(0, 0, 0);
else if (v > threshold_)
return value::rgb8(v_d2, 128 + v_d2, v_d2);
else
diff --git a/scribo/scribo/binarization/internal/local_threshold_debug.hh
b/scribo/scribo/binarization/internal/local_threshold_debug.hh
index 6b2263f..46503f6 100644
--- a/scribo/scribo/binarization/internal/local_threshold_debug.hh
+++ b/scribo/scribo/binarization/internal/local_threshold_debug.hh
@@ -56,6 +56,7 @@ namespace scribo
const char* mean_image_output = 0;
const char* threshold_image_output = 0;
const char* full_threshold_image_output = 0;
+ const char * scale_proba_output = 0;
const char* scale_image_output = 0;
const char* scale_iz_image_output = 0;
@@ -68,6 +69,8 @@ namespace scribo
image2d<double> debug_mean;
image2d<double> debug_threshold;
+ image3d<double> debug_scale_proba;
+
image2d<double> debug_alpham;
image2d<bool> debug_alphacond;
diff --git a/scribo/scribo/binarization/internal/sauvola_ms_functor.hh
b/scribo/scribo/binarization/internal/sauvola_ms_functor.hh
index d72fc26..d0e6200 100644
--- a/scribo/scribo/binarization/internal/sauvola_ms_functor.hh
+++ b/scribo/scribo/binarization/internal/sauvola_ms_functor.hh
@@ -43,6 +43,7 @@
# include <scribo/binarization/internal/local_threshold_debug.hh>
# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
+#include <mln/value/int_u8.hh>
namespace scribo
{
@@ -60,6 +61,11 @@ namespace scribo
struct sauvola_ms_functor
{
const I& input;
+
+ const image2d<value::int_u8>& e_2;
+ unsigned i;
+ unsigned q;
+
mln_fwd_pixter(const I) pxl;
double res;
image2d<unsigned> parent;
@@ -79,7 +85,7 @@ namespace scribo
sauvola_formula formula_;
- sauvola_ms_functor(const I& input, double K, double R);
+ sauvola_ms_functor(const I& input, double K, double R, const
image2d<value::int_u8>&e_2, unsigned i, unsigned q);
void exec(double mean, double stddev);
void end_of_row(int row);
@@ -101,8 +107,11 @@ namespace scribo
template <typename I>
- sauvola_ms_functor<I>::sauvola_ms_functor(const I& input, double K,
double R)
+ sauvola_ms_functor<I>::sauvola_ms_functor(const I& input, double K,
double R, const image2d<value::int_u8>&e_2, unsigned i, unsigned q)
: input(input),
+ e_2(e_2),
+ i(i),
+ q(q),
pxl(input),
K_(K),
R_(R)
@@ -142,7 +151,49 @@ namespace scribo
value::int_u8 t_p;
mln::convert::from_to(formula_(mean, stddev, K_, R_), t_p);
+ // point2d pi = input.point_at_index(p);
+ // pi.row() *= std::pow(q, i - 2);
+ // pi.col() *= std::pow(q, i - 2);
+
+ // point2d pi_up = pi;
+ // pi_up.row() -= std::pow(q, i - 2);
+
+ // point2d pi_up_left = pi;
+ // pi_up_left.row() -= std::pow(q, i - 2);
+ // pi_up_left.col() -= std::pow(q, i - 2);
+
+ // point2d pi_up_right = pi;
+ // pi_up_right.row() -= std::pow(q, i - 2);
+ // pi_up_right.col() += std::pow(q, i - 2);
+
+ // point2d pi_down = pi;
+ // pi_down.row() += std::pow(q, i - 2);
+
+ // point2d pi_down_left = pi;
+ // pi_down_left.row() += std::pow(q, i - 2);
+ // pi_down_left.col() -= std::pow(q, i - 2);
+
+ // point2d pi_down_right = pi;
+ // pi_down_right.row() += std::pow(q, i - 2);
+ // pi_down_right.col() += std::pow(q, i - 2);
+
+ // point2d pi_left = pi;
+ // pi_left.col() -= std::pow(q, i - 2);
+
+ // point2d pi_right = pi;
+ // pi_right.col() += std::pow(q, i - 2);
+
+
+
+
+
+// if (e_2(pi) != 0) // Already retrieved from another scale.
+// // || e_2(pi_up) != 0 || e_2(pi_down) != 0 || e_2(pi_left) != 0 || e_2(pi_right)
!= 0
+// // || e_2(pi_up_left) != 0 || e_2(pi_up_right) != 0 || e_2(pi_down_left) != 0 ||
e_2(pi_down_right) != 0)
+// msk.element(p) = false;
+// else
msk.element(p) = input.element(p) < t_p;
+
# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
full_msk.element(p) = msk.element(p);
# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
diff --git a/scribo/scribo/binarization/sauvola_ms.hh
b/scribo/scribo/binarization/sauvola_ms.hh
index 63ea38f..e6297bd 100644
--- a/scribo/scribo/binarization/sauvola_ms.hh
+++ b/scribo/scribo/binarization/sauvola_ms.hh
@@ -72,6 +72,7 @@
# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
# include <scribo/binarization/internal/local_threshold_debug.hh>
# include <mln/io/pgm/save.hh>
+# include <mln/io/dump/save.hh>
# include <mln/debug/filename.hh>
# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
@@ -186,13 +187,15 @@ namespace scribo
// 1st pass
scribo::binarization::internal::sauvola_ms_functor< image2d<int_u8> >
- f(sub, K, SCRIBO_DEFAULT_SAUVOLA_R);
+ f(sub, K, SCRIBO_DEFAULT_SAUVOLA_R, e_2, i, q);
scribo::canvas::integral_browsing(integral_sum_sum_2,
ratio,
w_local_w, w_local_h,
s,
f);
+ std::cout << " i = " << i << " - ratio = "
<< ratio << std::endl;
+
// 2nd pass
{
mln::util::array<mln_value_(I) *> ptr(ratio);
@@ -235,6 +238,10 @@ namespace scribo
&& f.card.element(p) < lambda_max;
# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
f.full_msk.element(p) = true;
+
+ for (unsigned l = 0; l < ratio; ++l)
+ for (unsigned k = 0; k < ratio; ++k)
+ debug_scale_proba(point3d(i - 2, sq.row() + l, sq.col() + k)) =
f.card.element(p);
# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
if (f.msk.element(p) && e_2(sq) == 0u)
@@ -250,6 +257,13 @@ namespace scribo
f.msk.element(p) = f.msk.element(f.parent.element(p));
# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
f.full_msk.element(p) = f.full_msk.element(f.parent.element(p));
+
+ point2d sqp = f.parent.point_at_index(f.parent.element(p)) * ratio;
+ unsigned v = debug_scale_proba(point3d(i - 2, sqp.row(), sqp.col()));
+
+ for (unsigned l = 0; l < ratio; ++l)
+ for (unsigned k = 0; k < ratio; ++k)
+ debug_scale_proba(point3d(i - 2, sq.row() + l, sq.col() + k)) = v;
# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
if (f.msk.element(p) && e_2(sq) == 0u)
@@ -868,10 +882,10 @@ namespace scribo
data::fill(e_2, 0u);
// Computing optimal object area for each scale.
- unsigned w_1_sq = w_1 * w_1;
- unsigned q_2 = std::pow(float(q), float(2));
- unsigned min_area = (5 * w_1_sq) / (4 * q_2);
- unsigned max_area = (w_1_sq + (q_2) * w_1_sq) / 4;
+ // unsigned w_1_sq = w_1 * w_1;
+ // unsigned q_2 = std::pow(float(q), float(2));
+ // unsigned min_area = (5 * w_1_sq) / (4 * q_2);
+ // unsigned max_area = (w_1_sq + (q_2) * w_1_sq) / 4;
// mln::util::array<unsigned> area(sub_ima.size(), 0);
@@ -879,11 +893,33 @@ namespace scribo
// for (unsigned i = 3; i < area.nelements(); ++i)
// area[i] = std::pow(float(q), float(i * 2 - 4)) * area[2];
+ mln::util::array<unsigned> win_w(sub_ima.size(), 0);
+ win_w[2] = s * w_1;
+ for (unsigned i = 3; i < win_w.nelements(); ++i)
+ {
+ win_w[i] = q * win_w[i - 1];
+ if (!(win_w[i] % 2))
+ ++win_w[i];
+ }
+
+ float coeff = 1.4;
+
+
+# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG
+ internal::debug_scale_proba = image3d<double>(3,
+ integral_sum_sum_2.nrows(),
+ integral_sum_sum_2.ncols(),
+ integral_sum_sum_2.border());
+# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
+
+
// Highest scale -> no maximum component size.
{
int i = sub_ima.size() - 1;
t_ima[i] = internal::compute_t_n_and_e_2(sub_ima[i], e_2,
- min_area,
+// (8096 / 144) / coeff,
+// 44 / coeff,
+ win_w[i] / 3 / coeff,
mln_max(unsigned),
s,
q, i, w_work,
@@ -896,8 +932,12 @@ namespace scribo
for (int i = sub_ima.size() - 2; i > 2; --i)
{
t_ima[i] = internal::compute_t_n_and_e_2(sub_ima[i], e_2,
- min_area,
- max_area,
+// 22 / coeff,
+// 201 * coeff,
+ win_w[i] / 3 / coeff,
+ win_w[i] * 3 * coeff,
+// (810 / 36) / coeff,
+// (8096 / 36) * coeff,
s,
q, i, w_work,
integral_sum_sum_2,
@@ -909,7 +949,9 @@ namespace scribo
{
t_ima[2] = internal::compute_t_n_and_e_2(sub_ima[2], e_2,
0,
- max_area,
+// 99 * coeff,
+ win_w[2] * 3 * coeff,
+// (810 / 9) * coeff,
s, 1, 2, w_work,
integral_sum_sum_2,
K);
@@ -938,6 +980,9 @@ namespace scribo
if (internal::scale_iz_image_output)
io::pgm::save(e_2,
mln::debug::filename(internal::scale_iz_image_output));
+ if (internal::scale_proba_output)
+ io::dump::save(internal::debug_scale_proba,
+ mln::debug::filename(internal::scale_proba_output));
# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG
// Binarize
diff --git a/scribo/src/binarization/sauvola_ms_debug.cc
b/scribo/src/binarization/sauvola_ms_debug.cc
index 63fbefe..c04e58b 100644
--- a/scribo/src/binarization/sauvola_ms_debug.cc
+++ b/scribo/src/binarization/sauvola_ms_debug.cc
@@ -105,6 +105,7 @@ int main(int argc, char *argv[])
scribo::binarization::internal::threshold_image_output =
"threshold_image.pbm";
scribo::binarization::internal::full_threshold_image_output =
"full_threshold_image.pbm";
scribo::binarization::internal::scale_iz_image_output = "scale_iz.pgm";
+ scribo::binarization::internal::scale_proba_output = "scale_proba.dump";
// Load
image2d<value::rgb8> input_1;
--
1.7.2.5