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
June 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
6 participants
147 discussions
Start a n
N
ew thread
olena-2.0-78-gb781ec6 Very fast classic sauvola.
by Guillaume Lazzara
--- scribo/sauvola_fast.cc | 118 +++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 116 insertions(+), 2 deletions(-) diff --git a/scribo/sauvola_fast.cc b/scribo/sauvola_fast.cc index 95e49b2..ed4e6d4 100644 --- a/scribo/sauvola_fast.cc +++ b/scribo/sauvola_fast.cc @@ -83,6 +83,117 @@ 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_) { @@ -165,7 +276,10 @@ namespace mln util::timer t; t.start(); image2d<util::couple<double,double> > integral; - init_integral(input, integral); + init_integral_3(input, integral); + + // image2d<value::int_u8> sub = scribo::subsampling::integral(input, 3, integral); + t.stop(); std::cout << "image integrale - " << t << std::endl; @@ -173,7 +287,7 @@ namespace mln 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, 3, win, win, 1, f); + scribo::canvas::integral_browsing(integral, 1, win / 3, win / 3, 3, f); t.stop(); std::cout << "Binarization - " << t << std::endl; -- 1.7.2.5
12 years, 6 months
1
0
0
0
olena-2.0-77-g3ca5ebf Working optimized sauvola classic
by Guillaume Lazzara
--- scribo/sauvola_fast.cc | 85 +++++++++++++++++++++++++++++++---------------- 1 files changed, 56 insertions(+), 29 deletions(-) diff --git a/scribo/sauvola_fast.cc b/scribo/sauvola_fast.cc index 8018135..95e49b2 100644 --- a/scribo/sauvola_fast.cc +++ b/scribo/sauvola_fast.cc @@ -17,43 +17,63 @@ namespace mln typedef mln_ch_value(I,bool) bin_t; bin_t bin; - mln_fwd_pixter(const I) pi; - mln_fwd_pixter(bin_t) po; + image2d<double> th_; + + const mln_value(I)* pi; + bool* po; double K_; double R_; scribo::binarization::internal::sauvola_formula formula_; - unsigned count_; + 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) : input(input_), bin(bin_), - pi(input), - po(bin), + pi(&input(input.domain().pmin())), + po(&bin(bin.domain().pmin())), K_(K), R_(R) { - pi.start(); - po.start(); - count_ = 0; + step_ = 3; + 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; + + offset1 = input.delta_index(dpoint2d(+1,0)); + offset2 = input.delta_index(dpoint2d(+2,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 + double th = formula_(p, mean, stddev, K_, R_); + + for (int i = 0; i < step_; ++i, ++po, ++pi) + { + *po = (*pi <= th); + *(po + offset1) = (*(pi + offset1) <= th); + *(po + offset2) = (*(pi + offset2) <= th); + } + } - ++count_; + void end_of_row(int) + { + po += next_line3; + pi += next_line3; } + void finalize() { - std::cout << input.domain().nsites() << " - " << input.domain().nrows() * input.domain().ncols() << " - " << count_ << std::endl; } }; @@ -64,7 +84,7 @@ namespace mln template <typename I, typename J> void init_integral(const Image<I>& input_, - Image<J>& integral_sum_sum_2_) + Image<J>& integral_sum_sum_2_) { trace::entering("subsampling::impl::integral_3"); @@ -90,23 +110,23 @@ namespace mln unsigned row = 0; unsigned b_offset = input.delta_index(dpoint2d(input.border(), - 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++; + V v = *ptr1++; - h_sum += v; - h_sum_2 += v * v; + h_sum += v; + h_sum_2 += v * v; - // exception - p_integ->first() = h_sum; - p_integ->second() = h_sum_2; + // exception + p_integ->first() = h_sum; + p_integ->second() = h_sum_2; - ++p_integ; + ++p_integ; } } @@ -120,15 +140,15 @@ namespace mln const V* ptr1 = & input.at_(row, 0); for (unsigned col = 0; col < ncols; ++col) { - V v = *ptr1++; + V v = *ptr1++; - h_sum += v; - h_sum_2 += v * v; + 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->first() = h_sum + (p_integ + up)->first(); + p_integ->second() = h_sum_2 + (p_integ + up)->second(); - ++p_integ; + ++p_integ; } p_integ += b_next; @@ -142,13 +162,20 @@ namespace mln 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(input, integral); + t.stop(); + std::cout << "image integrale - " << t << std::endl; + 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); - scribo::canvas::integral_browsing(integral, 1, win, win, 1, f); + scribo::canvas::integral_browsing(integral, 3, win, win, 1, f); + t.stop(); + std::cout << "Binarization - " << t << std::endl; return f.bin; } -- 1.7.2.5
12 years, 6 months
1
0
0
0
olena-2.0-76-gb98b0d1 backup
by Guillaume Lazzara
--- scribo/sauvola_fast.cc | 175 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 175 insertions(+), 0 deletions(-) create mode 100644 scribo/sauvola_fast.cc 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, 6 months
1
0
0
0
olena-2.0-74-g574c613 backup
by Guillaume Lazzara
--- .../sandbox/z/sauvola_ms_rv/skewness/skewness2.cc | 2 ++ scribo/scribo/binarization/sauvola_threshold.hh | 6 +++++- 2 files changed, 7 insertions(+), 1 deletions(-) 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; 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, 6 months
1
0
0
0
olena-2.0-73-g07c26a2 BACKUP - fixed by theo
by Guillaume Lazzara
T = (255 - m) * alpha si (255 - f(p)) < T -> noir sinon -> blanc --- .../sandbox/z/sauvola_ms_rv/skewness/skewness2.cc | 31 +++++++++++++------- .../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, 67 insertions(+), 30 deletions(-) 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; 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, 6 months
1
0
0
0
olena-2.0-72-gbd5b77d backup - fast multiscale binarization + skewness/revert on input image.
by Guillaume Lazzara
--- 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 ++ .../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 ------------- 7 files changed, 414 insertions(+), 218 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 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/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]); +} 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, 6 months
1
0
0
0
olena-2.0-71-ge69e187 Working sauvola_ms_rv
by Guillaume Lazzara
--- scribo/sandbox/z/skewness/skewness2.cc | 154 ++++++++++++++++++++++++++++++++ 1 files changed, 154 insertions(+), 0 deletions(-) create mode 100644 scribo/sandbox/z/skewness/skewness2.cc diff --git a/scribo/sandbox/z/skewness/skewness2.cc b/scribo/sandbox/z/skewness/skewness2.cc new file mode 100644 index 0000000..642ae3f --- /dev/null +++ b/scribo/sandbox/z/skewness/skewness2.cc @@ -0,0 +1,154 @@ +#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, 6 months
1
0
0
0
olena-2.0-70-g62c6860 BACKUP
by Guillaume Lazzara
--- milena/mln/data/compute_in_window.hh | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-) diff --git a/milena/mln/data/compute_in_window.hh b/milena/mln/data/compute_in_window.hh index 297a923..c47501c 100644 --- a/milena/mln/data/compute_in_window.hh +++ b/milena/mln/data/compute_in_window.hh @@ -23,8 +23,8 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_DATA_COMPUTE_HH -# define MLN_DATA_COMPUTE_HH +#ifndef MLN_DATA_COMPUTE_IN_WINDOW_HH +# define MLN_DATA_COMPUTE_IN_WINDOW_HH /// \file /// @@ -76,10 +76,13 @@ namespace mln compute_in_window_tests(const Accumulator<A>& a, const Image<I>& input_, const Window<W>& win_) { - (void) a; const W& win = exact(win_); const I& input = exact(input_); + (void) a; + (void) win; + (void) input; + mln_assertion(win.is_valid()); mln_assertion(input.is_valid()); } @@ -142,15 +145,15 @@ namespace mln internal::compute_in_window_tests(a, input, win); + extension::adjust(input, win); + border::mirror(input); + typedef mln_ch_value(I, A) J; J accu; initialize(accu, input); accu::image::init(accu); - extension::adjust(input, win); - border::mirror(input); - mln_pixter(J) p(accu); mln_qixter(J, W) q(p, win); @@ -245,4 +248,4 @@ namespace mln } // end of namespace mln -#endif // ! MLN_DATA_COMPUTE_HH +#endif // ! MLN_DATA_COMPUTE_IN_WINDOW_HH -- 1.7.2.5
12 years, 6 months
1
0
0
0
olena-2.0-69-gd60f027 Backup
by Guillaume Lazzara
--- scribo/sandbox/z/skewness/skewness.cc | 128 +++++++++++++++++++++++++++++++++ 1 files changed, 128 insertions(+), 0 deletions(-) create mode 100644 scribo/sandbox/z/skewness/skewness.cc diff --git a/scribo/sandbox/z/skewness/skewness.cc b/scribo/sandbox/z/skewness/skewness.cc new file mode 100644 index 0000000..0280fa3 --- /dev/null +++ b/scribo/sandbox/z/skewness/skewness.cc @@ -0,0 +1,128 @@ +#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/fun/v2b/threshold.hh> +#include <mln/io/dump/save.hh> + +mln::image2d<double> skewness; + +#include <scribo/binarization/sauvola.hh> + +namespace mln +{ + + template <typename T, typename N> + std::pair<image2d<double>, image2d<double> > + init_(const image2d<T>& ima, const N& nbh) + { + image2d<double> output_2, output_3; + initialize(output_2, ima); + initialize(output_3, ima); + extension::adjust(ima, nbh); + border::mirror(ima); + + typedef image2d<T> I; + mln_piter(I) p(ima.domain()); + mln_niter(N) n(nbh, p); + + extension::duplicate(ima); + + for_all(p) + { + double sum = ima(p); + for_all(n) + sum += ima(n); + + double mean = sum / (double)nbh.size(); + double + res_2 = std::pow(ima(p) - mean, 2), + res_3 = std::pow(ima(p) - mean, 3); + for_all(n) + { + res_2 += std::pow(ima(n) - mean, 2); + res_3 += std::pow(ima(n) - mean, 3); + } + + output_2(p) = res_2; + output_3(p) = res_3; + } + + return std::pair<image2d<double>, image2d<double> >(output_2, output_3); + } + + +} + + + +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; + } + + image2d<value::int_u8> input; + io::pgm::load(input, argv[1]); + std::string prefix = argv[2]; + + int win_size = atoi(argv[3]); + win::rectangle2d wr = win::rectangle2d(win_size,win_size); + window2d win; + win.insert(wr); + + std::pair<image2d<double>, image2d<double> > res_init = init_(input, neighb<window2d>(win)); + + image2d<double> x_mean_2 = res_init.first; + image2d<double> x_mean_3 = res_init.second; + + { + io::pgm::save(data::stretch(value::int_u8(), x_mean_2), prefix + "x_mean_2_stretch.pgm"); + io::pgm::save(data::stretch(value::int_u8(), x_mean_3), prefix + "x_mean_3_stretch.pgm"); + } + + + initialize(skewness, x_mean_2); + data::fill(skewness, 0); + + int n; + mln_piter_(image2d<double>) p(skewness.domain()); + for_all(p) + { + n = win.size(); + double frac = std::pow(std::sqrt((1.0/(double)n * x_mean_2(p))), 3); + skewness(p) = (std::sqrt(n * (n - 1)) / (n - 2)) * ((1.0/(double)n * x_mean_3(p)) / frac); + + // if (p == point2d(5, 5)) + // std::cout << p << " - " << std::setprecision(8) << (double)x_mean_3(p) << " - " << (double)x_mean_2(p) << " - " << skewness(p) << std::endl; + } + + + { + io::dump::save(skewness, prefix + "skewness.dump"); + io::pgm::save(data::convert(value::int_u8(), skewness), prefix + "skewness_u8.pgm"); + io::pbm::save(data::transform(skewness, fun::v2b::threshold<double>(0)), prefix + "skewness.pbm"); + io::pgm::save(data::stretch(value::int_u8(), skewness), prefix + "skewness_stretch.pgm"); + } + +// image2d<bool> bin = scribo::binarization::sauvola(input, 51); +// io::pbm::save(bin, "input.pbm"); +} -- 1.7.2.5
12 years, 6 months
1
0
0
0
olena-2.0-68-g3a65b8d Improve option parser.
by Guillaume Lazzara
* scribo/debug/option_check.hh: New function for verbose mode. * scribo/debug/option_parser.hh: Fix a bug with misplaced options. --- scribo/ChangeLog | 8 ++++++++ scribo/scribo/debug/option_check.hh | 19 ++++++++++++++++++- scribo/scribo/debug/option_parser.hh | 19 ++++++++++++++----- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 6a68f43..f8d7491 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,13 @@ 2012-05-10 Guillaume Lazzara <z(a)lrde.epita.fr> + Improve option parser. + + * scribo/debug/option_check.hh: New function for verbose mode. + + * scribo/debug/option_parser.hh: Fix a bug with misplaced options. + +2012-05-10 Guillaume Lazzara <z(a)lrde.epita.fr> + Add Readme files about contests. * src/contest/DAE-2011/README, diff --git a/scribo/scribo/debug/option_check.hh b/scribo/scribo/debug/option_check.hh index 4a0acd1..11cceb1 100644 --- a/scribo/scribo/debug/option_check.hh +++ b/scribo/scribo/debug/option_check.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2011, 2012 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of Olena. // @@ -31,6 +32,7 @@ # include <vector> # include <iostream> # include <mln/core/contract.hh> +# include <scribo/debug/logger.hh> namespace scribo { @@ -42,6 +44,7 @@ namespace scribo bool check_ocr_lang(const std::vector<const char *>& args); bool check_sauvola_first_subsampling(const std::vector<const char *>& args); bool check_sauvola_split_ntrue(const std::vector<const char *>& args); + bool check_verbose_mode(const std::vector<const char *>& args); # ifndef MLN_INCLUDE_ONLY @@ -121,6 +124,20 @@ namespace scribo } + inline + bool check_verbose_mode(const std::vector<const char *>& args) + { + mln_assertion(args.size() == 1); + + if (logger().set_verbose_mode(txt_to_verbose_mode(args[0]))) + return true; + + std::cerr << "Error: Invalid verbose mode " << args[0] << std::endl; + + return false; + } + + # endif // ! MLN_INCLUDE_ONLY } // end of namespace scribo::debug diff --git a/scribo/scribo/debug/option_parser.hh b/scribo/scribo/debug/option_parser.hh index 9795a78..c956064 100644 --- a/scribo/scribo/debug/option_parser.hh +++ b/scribo/scribo/debug/option_parser.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2011, 2012 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of Olena. // @@ -290,8 +291,17 @@ namespace scribo // I/O parameters default: - args_[arg_desc_[nrequired_argc].name] = argv[0]; - ++nrequired_argc; + if (nrequired_argc == required_argc_) + { + std::cerr << "Error: wrong number of arguments! \"" + << argv[0] << "\" was not expected!" << std::endl; + no_error = false; + } + else + { + args_[arg_desc_[nrequired_argc].name] = argv[0]; + ++nrequired_argc; + } ++argv; break; } @@ -301,8 +311,7 @@ namespace scribo { if (nrequired_argc) std::cerr << "Error: wrong number of arguments!" << std::endl; - print_help(); - return false; + no_error = false; } if (! no_error) -- 1.7.2.5
12 years, 6 months
1
0
0
0
← Newer
1
...
6
7
8
9
10
11
12
...
15
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Results per page:
10
25
50
100
200