LRE
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
List overview
Download
Olena-patches
August 2012
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
olena-patches@lrde.epita.fr
2 participants
138 discussions
Start a n
N
ew thread
olena-2.0-93-g6e6efc3 scribo/binarization/sauvola_ms.hh: Change area thresholds.
by Guillaume Lazzara
--- scribo/ChangeLog | 4 +++ scribo/scribo/binarization/sauvola_ms.hh | 37 +++++++++++++++++------------ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 5383b57..9c1b5dd 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,9 @@ 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * scribo/binarization/sauvola_ms.hh: Change area thresholds. + +2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * scribo/binarization/sauvola_ms.hh: More fixes in debug. 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> diff --git a/scribo/scribo/binarization/sauvola_ms.hh b/scribo/scribo/binarization/sauvola_ms.hh index 0abef14..63ea38f 100644 --- a/scribo/scribo/binarization/sauvola_ms.hh +++ b/scribo/scribo/binarization/sauvola_ms.hh @@ -156,6 +156,8 @@ namespace scribo w_local_h = w_local, w_local_w = w_local; + std::cout << "scale " << i << " - w = " << w << " - lambda_min = " << lambda_min << " - lambda_max = " << lambda_max << std::endl; + // Make sure the window fits in the image domain. if (w_local_w >= static_cast<const unsigned>(integral_sum_sum_2.ncols())) { @@ -180,6 +182,7 @@ namespace scribo ++w_local_h; } + std::cout << "Scale " << i << " - w_h = " << w_local_h << " - w_w = " << w_local_w << " - w = " << w << std::endl; // 1st pass scribo::binarization::internal::sauvola_ms_functor< image2d<int_u8> > @@ -787,21 +790,16 @@ namespace scribo dpoint2d none(0, 0); - unsigned lambda_min_1 = w_1 / 2; - // Number of subscales. unsigned nb_subscale = 3; // Window size. - unsigned w_work = w_1 / s; // Scale 2 + unsigned w_work = w_1 * s; // Scale 2 // Subscale step. unsigned q = 2; - unsigned lambda_min_2 = lambda_min_1 / s; - unsigned lambda_max_2 = lambda_min_2 * q; - mln::util::array<I> t_ima; @@ -869,13 +867,23 @@ namespace scribo initialize(e_2, sub_ima[2]); 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; + + + // mln::util::array<unsigned> area(sub_ima.size(), 0); + // area[2] = s * s * w_1 * w_1; + // for (unsigned i = 3; i < area.nelements(); ++i) + // area[i] = std::pow(float(q), float(i * 2 - 4)) * area[2]; + // Highest scale -> no maximum component size. { int i = sub_ima.size() - 1; - // Cast to float is needed on MacOS X. - unsigned ratio = unsigned(std::pow(float(q), float(i - 2))); // Ratio compared to e_2 t_ima[i] = internal::compute_t_n_and_e_2(sub_ima[i], e_2, - lambda_min_2 / ratio, + min_area, mln_max(unsigned), s, q, i, w_work, @@ -887,11 +895,9 @@ namespace scribo { for (int i = sub_ima.size() - 2; i > 2; --i) { - // Cast to float is needed on MacOS X. - unsigned ratio = unsigned(std::pow(float(q), float(i - 2))); // Ratio compared to e_2 t_ima[i] = internal::compute_t_n_and_e_2(sub_ima[i], e_2, - lambda_min_2 / ratio, - lambda_max_2 / ratio, + min_area, + max_area, s, q, i, w_work, integral_sum_sum_2, @@ -901,8 +907,9 @@ namespace scribo // Lowest scale -> no minimum component size. { - t_ima[2] = internal::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, + max_area, s, 1, 2, w_work, integral_sum_sum_2, K); -- 1.7.2.5
12 years, 4 months
1
0
0
0
olena-2.0-83-ga839009 sauvola_fast.cc: Cleanup and add some debug.
by Guillaume Lazzara
--- scribo/ChangeLog | 4 + scribo/sauvola_fast.cc | 234 ++++++++---------------------------------------- 2 files changed, 40 insertions(+), 198 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index b01a8f8..43931c6 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,9 @@ 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * sauvola_fast.cc: Cleanup and add some debug. + +2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * sauvola_fast.cc: Use subscaled integral image. 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> diff --git a/scribo/sauvola_fast.cc b/scribo/sauvola_fast.cc index ed4e6d4..7eb41ca 100644 --- a/scribo/sauvola_fast.cc +++ b/scribo/sauvola_fast.cc @@ -5,12 +5,14 @@ #include <mln/util/couple.hh> #include <mln/util/timer.hh> #include <scribo/binarization/internal/sauvola_formula.hh> +#include <scribo/util/init_integral_image.hh> +#include <scribo/util/integral_sum_sum2_functor.hh> namespace mln { template <typename I> - struct sauvola_fast_functor + struct sauvola_functor { const I& input; @@ -28,13 +30,12 @@ namespace mln scribo::binarization::internal::sauvola_formula formula_; int step_; - unsigned next_line1; unsigned next_line2; unsigned next_line3; unsigned offset1; unsigned offset2; - sauvola_fast_functor(const I& input_, mln_ch_value(I,bool)& bin_, double K, double R) + sauvola_functor(const I& input_, mln_ch_value(I,bool)& bin_, double K, double R) : input(input_), bin(bin_), pi(&input(input.domain().pmin())), @@ -43,7 +44,7 @@ namespace mln R_(R) { step_ = 3; - next_line1 = 2 * input.border(); + unsigned next_line1 = 2 * input.border(); next_line2 = input.delta_index(dpoint2d(+1,0)) + next_line1; next_line3 = input.delta_index(dpoint2d(+2,0)) + next_line1; @@ -51,6 +52,7 @@ namespace mln offset2 = input.delta_index(dpoint2d(+2,0)); } + // Run every 4 pixels. void exec(double mean, double stddev) { static point2d p(0,0); @@ -63,6 +65,20 @@ namespace mln *(po + offset1) = (*(pi + offset1) <= th); *(po + offset2) = (*(pi + offset2) <= th); } + +# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG + // Store local mean + unsigned index = pi - input.buffer(); + + internal::debug_mean.element(index) = mean * internal::mean_debug_factor; + internal::debug_stddev.element(index) = stddev * internal::stddev_debug_factor; + internal::debug_threshold.element(index) = t; + + double alpha = K * (1 - stddev / R); + internal::debug_alpham.element(index) = alpha * mean * internal::alpham_debug_factor; + internal::debug_alphacond.element(index) = (stddev < (alpha * mean / 2.)); +# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG + } void end_of_row(int) @@ -80,213 +96,34 @@ namespace mln - - template <typename I, typename J> - void - init_integral_3(const Image<I>& input_, - Image<J>& integral_sum_sum_2_) - { - trace::entering("subsampling::impl::integral_3"); - - const unsigned scale = 3; - - const I& input = exact(input_); - J& integral_sum_sum_2 = exact(integral_sum_sum_2_); - - box<mln_site(I)> - output_domain = mln::make::box2d((input.nrows() + scale - 1) / scale, - (input.ncols() + scale - 1) / scale); - - mln_precondition(input.is_valid()); - mln_precondition(input.domain().pmin() == literal::origin); - mln_precondition(scale > 1); - - typedef mln_value(I) V; - typedef mln_sum(V) S; - typedef mln_value(J) V2; - typedef mln_site(I) P; - - integral_sum_sum_2.init_(output_domain, input.border()); - V2* p_integ = integral_sum_sum_2.buffer(); - - const int up = integral_sum_sum_2.delta_index(dpoint2d(-1, 0)); - - const unsigned nrows = 3 * integral_sum_sum_2.nrows(); - const unsigned ncols = 3 * integral_sum_sum_2.ncols(); - - unsigned row = 0; - - unsigned b_offset = integral_sum_sum_2.delta_index(dpoint2d(input.border(), - input.border())); - p_integ += b_offset; - { - S h_sum = 0, h_sum_2 = 0; - const V* ptr1 = & input.at_(row, 0); - const V* ptr2 = & input.at_(row + 1, 0); - const V* ptr3 = & input.at_(row + 2, 0); - for (unsigned col = 0; col < ncols; col += scale) - { - V v11 = *ptr1, v12 = *(ptr1 + 1), v13 = *(ptr1 + 2), - v21 = *ptr2, v22 = *(ptr2 + 1), v23 = *(ptr2 + 2), - v31 = *ptr3, v32 = *(ptr3 + 1), v33 = *(ptr3 + 2); - ptr1 += 3; - ptr2 += 3; - ptr3 += 3; - S local_sum = v11 + v12 + v13 - + v21 + v22 + v23 - + v31 + v32 + v33, - local_sum_2 = v11*v11 + v12*v12 + v13*v13 - + v21*v21 + v22*v22 + v23*v23 - + v31*v31 + v32*v32 + v33*v33; - - h_sum += local_sum; - h_sum_2 += local_sum_2; - - // exception - p_integ->first() = h_sum; - p_integ->second() = h_sum_2; - - p_integ += 1; - } - } - - unsigned b_next = 2 * input.border(); - - p_integ += b_next; - - for (row += scale; row < nrows; row += scale) - { - S h_sum = 0, h_sum_2 = 0; - const V* ptr1 = & input.at_(row, 0); - const V* ptr2 = & input.at_(row + 1, 0); - const V* ptr3 = & input.at_(row + 2, 0); - for (unsigned col = 0; col < ncols; col += scale) - { - V v11 = *ptr1, v12 = *(ptr1 + 1), v13 = *(ptr1 + 2), - v21 = *ptr2, v22 = *(ptr2 + 1), v23 = *(ptr2 + 2), - v31 = *ptr3, v32 = *(ptr3 + 1), v33 = *(ptr3 + 2); - ptr1 += 3; - ptr2 += 3; - ptr3 += 3; - S local_sum = v11 + v12 + v13 - + v21 + v22 + v23 - + v31 + v32 + v33, - local_sum_2 = v11*v11 + v12*v12 + v13*v13 - + v21*v21 + v22*v22 + v23*v23 - + v31*v31 + v32*v32 + v33*v33; - - h_sum += local_sum; - h_sum_2 += local_sum_2; - - p_integ->first() = h_sum + (p_integ + up)->first(); - p_integ->second() = h_sum_2 + (p_integ + up)->second(); - - p_integ += 1; - } - - p_integ += b_next; - } - - trace::exiting("subsampling::impl::integral_3"); - } - - - - template <typename I, typename J> - void - init_integral(const Image<I>& input_, - Image<J>& integral_sum_sum_2_) - { - trace::entering("subsampling::impl::integral_3"); - - const I& input = exact(input_); - J& integral_sum_sum_2 = exact(integral_sum_sum_2_); - - mln_precondition(input.is_valid()); - mln_precondition(input.domain().pmin() == literal::origin); - - typedef mln_value(I) V; - typedef mln_sum(V) S; - typedef mln_value(J) V2; - typedef mln_site(I) P; - - initialize(integral_sum_sum_2, input); - V2* p_integ = integral_sum_sum_2.buffer(); - - const int up = input.delta_index(dpoint2d(-1, 0)); - - const unsigned nrows = input.domain().nrows(); - const unsigned ncols = input.domain().ncols(); - - unsigned row = 0; - - unsigned b_offset = input.delta_index(dpoint2d(input.border(), - input.border())); - p_integ += b_offset; - { - S h_sum = 0, h_sum_2 = 0; - const V* ptr1 = & input.at_(row, 0); - for (unsigned col = 0; col < ncols; ++col) - { - V v = *ptr1++; - - h_sum += v; - h_sum_2 += v * v; - - // exception - p_integ->first() = h_sum; - p_integ->second() = h_sum_2; - - ++p_integ; - } - } - - unsigned b_next = 2 * input.border(); - - p_integ += b_next; - - for (row += 1; row < nrows; ++row) - { - S h_sum = 0, h_sum_2 = 0; - const V* ptr1 = & input.at_(row, 0); - for (unsigned col = 0; col < ncols; ++col) - { - V v = *ptr1++; - - h_sum += v; - h_sum_2 += v * v; - - p_integ->first() = h_sum + (p_integ + up)->first(); - p_integ->second() = h_sum_2 + (p_integ + up)->second(); - - ++p_integ; - } - - p_integ += b_next; - } - - trace::exiting("subsampling::impl::integral_3"); - } - - - image2d<bool> sauvola_fast(const image2d<value::int_u8>& input, unsigned win) { util::timer t; t.start(); - image2d<util::couple<double,double> > integral; - init_integral_3(input, integral); - // image2d<value::int_u8> sub = scribo::subsampling::integral(input, 3, integral); + scribo::util::integral_sum_sum2_functor<value::int_u8, double> fi; + image2d<util::couple<double,double> > + integral = scribo::util::init_integral_image(input, 3, fi); t.stop(); std::cout << "image integrale - " << t << std::endl; +# ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG + initialize(internal::debug_mean, input); + initialize(internal::debug_stddev, input); + + initialize(internal::debug_threshold, input); + initialize(internal::debug_alpham, input); + initialize(internal::debug_alphacond, input); +# endif // ! SCRIBO_LOCAL_THRESHOLD_DEBUG + t.restart(); image2d<bool> output; initialize(output, input); - sauvola_fast_functor<image2d<value::int_u8> > f(input, output, SCRIBO_DEFAULT_SAUVOLA_K, SCRIBO_DEFAULT_SAUVOLA_R); + sauvola_functor<image2d<value::int_u8> > f(input, output, + SCRIBO_DEFAULT_SAUVOLA_K, + SCRIBO_DEFAULT_SAUVOLA_R); scribo::canvas::integral_browsing(integral, 1, win / 3, win / 3, 3, f); t.stop(); std::cout << "Binarization - " << t << std::endl; @@ -314,3 +151,4 @@ int main(int argc, char *argv[]) io::pbm::save(output, argv[3]); } + -- 1.7.2.5
12 years, 4 months
1
0
0
0
olena-2.0-80-gb1d52c9 sauvola_fast.cc: New implementation.
by Guillaume Lazzara
--- scribo/ChangeLog | 4 + scribo/sauvola_fast.cc | 175 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+), 0 deletions(-) create mode 100644 scribo/sauvola_fast.cc diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 8b2cae5..5d4003e 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,9 @@ 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * sauvola_fast.cc: New implementation. + +2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * scribo/binarization/sauvola_threshold.hh: Add some debug. 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> diff --git a/scribo/sauvola_fast.cc b/scribo/sauvola_fast.cc new file mode 100644 index 0000000..8018135 --- /dev/null +++ b/scribo/sauvola_fast.cc @@ -0,0 +1,175 @@ +#include <mln/core/image/image2d.hh> +#include <scribo/canvas/integral_browsing.hh> +#include <mln/io/pgm/load.hh> +#include <mln/io/pbm/save.hh> +#include <mln/util/couple.hh> +#include <mln/util/timer.hh> +#include <scribo/binarization/internal/sauvola_formula.hh> + +namespace mln +{ + + template <typename I> + struct sauvola_fast_functor + { + + const I& input; + typedef mln_ch_value(I,bool) bin_t; + bin_t bin; + + mln_fwd_pixter(const I) pi; + mln_fwd_pixter(bin_t) po; + + double K_; + double R_; + + scribo::binarization::internal::sauvola_formula formula_; + + unsigned count_; + + sauvola_fast_functor(const I& input_, mln_ch_value(I,bool)& bin_, double K, double R) + : input(input_), + bin(bin_), + pi(input), + po(bin), + K_(K), + R_(R) + { + pi.start(); + po.start(); + count_ = 0; + } + + void exec(double mean, double stddev) + { + static point2d p(0,0); + po.val() = (pi.val() <= formula_(p, mean, stddev, K_, R_)); + + pi.next(); // next pixel + po.next(); // next pixel + + ++count_; + } + + void finalize() + { + std::cout << input.domain().nsites() << " - " << input.domain().nrows() * input.domain().ncols() << " - " << count_ << std::endl; + } + + }; + + + + + template <typename I, typename J> + void + init_integral(const Image<I>& input_, + Image<J>& integral_sum_sum_2_) + { + trace::entering("subsampling::impl::integral_3"); + + const I& input = exact(input_); + J& integral_sum_sum_2 = exact(integral_sum_sum_2_); + + mln_precondition(input.is_valid()); + mln_precondition(input.domain().pmin() == literal::origin); + + typedef mln_value(I) V; + typedef mln_sum(V) S; + typedef mln_value(J) V2; + typedef mln_site(I) P; + + initialize(integral_sum_sum_2, input); + V2* p_integ = integral_sum_sum_2.buffer(); + + const int up = input.delta_index(dpoint2d(-1, 0)); + + const unsigned nrows = input.domain().nrows(); + const unsigned ncols = input.domain().ncols(); + + unsigned row = 0; + + unsigned b_offset = input.delta_index(dpoint2d(input.border(), + input.border())); + p_integ += b_offset; + { + S h_sum = 0, h_sum_2 = 0; + const V* ptr1 = & input.at_(row, 0); + for (unsigned col = 0; col < ncols; ++col) + { + V v = *ptr1++; + + h_sum += v; + h_sum_2 += v * v; + + // exception + p_integ->first() = h_sum; + p_integ->second() = h_sum_2; + + ++p_integ; + } + } + + unsigned b_next = 2 * input.border(); + + p_integ += b_next; + + for (row += 1; row < nrows; ++row) + { + S h_sum = 0, h_sum_2 = 0; + const V* ptr1 = & input.at_(row, 0); + for (unsigned col = 0; col < ncols; ++col) + { + V v = *ptr1++; + + h_sum += v; + h_sum_2 += v * v; + + p_integ->first() = h_sum + (p_integ + up)->first(); + p_integ->second() = h_sum_2 + (p_integ + up)->second(); + + ++p_integ; + } + + p_integ += b_next; + } + + trace::exiting("subsampling::impl::integral_3"); + } + + + + image2d<bool> + sauvola_fast(const image2d<value::int_u8>& input, unsigned win) + { + image2d<util::couple<double,double> > integral; + init_integral(input, integral); + + image2d<bool> output; + initialize(output, input); + sauvola_fast_functor<image2d<value::int_u8> > f(input, output, SCRIBO_DEFAULT_SAUVOLA_K, SCRIBO_DEFAULT_SAUVOLA_R); + scribo::canvas::integral_browsing(integral, 1, win, win, 1, f); + + return f.bin; + } + +} + + +int main(int argc, char *argv[]) +{ + using namespace mln; + + image2d<value::int_u8> input; + io::pgm::load(input, argv[1]); + + unsigned win = atoi(argv[2]); + + util::timer t; + t.start(); + image2d<bool> output = sauvola_fast(input, win); + t.stop(); + std::cout << t << std::endl; + + io::pbm::save(output, argv[3]); +} -- 1.7.2.5
12 years, 4 months
1
0
0
0
olena-2.0-79-ga8f83ef z/sauvola_ms_rv/dump_color_sign.cc: New.
by Guillaume Lazzara
--- scribo/sandbox/ChangeLog | 4 ++ scribo/sandbox/z/sauvola_ms_rv/dump_color_sign.cc | 52 +++++++++++++++++++++ 2 files changed, 56 insertions(+), 0 deletions(-) create mode 100644 scribo/sandbox/z/sauvola_ms_rv/dump_color_sign.cc diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog index 92abdb1..2c0068f 100644 --- a/scribo/sandbox/ChangeLog +++ b/scribo/sandbox/ChangeLog @@ -1,5 +1,9 @@ 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * z/sauvola_ms_rv/dump_color_sign.cc: New. + +2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + Add test images. * z/sauvola_ms_rv/img/001.pgm, diff --git a/scribo/sandbox/z/sauvola_ms_rv/dump_color_sign.cc b/scribo/sandbox/z/sauvola_ms_rv/dump_color_sign.cc new file mode 100644 index 0000000..6ea6ad8 --- /dev/null +++ b/scribo/sandbox/z/sauvola_ms_rv/dump_color_sign.cc @@ -0,0 +1,52 @@ +#include <mln/core/concept/function.hh> +#include <mln/core/image/image2d.hh> +#include <mln/value/rgb8.hh> +#include <mln/io/dump/load.hh> +#include <mln/io/ppm/save.hh> +#include <mln/data/transform.hh> +#include <mln/data/stretch.hh> +#include <mln/arith/minus.hh> + +namespace mln +{ + + struct color_diff : Function_v2v<color_diff> + { + typedef value::rgb8 result; + + value::rgb8 operator()(const int& v) const + { + int v_d2 = std::abs(v) * 0.0001; + + if (v < 0) + return value::rgb8(128 + v_d2, v_d2, v_d2); + else if (v > 0) + return value::rgb8(v_d2, 128 + v_d2, v_d2); + else + return value::rgb8(255, 255, 255); + } + }; + +} + + +int main(int argc, char *argv[]) +{ + using namespace mln; + + + if (argc != 3) + { + std::cout << "Usage: " << argv[0] << " in.dump out.ppm" << std::endl; + return 1; + } + + image2d<double> input; + + io::dump::load(input, argv[1]); + + color_diff f; + image2d<value::rgb8> result = data::transform(input, f); + + io::ppm::save(result, argv[2]); +} -- 1.7.2.5
12 years, 4 months
1
0
0
0
olena-2.0-77-ge375d14 z/sauvola_ms_rv/skewness/skewness2.cc: Retrieve skewness debug image.
by Guillaume Lazzara
--- scribo/sandbox/ChangeLog | 5 +++++ .../sandbox/z/sauvola_ms_rv/skewness/skewness2.cc | 2 ++ 2 files changed, 7 insertions(+), 0 deletions(-) diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog index ba8672b..67fe4a3 100644 --- a/scribo/sandbox/ChangeLog +++ b/scribo/sandbox/ChangeLog @@ -1,5 +1,10 @@ 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * z/sauvola_ms_rv/skewness/skewness2.cc: Retrieve skewness debug + image. + +2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * z/sauvola_ms_rv/skewness/skewness2.cc: Fix calls to sauvola. 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> diff --git a/scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc b/scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc index 9b77a99..331575f 100644 --- a/scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc +++ b/scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc @@ -32,6 +32,7 @@ #include "integral_browsing_rv.hh" mln::image2d<bool> skewness_pbm; +mln::image2d<double> skewness_d; std::string prefix; @@ -197,6 +198,7 @@ int main(int argc, char *argv[]) scribo::canvas::integral_browsing_rv(integral_sum_sum_2_sum_3, skewness_win_size, skewness_win_size, f); skewness_pbm = f.skewness_; + skewness_d = f.skewness_d_; t.stop(); std::cout << "invert on skewness - " << t << std::endl; -- 1.7.2.5
12 years, 4 months
1
0
0
0
olena-2.0-76-ga987daa scribo/binarization/sauvola_threshold.hh: Add some debug.
by Guillaume Lazzara
--- scribo/ChangeLog | 4 ++++ scribo/scribo/binarization/sauvola_threshold.hh | 6 +++++- 2 files changed, 9 insertions(+), 1 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 6c79022..8b2cae5 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,9 @@ 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * scribo/binarization/sauvola_threshold.hh: Add some debug. + +2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + Compute Sauvola on documents with light text and dark background. * scribo/binarization/internal/compute_local_threshold.hh, diff --git a/scribo/scribo/binarization/sauvola_threshold.hh b/scribo/scribo/binarization/sauvola_threshold.hh index df46e95..7950c13 100644 --- a/scribo/scribo/binarization/sauvola_threshold.hh +++ b/scribo/scribo/binarization/sauvola_threshold.hh @@ -44,7 +44,7 @@ # include <scribo/binarization/internal/compute_local_threshold.hh> # include <scribo/binarization/internal/sauvola_formula.hh> - +extern std::string prefix; namespace scribo { @@ -130,6 +130,7 @@ namespace scribo # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG initialize(internal::debug_mean, input); initialize(internal::debug_stddev, input); + initialize(internal::debug_threshold, input); initialize(internal::debug_alpham, input); initialize(internal::debug_alphacond, input); @@ -262,6 +263,9 @@ namespace scribo simple = init_integral_image(input, scribo::internal::identity_), squared = init_integral_image(input, scribo::internal::square_); + io::dump::save(simple, prefix + "simple.dump"); + io::dump::save(squared, prefix + "squared.dump"); + return sauvola_threshold(input, window_size, K, simple, squared); } -- 1.7.2.5
12 years, 4 months
1
0
0
0
olena-2.0-75-gb09fb77 z/sauvola_ms_rv/skewness/skewness2.cc: Fix calls to sauvola.
by Guillaume Lazzara
--- scribo/sandbox/ChangeLog | 4 ++ .../sandbox/z/sauvola_ms_rv/skewness/skewness2.cc | 31 +++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog index 446cae0..ba8672b 100644 --- a/scribo/sandbox/ChangeLog +++ b/scribo/sandbox/ChangeLog @@ -1,5 +1,9 @@ 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * z/sauvola_ms_rv/skewness/skewness2.cc: Fix calls to sauvola. + +2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + Add new tools. * z/sauvola_ms_rv/pgm_color_diff.cc, diff --git a/scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc b/scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc index 043e0ad..9b77a99 100644 --- a/scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc +++ b/scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc @@ -26,9 +26,9 @@ #include <mln/arith/revert.hh> #include <mln/util/timer.hh> -mln::image2d<double> skewness; #include <scribo/binarization/sauvola_ms.hh> +#include <scribo/binarization/sauvola.hh> #include "integral_browsing_rv.hh" mln::image2d<bool> skewness_pbm; @@ -131,7 +131,8 @@ namespace mln struct invert_on_skewness { I input; - image2d<double> skewness_; + image2d<bool> skewness_; + image2d<double> skewness_d_; mln_fwd_pixter(I) pxl; invert_on_skewness(const I& input_) @@ -140,14 +141,16 @@ namespace mln { pxl.start(); initialize(skewness_, input); + initialize(skewness_d_, input); } void exec(double skewness) { - skewness_.element(pxl.offset()) = skewness; + skewness_d_.element(pxl.offset()) = skewness; + skewness_.element(pxl.offset()) = (skewness <= 1000.); - if (skewness > 1000.) - pxl.val() = 255 - pxl.val(); + // if (skewness > 1000.) + // pxl.val() = 255 - pxl.val(); pxl.next(); // next pixel } @@ -163,9 +166,9 @@ int main(int argc, char *argv[]) { using namespace mln; - if (argc != 4) + if (argc != 5) { - std::cerr << "Usage: " << argv[0] << " <input.pgm> <prefix> <win_size>" << std::endl; + std::cerr << "Usage: " << argv[0] << " <input.pgm> <prefix> <skewness_win_size> <sauvola_win_size>" << std::endl; return 1; } @@ -179,7 +182,8 @@ int main(int argc, char *argv[]) prefix = argv[2]; - int win_size = atoi(argv[3]); + int skewness_win_size = atoi(argv[3]); + int sauvola_win_size = atoi(argv[4]); t.stop(); std::cout << "Initialization - " << t << std::endl; @@ -190,16 +194,21 @@ int main(int argc, char *argv[]) scribo::integral_rv(input, integral_sum_sum_2_sum_3); invert_on_skewness<image2d<value::int_u8> > f(input); - scribo::canvas::integral_browsing_rv(integral_sum_sum_2_sum_3, win_size, win_size, f); + scribo::canvas::integral_browsing_rv(integral_sum_sum_2_sum_3, skewness_win_size, skewness_win_size, f); + + skewness_pbm = f.skewness_; t.stop(); std::cout << "invert on skewness - " << t << std::endl; io::dump::save(f.skewness_, prefix + "skewness.dump"); + io::dump::save(f.skewness_d_, prefix + "skewness_d.dump"); t.restart(); - image2d<bool> bin = scribo::binarization::sauvola_ms(f.input, 101, 2); - std::cout << "sauvola_ms - " << t << std::endl; +// image2d<bool> bin = scribo::binarization::sauvola_ms(input, 101, 2); +// std::cout << "sauvola_ms - " << t << std::endl; + image2d<bool> bin = scribo::binarization::sauvola(input, sauvola_win_size); + std::cout << "sauvola - " << t << std::endl; std::cout << "Total time : " << tt << std::endl; -- 1.7.2.5
12 years, 4 months
1
0
0
0
olena-2.0-74-g9be09ea Compute Sauvola on documents with light text and dark background.
by Guillaume Lazzara
* scribo/binarization/internal/compute_local_threshold.hh, * scribo/binarization/internal/first_pass_functor.hh, * scribo/binarization/internal/sauvola_formula.hh, * scribo/binarization/local_threshold.hh: Update formula. --- scribo/ChangeLog | 9 ++++++ .../internal/compute_local_threshold.hh | 15 +++++++++- .../binarization/internal/first_pass_functor.hh | 2 +- .../binarization/internal/sauvola_formula.hh | 22 +++++++++++----- scribo/scribo/binarization/local_threshold.hh | 27 +++++++++++++------ 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index f8d7491..6c79022 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,3 +1,12 @@ +2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + + Compute Sauvola on documents with light text and dark background. + + * scribo/binarization/internal/compute_local_threshold.hh, + * scribo/binarization/internal/first_pass_functor.hh, + * scribo/binarization/internal/sauvola_formula.hh, + * scribo/binarization/local_threshold.hh: Update formula. + 2012-05-10 Guillaume Lazzara <z(a)lrde.epita.fr> Improve option parser. diff --git a/scribo/scribo/binarization/internal/compute_local_threshold.hh b/scribo/scribo/binarization/internal/compute_local_threshold.hh index 147ef0f..4c25e17 100644 --- a/scribo/scribo/binarization/internal/compute_local_threshold.hh +++ b/scribo/scribo/binarization/internal/compute_local_threshold.hh @@ -42,7 +42,8 @@ -// extern mln::image2d<double> skewness; +extern mln::image2d<double> skewness; +extern mln::image2d<bool> skewness_pbm; namespace scribo { @@ -117,6 +118,11 @@ namespace scribo - simple.at_(row_max, col_min) - simple.at_(row_min, col_max)); + // if (!skewness_pbm(p)) + // { + // m_x_y_tmp = 255 * wh - m_x_y_tmp; + // } + double m_x_y = m_x_y_tmp / wh; # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG @@ -130,6 +136,11 @@ namespace scribo - squared.at_(row_max, col_min) - squared.at_(row_min, col_max)); + // if (!skewness_pbm(p)) + // { + // s_x_y_tmp = std::pow(255, 2) * wh - s_x_y_tmp; + // } + double s_x_y = std::sqrt((s_x_y_tmp - (m_x_y_tmp * m_x_y_tmp) / wh) / (wh - 1.f)); # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG @@ -140,7 +151,7 @@ namespace scribo // Thresholding. // skewness_ = skewness(p); // b = (p == point2d(5,5)); - double t_x_y = formula(m_x_y, s_x_y, K, R); + double t_x_y = formula(p, m_x_y, s_x_y, K, R); # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG double alpha = K * (1 - s_x_y / R); diff --git a/scribo/scribo/binarization/internal/first_pass_functor.hh b/scribo/scribo/binarization/internal/first_pass_functor.hh index 8da401b..f0ae5a9 100644 --- a/scribo/scribo/binarization/internal/first_pass_functor.hh +++ b/scribo/scribo/binarization/internal/first_pass_functor.hh @@ -132,7 +132,7 @@ namespace scribo unsigned p = pxl.offset(); value::int_u8 t_p; - mln::convert::from_to(formula_(mean, stddev, K_, R_), + mln::convert::from_to(formula_(input.point_at_index(p), mean, stddev, K_, R_), t_p); msk.element(p) = input.element(p) < t_p; diff --git a/scribo/scribo/binarization/internal/sauvola_formula.hh b/scribo/scribo/binarization/internal/sauvola_formula.hh index adbef13..e010e85 100644 --- a/scribo/scribo/binarization/internal/sauvola_formula.hh +++ b/scribo/scribo/binarization/internal/sauvola_formula.hh @@ -46,6 +46,10 @@ # define SCRIBO_DEFAULT_SAUVOLA_R 128 +#include <mln/core/alias/point2d.hh> + +extern mln::image2d<bool> skewness_pbm; + namespace scribo { @@ -55,6 +59,8 @@ namespace scribo namespace internal { + using namespace mln; + struct sauvola_formula { @@ -70,13 +76,13 @@ namespace scribo \return A threshold. */ - double operator()(const double m_x_y, const double s_x_y, + double operator()(const point2d& p, const double m_x_y, const double s_x_y, const double K, const double R) const; /*! \overload K = 0.34 and R = 128. */ - double operator()(const double m_x_y, const double s_x_y) const; + double operator()(const point2d& p, const double m_x_y, const double s_x_y) const; }; @@ -88,7 +94,7 @@ namespace scribo inline double - sauvola_formula::operator()(const double m_x_y, const double s_x_y, + sauvola_formula::operator()(const point2d& p, const double m_x_y, const double s_x_y, const double K, const double R) const { // if (b) @@ -98,15 +104,17 @@ namespace scribo // if (skewness_ > 0) // if (new_t != old_t) // std::cout << skewness_ << " - " << new_t << " vs " << old_t << std::endl; - - return m_x_y * (1.0 + K * ((s_x_y / R) - 1.0)); + if (skewness_pbm(p)) + return m_x_y * (1.0 + K * ((s_x_y / R) - 1.0)); + else + return (255 - m_x_y) * (1.0 + K * ((s_x_y / R) - 1.0)); } inline double - sauvola_formula::operator()(const double m_x_y, const double s_x_y) const + sauvola_formula::operator()(const point2d& p, const double m_x_y, const double s_x_y) const { - return (*this)(m_x_y, s_x_y, + return (*this)(p, m_x_y, s_x_y, SCRIBO_DEFAULT_SAUVOLA_K, SCRIBO_DEFAULT_SAUVOLA_R); } diff --git a/scribo/scribo/binarization/local_threshold.hh b/scribo/scribo/binarization/local_threshold.hh index 9d116ed..ab589e2 100644 --- a/scribo/scribo/binarization/local_threshold.hh +++ b/scribo/scribo/binarization/local_threshold.hh @@ -34,12 +34,13 @@ /// /// \brief Binarize an image using a threshold image. +extern mln::image2d<bool> skewness_pbm; + namespace scribo { using namespace mln; - namespace binarization { @@ -110,8 +111,10 @@ namespace scribo mln_piter(I) p(input.domain()); for_all(p) - output(p) = (input(p) <= threshold(p)); - + if (skewness_pbm(p)) + output(p) = (input(p) <= threshold(p)); + else + output(p) = ((255 - input(p)) <= threshold(p)); trace::exiting("scribo::binarization::impl::generic::local_threshold"); return output; @@ -132,6 +135,8 @@ namespace scribo const I& input = exact(input_); const T& threshold = exact(threshold_); + border::resize(::skewness_pbm, input.border()); + typedef mln_ch_value(I, bool) O; O output; initialize(output, input); @@ -139,8 +144,12 @@ namespace scribo mln_pixter(const I) pi(input); mln_pixter(const T) pt(threshold); mln_pixter(O) po(output); + for_all_3(pi, pt, po) - po.val() = pi.val() <= pt.val(); + if (skewness_pbm.element(pi.offset())) + po.val() = (pi.val() <= pt.val()); + else + po.val() = ((255 - pi.val()) <= pt.val()); trace::exiting("scribo::binarization::impl::generic::local_threshold_fastest"); return output; @@ -159,7 +168,7 @@ namespace scribo template <typename I, typename T> mln_ch_value(I, bool) - local_threshold_dispatch(trait::image::value_alignment::any, + local_threshold_dispatch(trait::image::speed::any, trait::image::speed::any, const Image<I>& input, const Image<T>& threshold) { @@ -169,7 +178,7 @@ namespace scribo template <typename I, typename T> mln_ch_value(I, bool) - local_threshold_dispatch(trait::image::value_alignment::with_grid, + local_threshold_dispatch(trait::image::speed::fastest, trait::image::speed::fastest, const Image<I>& input, const Image<T>& threshold) { @@ -181,9 +190,9 @@ namespace scribo local_threshold_dispatch(const Image<I>& input, const Image<T>& threshold) { - return local_threshold_dispatch(mln_trait_image_value_alignment(I)(), - mln_trait_image_speed(I)(), - exact(input), exact(threshold)); + return local_threshold_dispatch(mln_trait_image_speed(I)(), + mln_trait_image_speed(T)(), + input, threshold); } } // end of namespace scribo::binarization::internal -- 1.7.2.5
12 years, 4 months
1
0
0
0
olena-2.0-73-g241d1ff Add new tools.
by Guillaume Lazzara
* z/sauvola_ms_rv/pgm_color_diff.cc, * z/sauvola_ms_rv/pgm_local_mean.cc, * z/sauvola_ms_rv/ppm_influence_zone_geodesic.cc: New. --- scribo/sandbox/ChangeLog | 8 +++ scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc | 60 ++++++++++++++++++++ scribo/sandbox/z/sauvola_ms_rv/pgm_local_mean.cc | 29 ++++++++++ .../z/sauvola_ms_rv/ppm_influence_zone_geodesic.cc | 24 ++++++++ 4 files changed, 121 insertions(+), 0 deletions(-) create mode 100644 scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc create mode 100644 scribo/sandbox/z/sauvola_ms_rv/pgm_local_mean.cc create mode 100644 scribo/sandbox/z/sauvola_ms_rv/ppm_influence_zone_geodesic.cc diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog index 8cfe592..446cae0 100644 --- a/scribo/sandbox/ChangeLog +++ b/scribo/sandbox/ChangeLog @@ -1,5 +1,13 @@ 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + Add new tools. + + * z/sauvola_ms_rv/pgm_color_diff.cc, + * z/sauvola_ms_rv/pgm_local_mean.cc, + * z/sauvola_ms_rv/ppm_influence_zone_geodesic.cc: New. + +2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + Rename skewness directory and share code between implementations. * z/skewness/skewness.cc, diff --git a/scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc b/scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc new file mode 100644 index 0000000..7474c46 --- /dev/null +++ b/scribo/sandbox/z/sauvola_ms_rv/pgm_color_diff.cc @@ -0,0 +1,60 @@ +#include <mln/core/concept/function.hh> +#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/ppm/save.hh> +#include <mln/data/transform.hh> +#include <mln/arith/minus.hh> + +namespace mln +{ + + struct color_diff : Function_v2v<color_diff> + { + typedef value::rgb8 result; + + color_diff(int threshold) : threshold_(threshold) {} + + value::rgb8 operator()(const int& v) const + { + int v_d2 = std::abs(v / 2); + + if (v >= -threshold_ && v <= threshold_) + return value::rgb8(255, 255, 255); + else if (v > threshold_) + return value::rgb8(v_d2, 128 + v_d2, v_d2); + else + return value::rgb8(128 + v_d2, v_d2, v_d2); + } + + + int threshold_; + }; + +} + + +int main(int argc, char *argv[]) +{ + using namespace mln; + + + if (argc != 5) + { + std::cout << "Usage: " << argv[0] << " in.pgm ref.pgm threshold out.ppm" << std::endl; + return 1; + } + + image2d<value::int_u8> input, ref; + + io::pgm::load(input, argv[1]); + io::pgm::load(ref, argv[2]); + + image2d<int> diff = input - ref; + + color_diff f(atoi(argv[3])); + image2d<value::rgb8> result = data::transform(diff, f); + + io::ppm::save(result, argv[4]); +} diff --git a/scribo/sandbox/z/sauvola_ms_rv/pgm_local_mean.cc b/scribo/sandbox/z/sauvola_ms_rv/pgm_local_mean.cc new file mode 100644 index 0000000..06c51e9 --- /dev/null +++ b/scribo/sandbox/z/sauvola_ms_rv/pgm_local_mean.cc @@ -0,0 +1,29 @@ +#include <mln/core/image/image2d.hh> +#include <mln/io/pgm/load.hh> +#include <mln/io/pgm/save.hh> +#include <mln/value/int_u8.hh> +#include <mln/data/compute_in_window.hh> +#include <mln/accu/stat/mean.hh> +#include <mln/win/rectangle2d.hh> +#include <mln/data/convert.hh> + +int main(int argc, char *argv[]) +{ + using namespace mln; + + if (argc != 4) + { + std::cout << "Usage: " << argv[0] << " in.pgm win_size out.pgm" << std::endl; + return 1; + } + + unsigned win_size = atoi(argv[2]); + win::rectangle2d win(win_size, win_size); + typedef value::int_u8 V; + image2d<V> input; + io::pgm::load(input, argv[1]); + + image2d<float> mean = data::compute_in_window(accu::stat::mean<V>(), input, win); + + io::pgm::save(data::convert(value::int_u8(), mean), argv[3]); +} diff --git a/scribo/sandbox/z/sauvola_ms_rv/ppm_influence_zone_geodesic.cc b/scribo/sandbox/z/sauvola_ms_rv/ppm_influence_zone_geodesic.cc new file mode 100644 index 0000000..f7b66b7 --- /dev/null +++ b/scribo/sandbox/z/sauvola_ms_rv/ppm_influence_zone_geodesic.cc @@ -0,0 +1,24 @@ +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/value/rgb8.hh> +#include <mln/transform/influence_zone_geodesic.hh> +#include <mln/io/ppm/all.hh> + + +int main(int argc, char *argv[]) +{ + using namespace mln; + + if (argc != 3) + { + std::cout << argv[0] << " input.ppm output.ppm" << std::endl; + return 1; + } + + image2d<value::rgb8> input; + io::ppm::load(input, argv[1]); + + image2d<value::rgb8> iz = transform::influence_zone_geodesic(input, c8()); + + io::ppm::save(iz, argv[2]); +} -- 1.7.2.5
12 years, 4 months
1
0
0
0
olena-2.0-72-ga07c8c6 Rename skewness directory and share code between implementations.
by Guillaume Lazzara
* z/skewness/skewness.cc, * z/skewness/skewness2.cc: Move... * z/sauvola_ms_rv/skewness.cc, * z/sauvola_ms_rv/skewness/skewness2.cc: ... Here. * z/sauvola_ms_rv/skewness/integral_browsing_rv.hh: Share code between the two implementations. --- scribo/sandbox/ChangeLog | 13 + .../z/{skewness => sauvola_ms_rv}/skewness.cc | 0 .../skewness/integral_browsing_rv.hh} | 135 ++++++------ .../sandbox/z/sauvola_ms_rv/skewness/skewness2.cc | 230 ++++++++++++++++++++ scribo/sandbox/z/skewness/skewness2.cc | 154 ------------- 5 files changed, 314 insertions(+), 218 deletions(-) rename scribo/sandbox/z/{skewness => sauvola_ms_rv}/skewness.cc (100%) copy scribo/{scribo/canvas/integral_browsing.hh => sandbox/z/sauvola_ms_rv/skewness/integral_browsing_rv.hh} (72%) create mode 100644 scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc delete mode 100644 scribo/sandbox/z/skewness/skewness2.cc diff --git a/scribo/sandbox/ChangeLog b/scribo/sandbox/ChangeLog index c87381c..8cfe592 100644 --- a/scribo/sandbox/ChangeLog +++ b/scribo/sandbox/ChangeLog @@ -1,5 +1,18 @@ 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + Rename skewness directory and share code between implementations. + + * z/skewness/skewness.cc, + * z/skewness/skewness2.cc: Move... + + * z/sauvola_ms_rv/skewness.cc, + * z/sauvola_ms_rv/skewness/skewness2.cc: ... Here. + + * z/sauvola_ms_rv/skewness/integral_browsing_rv.hh: Share code + between the two implementations. + +2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> + * z/skewness/skewness2.cc: New. 2012-08-23 Guillaume Lazzara <z(a)lrde.epita.fr> diff --git a/scribo/sandbox/z/skewness/skewness.cc b/scribo/sandbox/z/sauvola_ms_rv/skewness.cc similarity index 100% rename from scribo/sandbox/z/skewness/skewness.cc rename to scribo/sandbox/z/sauvola_ms_rv/skewness.cc diff --git a/scribo/scribo/canvas/integral_browsing.hh b/scribo/sandbox/z/sauvola_ms_rv/skewness/integral_browsing_rv.hh similarity index 72% copy from scribo/scribo/canvas/integral_browsing.hh copy to scribo/sandbox/z/sauvola_ms_rv/skewness/integral_browsing_rv.hh index 0ec3d83..79d5e34 100644 --- a/scribo/scribo/canvas/integral_browsing.hh +++ b/scribo/sandbox/z/sauvola_ms_rv/skewness/integral_browsing_rv.hh @@ -25,8 +25,8 @@ // executable file might be covered by the GNU General Public License. -#ifndef SCRIBO_CANVAS_INTEGRAL_BROWSING_HH -# define SCRIBO_CANVAS_INTEGRAL_BROWSING_HH +#ifndef SCRIBO_CANVAS_INTEGRAL_BROWSING_RV_HH +# define SCRIBO_CANVAS_INTEGRAL_BROWSING_RV_HH # include <mln/core/image/image2d.hh> # include <mln/util/couple.hh> @@ -40,10 +40,10 @@ namespace scribo template <typename F> - void integral_browsing(const image2d<mln::util::couple<double, double> >& ima, - unsigned step, - unsigned w, unsigned h, - F& functor); + void integral_browsing_rv(const image2d<mln::util::couple<double, mln::util::couple<double, double> > >& ima, + unsigned step, + unsigned w, unsigned h, + F& functor); # ifndef MLN_INCLUDE_ONLY @@ -54,19 +54,15 @@ namespace scribo inline void compute_stats(// in - double sum, double sum_2, unsigned n, + double sum, double sum_2, double sum_3, unsigned n, // out - double& mean, double& stddev) + double& skewness) { - mean = sum / n; - - // unbias version: - double num = (sum_2 - sum * sum / n); - if (num > 0) - stddev = std::sqrt(num / (n - 1)); - else - stddev = 0; + // Mean + double mean = sum / n; + // Skewness + skewness = (sum_3 - 3. * mean * sum_2) / (double) n + 2. * std::pow(mean, 3); } } // end of namespace scribo::canvas::internal @@ -75,13 +71,13 @@ namespace scribo template <typename F> - void integral_browsing(const image2d<mln::util::couple<double, double> >& ima, - unsigned step, - unsigned w, unsigned h, - unsigned s, - F& functor) + void integral_browsing_rv(const image2d<mln::util::couple<double, mln::util::couple<double, double> > >& ima, + unsigned w, unsigned h, + F& functor) { - typedef mln::util::couple<double, double> V; + unsigned step = 1; + + typedef mln::util::couple<double, mln::util::couple<double, double> > V; typedef const V* Ptr; Ptr a_ima, b_ima, c_ima, d_ima; @@ -121,9 +117,8 @@ namespace scribo b_ml_start = 0, d_ml_start = 0, b_mr_start = 0, d_mr_start = 0, b_bl_start = 0, d_bl_start = 0, b_br_start = 0, d_br = 0; - double mean, stddev; + double skewness; - unsigned s_2 = s * s; // ------------------------------- // T (top) @@ -157,10 +152,11 @@ namespace scribo { // D internal::compute_stats(d_ima->first(), - d_ima->second(), - size_tl * s_2, - mean, stddev); - functor.exec(mean, stddev); + d_ima->second().first(), + d_ima->second().second(), + size_tl, + skewness); + functor.exec(skewness); d_ima += step; size_tl += delta_size_tl; } @@ -177,10 +173,11 @@ namespace scribo { // D - C internal::compute_stats(d_ima->first() - c_ima->first(), - d_ima->second() - c_ima->second(), - size_tc * s_2, - mean, stddev); - functor.exec(mean, stddev); + d_ima->second().first() - c_ima->second().first(), + d_ima->second().second() - c_ima->second().second(), + size_tc, + skewness); + functor.exec(skewness); c_ima += step; d_ima += step; } @@ -192,17 +189,19 @@ namespace scribo d_ima = d_tr_start; double d_sum = d_ima->first(), - d_sum_2 = d_ima->second(); + d_sum_2 = d_ima->second().first(), + d_sum_3 = d_ima->second().second(); size_tr = size_tr_start; for (; col < ncols; col += step) { // D* - C internal::compute_stats(d_sum - c_ima->first(), - d_sum_2 - c_ima->second(), - size_tr * s_2, - mean, stddev); - functor.exec(mean, stddev); + d_sum_2 - c_ima->second().first(), + d_sum_3 - c_ima->second().second(), + size_tr, + skewness); + functor.exec(skewness); c_ima += step; size_tr -= delta_size_tr; } @@ -249,10 +248,11 @@ namespace scribo { // D - B internal::compute_stats(d_ima->first() - b_ima->first(), - d_ima->second() - b_ima->second(), - size_ml * s_2, - mean, stddev); - functor.exec(mean, stddev); + d_ima->second().first() - b_ima->second().first(), + d_ima->second().second() - b_ima->second().second(), + size_ml, + skewness); + functor.exec(skewness); b_ima += step; d_ima += step; size_ml += h_step; @@ -271,11 +271,12 @@ namespace scribo // D + A - B - C 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()), - size_mc * s_2, - mean, stddev); + (d_ima->second().first() - b_ima->second().first()) + (a_ima->second().first() - c_ima->second().first()), + (d_ima->second().second() - b_ima->second().second()) + (a_ima->second().second() - c_ima->second().second()), + size_mc, + skewness); - functor.exec(mean, stddev); + functor.exec(skewness); a_ima += step; b_ima += step; @@ -290,16 +291,18 @@ namespace scribo d_ima = d_mr_start; double d_b_sum = d_ima->first() - b_ima->first(), - d_b_sum_2 = d_ima->second() - b_ima->second(); + d_b_sum_2 = d_ima->second().first() - b_ima->second().first(), + d_b_sum_3 = d_ima->second().second() - b_ima->second().second(); for (; col < ncols; col += step) { // D* + A - B* - C internal::compute_stats(d_b_sum + (a_ima->first() - c_ima->first()), - d_b_sum_2 + (a_ima->second() - c_ima->second()), - size_mr * s_2, - mean, stddev); - functor.exec(mean, stddev); + d_b_sum_2 + (a_ima->second().first() - c_ima->second().first()), + d_b_sum_3 + (a_ima->second().second() - c_ima->second().second()), + size_mr, + skewness); + functor.exec(skewness); a_ima += step; c_ima += step; size_mr -= h_step; @@ -345,10 +348,11 @@ namespace scribo { // D* - B internal::compute_stats(d_ima->first() - b_ima->first(), - d_ima->second() - b_ima->second(), - size_bl * s_2, - mean, stddev); - functor.exec(mean, stddev); + d_ima->second().first() - b_ima->second().first(), + d_ima->second().second() - b_ima->second().second(), + size_bl, + skewness); + functor.exec(skewness); b_ima += step; d_ima += step; size_bl += delta_size_bl; @@ -367,10 +371,11 @@ namespace scribo { // D* + A - B - C* 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()), - size_bc * s_2, - mean, stddev); - functor.exec(mean, stddev); + (d_ima->second().first() - b_ima->second().first()) + (a_ima->second().first() - c_ima->second().first()), + (d_ima->second().second() - b_ima->second().second()) + (a_ima->second().second() - c_ima->second().second()), + size_bc, + skewness); + functor.exec(skewness); a_ima += step; b_ima += step; c_ima += step; @@ -386,16 +391,18 @@ namespace scribo d_ima = d_br; double d_b_sum = d_ima->first() - b_ima->first(), - d_b_sum_2 = d_ima->second() - b_ima->second(); + d_b_sum_2 = d_ima->second().first() - b_ima->second().first(), + d_b_sum_3 = d_ima->second().second() - b_ima->second().second(); for (; col < ncols; col += step) { // D* + A - B* - C* internal::compute_stats(d_b_sum + (a_ima->first() - c_ima->first()), - d_b_sum_2 + (a_ima->second() - c_ima->second()), - size_br * s_2, - mean, stddev); - functor.exec(mean, stddev); + d_b_sum_2 + (a_ima->second().first() - c_ima->second().first()), + d_b_sum_3 + (a_ima->second().second() - c_ima->second().second()), + size_br, + skewness); + functor.exec(skewness); a_ima += step; c_ima += step; size_br -= delta_size_br; @@ -417,4 +424,4 @@ namespace scribo } // end of namespace mln -#endif // ! SCRIBO_CANVAS_INTEGRAL_BROWSING_HH +#endif // ! SCRIBO_CANVAS_INTEGRAL_BROWSING_RV_HH diff --git a/scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc b/scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc new file mode 100644 index 0000000..043e0ad --- /dev/null +++ b/scribo/sandbox/z/sauvola_ms_rv/skewness/skewness2.cc @@ -0,0 +1,230 @@ +#include <mln/io/pgm/all.hh> +#include <mln/io/pbm/all.hh> +#include <mln/core/image/dmorph/image_if.hh> +#include <mln/core/image/dmorph/sub_image.hh> +#include <mln/pw/all.hh> +#include <mln/value/int_u8.hh> +#include <mln/core/image/image2d.hh> +#include <mln/core/neighb.hh> +#include <mln/win/rectangle2d.hh> +#include <mln/extension/adjust.hh> +#include <mln/border/mirror.hh> +#include <mln/extension/duplicate.hh> +#include <mln/core/alias/window2d.hh> + +#include <mln/data/convert.hh> +#include <mln/data/stretch.hh> +#include <mln/debug/println.hh> +#include <mln/data/transform.hh> +#include <mln/io/dump/save.hh> +#include <mln/accu/math/sumpow.hh> +#include <mln/accu/stat/mean.hh> +#include <mln/data/compute_in_window.hh> +#include <mln/core/var.hh> +#include <mln/data/saturate.hh> +#include <mln/fun/v2b/threshold_le.hh> +#include <mln/arith/revert.hh> +#include <mln/util/timer.hh> + +mln::image2d<double> skewness; + +#include <scribo/binarization/sauvola_ms.hh> +#include "integral_browsing_rv.hh" + +mln::image2d<bool> skewness_pbm; +std::string prefix; + + +namespace scribo +{ + using namespace mln; + + template <typename I, typename J> + void + integral_rv(const Image<I>& input_, + Image<J>& integral_sum_sum_2_sum_3_) + { + trace::entering("subsampling::impl::integral_2"); + + const unsigned scale = 1; + + const I& input = exact(input_); + J& integral_sum_sum_2_sum_3 = exact(integral_sum_sum_2_sum_3_); + + typedef mln_value(I) V; + typedef mln_sum(V) S; + typedef mln_site(I) P; + typedef mln_value(J) V2; + + mlc_bool(P::dim == 2)::check(); + mln_precondition(input.is_valid()); + mln_precondition(input.domain().pmin() == literal::origin); + + initialize(integral_sum_sum_2_sum_3, input); + V2* p_integ = integral_sum_sum_2_sum_3.buffer(); + + const int up = integral_sum_sum_2_sum_3.delta_index(dpoint2d(-1, 0)); + + const unsigned nrows = input.nrows(); + const unsigned ncols = input.ncols(); + + unsigned border_thickness = input.border(); + unsigned b_offset = integral_sum_sum_2_sum_3.delta_index(dpoint2d(border_thickness, + border_thickness)); + p_integ += b_offset; + + unsigned row = 0; + { + S h_sum = 0, h_sum_2 = 0, h_sum_3 = 0; + const V* ptr1 = & input.at_(row, 0); + for (unsigned col = 0; col < ncols; ++col) + { + V v11 = *ptr1++; + h_sum += v11; + h_sum_2 += v11 * v11; + h_sum_3 += v11 * v11 * v11; + + // exception + p_integ->first() = h_sum; + p_integ->second().first() = h_sum_2; + p_integ->second().second() = h_sum_3; + + ++p_integ; + } + } + + unsigned b_next = 2 * border_thickness; + + p_integ += b_next; + + for (row += scale; row < nrows; ++row) + { + S h_sum = 0, h_sum_2 = 0, h_sum_3 = 0; + const V* ptr1 = & input.at_(row, 0); + for (unsigned col = 0; col < ncols; ++col) + { + V v11 = *ptr1++; + h_sum += v11; + h_sum_2 += v11 * v11; + h_sum_3 += v11 * v11 * v11; + + p_integ->first() = h_sum + (p_integ + up)->first(); + p_integ->second().first() = h_sum_2 + (p_integ + up)->second().first(); + p_integ->second().second() = h_sum_3 + (p_integ + up)->second().second(); + + ++p_integ; + } + + p_integ += b_next; + } + + trace::exiting("subsampling::impl::integral_2"); + } + +} // end of namespace scribo + + +namespace mln +{ + + template <typename I> + struct invert_on_skewness + { + I input; + image2d<double> skewness_; + mln_fwd_pixter(I) pxl; + + invert_on_skewness(const I& input_) + : input(duplicate(input_)), + pxl(input) + { + pxl.start(); + initialize(skewness_, input); + } + + void exec(double skewness) + { + skewness_.element(pxl.offset()) = skewness; + + if (skewness > 1000.) + pxl.val() = 255 - pxl.val(); + + pxl.next(); // next pixel + } + + void finalize() + { + } + }; + +} + +int main(int argc, char *argv[]) +{ + using namespace mln; + + if (argc != 4) + { + std::cerr << "Usage: " << argv[0] << " <input.pgm> <prefix> <win_size>" << std::endl; + return 1; + } + + util::timer tt; + tt.start(); + util::timer t; + + t.start(); + image2d<value::int_u8> input; + io::pgm::load(input, argv[1]); + + prefix = argv[2]; + + int win_size = atoi(argv[3]); + t.stop(); + std::cout << "Initialization - " << t << std::endl; + + // invert data if skewness > 0 + t.restart(); + + image2d<util::couple<double, util::couple<double, double> > > integral_sum_sum_2_sum_3; + scribo::integral_rv(input, integral_sum_sum_2_sum_3); + + invert_on_skewness<image2d<value::int_u8> > f(input); + scribo::canvas::integral_browsing_rv(integral_sum_sum_2_sum_3, win_size, win_size, f); + + t.stop(); + std::cout << "invert on skewness - " << t << std::endl; + + io::dump::save(f.skewness_, prefix + "skewness.dump"); + + t.restart(); + image2d<bool> bin = scribo::binarization::sauvola_ms(f.input, 101, 2); + std::cout << "sauvola_ms - " << t << std::endl; + + + std::cout << "Total time : " << tt << std::endl; + // prefix += "i_"; + + // image2d<bool> bin_i = scribo::binarization::sauvola(arith::revert(input), 51); + + // prefix = argv[2]; + + io::pbm::save(bin, prefix + "bin.pbm"); + // io::pbm::save(bin_i, prefix + "bin_i.pbm"); + + // image2d<bool> out; + // initialize(out, bin); + // mln_piter_(image2d<bool>) p(out.domain()); + // for_all(p) + // if (skewness_pbm(p)) + // out(p) = bin(p); + // else + // out(p) = bin_i(p); + + // io::pbm::save(out, prefix + "output.pbm"); + + // io::dump::save(scribo::binarization::internal::debug_stddev, prefix + "stddev.dump"); + // io::dump::save(scribo::binarization::internal::debug_mean, prefix + "mean.dump"); + // io::dump::save(scribo::binarization::internal::debug_threshold, prefix + "threshold.dump"); + +} diff --git a/scribo/sandbox/z/skewness/skewness2.cc b/scribo/sandbox/z/skewness/skewness2.cc deleted file mode 100644 index 642ae3f..0000000 --- a/scribo/sandbox/z/skewness/skewness2.cc +++ /dev/null @@ -1,154 +0,0 @@ -#include <mln/io/pgm/all.hh> -#include <mln/io/pbm/all.hh> -#include <mln/core/image/dmorph/image_if.hh> -#include <mln/core/image/dmorph/sub_image.hh> -#include <mln/pw/all.hh> -#include <mln/value/int_u8.hh> -#include <mln/core/image/image2d.hh> -#include <mln/core/neighb.hh> -#include <mln/win/rectangle2d.hh> -#include <mln/extension/adjust.hh> -#include <mln/border/mirror.hh> -#include <mln/extension/duplicate.hh> -#include <mln/core/alias/window2d.hh> - -#include <mln/data/convert.hh> -#include <mln/data/stretch.hh> -#include <mln/debug/println.hh> -#include <mln/data/transform.hh> -#include <mln/io/dump/save.hh> -#include <mln/accu/math/sumpow.hh> -#include <mln/accu/stat/mean.hh> -#include <mln/data/compute_in_window.hh> -#include <mln/core/var.hh> -#include <mln/data/saturate.hh> -#include <mln/fun/v2b/threshold_le.hh> -#include <mln/arith/revert.hh> -#include <mln/util/timer.hh> - -mln::image2d<double> skewness; - -#include <scribo/binarization/sauvola_ms.hh> - -mln::image2d<bool> skewness_pbm; -std::string prefix; - - -int main(int argc, char *argv[]) -{ - using namespace mln; - - if (argc != 4) - { - std::cerr << "Usage: " << argv[0] << " <input.pgm> <prefix> <win_size>" << std::endl; - return 1; - } - - util::timer tt; - tt.start(); - util::timer t; - - t.start(); - image2d<value::int_u8> input; - io::pgm::load(input, argv[1]); - - prefix = argv[2]; - - int win_size = atoi(argv[3]); - win::rectangle2d wr = win::rectangle2d(win_size,win_size); - window2d win; - win.insert(wr); - - accu::pair<accu::stat::mean<value::int_u8,double>, - accu::pair<accu::math::sumpow<2,value::int_u8,double>, - accu::math::sumpow<3,value::int_u8,double> > > accu; - t.stop(); - std::cout << "initialization - " << t << std::endl; - - - t.restart(); - mln_VAR(res, data::compute_in_window(accu, input, win)); - t.stop(); - std::cout << "compute in window - " << t << std::endl; - - initialize(skewness, res); - data::fill(skewness, 0); - - - point2d pc = input.domain().pcenter(); - std::cout << pc << " - sum_2 = " << res(pc).second.first << " - sum_3 = " << res(pc).second.second << " - mean = " << res(pc).first << std::endl; - - t.restart(); - { - int n; - mln_pixter_(image2d<double>) p(skewness); - for_all(p) - { - n = win.size(); - mln_VAR(d, res.element(p.offset())); - double m = d.first; - double sum_3 = d.second.second; - double sum_2 = d.second.first; - p.val() = (sum_3 - 3. * m * sum_2) / (double) n + 2. * std::pow(m, 3); - } - } - t.stop(); - std::cout << "Compute unskew - " << t << std::endl; - - - // t.restart(); - // skewness_pbm = data::transform(skewness, fun::v2b::threshold_le<double>(0)); - // t.stop(); - // std::cout << "binarize - " << t << std::endl; - - // { - // io::dump::save(skewness, prefix + "skewness.dump"); - // io::pgm::save(data::convert(value::int_u8(), skewness), prefix + "skewness_u8.pgm"); - // io::pgm::save(data::stretch(value::int_u8(), skewness), prefix + "skewness_stretch.pgm"); - // io::pbm::save(skewness_pbm, prefix + "skewness.pbm"); - // } - - t.restart(); - { - border::resize(skewness, input.border()); - mln_pixter_(image2d<value::int_u8>) p(input); - for_all(p) - { - if (skewness.element(p.offset()) > 0) - p.val() = mln_max(value::int_u8) - p.val(); - } - } - t.stop(); - std::cout << "Negate parts of input image - " << t << std::endl; - - t.restart(); - image2d<bool> bin = scribo::binarization::sauvola_ms(input, 101, 2); - std::cout << "sauvola_ms - " << t << std::endl; - - - std::cout << "Total time : " << tt << std::endl; - // prefix += "i_"; - - // image2d<bool> bin_i = scribo::binarization::sauvola(arith::revert(input), 51); - - // prefix = argv[2]; - - io::pbm::save(bin, prefix + "bin.pbm"); - // io::pbm::save(bin_i, prefix + "bin_i.pbm"); - - // image2d<bool> out; - // initialize(out, bin); - // mln_piter_(image2d<bool>) p(out.domain()); - // for_all(p) - // if (skewness_pbm(p)) - // out(p) = bin(p); - // else - // out(p) = bin_i(p); - - // io::pbm::save(out, prefix + "output.pbm"); - - // io::dump::save(scribo::binarization::internal::debug_stddev, prefix + "stddev.dump"); - // io::dump::save(scribo::binarization::internal::debug_mean, prefix + "mean.dump"); - // io::dump::save(scribo::binarization::internal::debug_threshold, prefix + "threshold.dump"); - -} -- 1.7.2.5
12 years, 4 months
1
0
0
0
← Newer
1
...
6
7
8
9
10
11
12
13
14
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Results per page:
10
25
50
100
200