olena-2.0-111-gdb78cd2 Add a better support for different k values in Sauvola Multiscale.

* scribo/scribo/binarization/internal/sauvola_ms_functor.hh, * scribo/scribo/binarization/sauvola_ms.hh, * scribo/scribo/binarization/sauvola_ms_split.hh, * scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh, * scribo/scribo/toolchain/text_in_doc_preprocess.hh: Make use of k2, k3 and k4 variables. * scribo/src/binarization/sauvola_ms.cc, * scribo/src/binarization/sauvola_ms_debug.cc, * scribo/src/binarization/sauvola_ms_fg.cc, * scribo/src/binarization/sauvola_ms_split.cc: Fix program arguments. --- scribo/ChangeLog | 17 +++++++ .../binarization/internal/sauvola_ms_functor.hh | 16 ++++--- scribo/scribo/binarization/sauvola_ms.hh | 48 ++++++++++--------- scribo/scribo/binarization/sauvola_ms_split.hh | 41 ++++++++++++----- .../internal/text_in_doc_preprocess_functor.hh | 28 +++++++++--- scribo/scribo/toolchain/text_in_doc_preprocess.hh | 46 +++++++++++++++---- scribo/src/binarization/sauvola_ms.cc | 2 +- scribo/src/binarization/sauvola_ms_debug.cc | 27 ++++++++--- scribo/src/binarization/sauvola_ms_fg.cc | 31 +++++++++++-- scribo/src/binarization/sauvola_ms_split.cc | 29 +++++++++--- 10 files changed, 207 insertions(+), 78 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 61e6c7e..6982e6b 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,3 +1,20 @@ +2012-05-22 Guillaume Lazzara <z@lrde.epita.fr> + + Add a better support for different k values in Sauvola Multiscale. + + * scribo/scribo/binarization/internal/sauvola_ms_functor.hh, + * scribo/scribo/binarization/sauvola_ms.hh, + * scribo/scribo/binarization/sauvola_ms_split.hh, + * scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh, + * scribo/scribo/toolchain/text_in_doc_preprocess.hh: Make use of + k2, k3 and k4 variables. + + * scribo/src/binarization/sauvola_ms.cc, + * scribo/src/binarization/sauvola_ms_debug.cc, + * scribo/src/binarization/sauvola_ms_fg.cc, + * scribo/src/binarization/sauvola_ms_split.cc: Fix program + arguments. + 2012-05-11 Guillaume Lazzara <z@lrde.epita.fr> Add a default verbose mode in debug::logger. diff --git a/scribo/scribo/binarization/internal/sauvola_ms_functor.hh b/scribo/scribo/binarization/internal/sauvola_ms_functor.hh index 3411d1b..020caa9 100644 --- a/scribo/scribo/binarization/internal/sauvola_ms_functor.hh +++ b/scribo/scribo/binarization/internal/sauvola_ms_functor.hh @@ -54,9 +54,9 @@ namespace scribo namespace internal { - double k2; - double k3; - double k4; + double k2 = SCRIBO_DEFAULT_SAUVOLA_K; + double k3 = SCRIBO_DEFAULT_SAUVOLA_K; + double k4 = SCRIBO_DEFAULT_SAUVOLA_K; using namespace mln; @@ -91,7 +91,9 @@ namespace scribo sauvola_formula formula_; - sauvola_ms_functor(const I& input, double K, double R, const image2d<value::int_u8>&e_2, unsigned i, unsigned q); + sauvola_ms_functor(const I& input, double R, + const image2d<value::int_u8>&e_2, + unsigned i, unsigned q); void exec(double mean, double stddev); void end_of_row(int row); @@ -113,13 +115,15 @@ namespace scribo template <typename I> - sauvola_ms_functor<I>::sauvola_ms_functor(const I& input, double K, double R, const image2d<value::int_u8>&e_2, unsigned i, unsigned q) + sauvola_ms_functor<I>::sauvola_ms_functor(const I& input, + double R, + const image2d<value::int_u8>&e_2, + unsigned i, unsigned q) : input(input), e_2(e_2), i(i), q(q), pxl(input), - //K_(K), R_(R), i_(i) { diff --git a/scribo/scribo/binarization/sauvola_ms.hh b/scribo/scribo/binarization/sauvola_ms.hh index b1e8144..1f120cc 100644 --- a/scribo/scribo/binarization/sauvola_ms.hh +++ b/scribo/scribo/binarization/sauvola_ms.hh @@ -69,6 +69,7 @@ # include <scribo/util/integral_sub_sum_sum2_functor.hh> # include <scribo/util/compute_sub_domains.hh> +# include <scribo/debug/logger.hh> # ifdef SCRIBO_LOCAL_THRESHOLD_DEBUG # include <scribo/binarization/internal/local_threshold_debug.hh> # include <mln/io/pgm/save.hh> @@ -96,10 +97,10 @@ namespace scribo \param[in] w_1 The window size used to compute stats. \param[in] s The scale factor used for the first subscaling. \param[in] lambda_min_1 Size of the objects kept at scale 1. - \param[in] K Sauvola's formulae parameter. \param[out] integral_sum_sum_2 Integral image of sum and squared sum. + Sauvola's formula parameter K is set to 0.34. \p w_1 and \p lambda_min_1 are expressed according to the image at scale 0, i.e. the original size. @@ -108,22 +109,24 @@ namespace scribo template <typename I> mln_ch_value(I,bool) sauvola_ms(const Image<I>& input_1_, unsigned w_1, - unsigned s, double K, + unsigned s, image2d<mln::util::couple<double,double> >& integral_sum_sum_2); /// \overload /// The integral image is not returned. + /// K is set to 0.34. // template <typename I> mln_ch_value(I,bool) - sauvola_ms(const Image<I>& input_1_, unsigned w_1, unsigned s, double K); + sauvola_ms(const Image<I>& input_1_, unsigned w_1, unsigned s); /// \overload - /// K is set to 0.34. + /// Allow to specify a different k parameter for each scale. // template <typename I> mln_ch_value(I,bool) - sauvola_ms(const Image<I>& input_1, unsigned w_1, unsigned s); + sauvola_ms(const Image<I>& input_1, unsigned w_1, unsigned s, + double k2, double k3, double k4); @@ -154,8 +157,7 @@ namespace scribo unsigned lambda_min, unsigned lambda_max, unsigned s, unsigned q, unsigned i, unsigned w, - const image2d<mln::util::couple<double,double> >& integral_sum_sum_2, - double K) + const image2d<mln::util::couple<double,double> >& integral_sum_sum_2) { typedef image2d<int_u8> I; typedef point2d P; @@ -170,7 +172,7 @@ namespace scribo // 1st pass scribo::binarization::internal::sauvola_ms_functor< image2d<int_u8> > - f(sub, K, SCRIBO_DEFAULT_SAUVOLA_R, e_2, i, q); + f(sub, SCRIBO_DEFAULT_SAUVOLA_R, e_2, i, q); scribo::canvas::integral_browsing(integral_sum_sum_2, ratio, w_local_w, w_local_h, @@ -783,7 +785,7 @@ namespace scribo template <typename I> mln_ch_value(I,bool) sauvola_ms(const Image<I>& input_1_, unsigned w_1, - unsigned s, double K, + unsigned s, image2d<mln::util::couple<double,double> >& integral_sum_sum_2) { trace::entering("scribo::binarization::sauvola_ms"); @@ -912,8 +914,7 @@ namespace scribo mln_max(unsigned), s, q, i, w_work, - integral_sum_sum_2, - K); + integral_sum_sum_2); } // Other scales -> maximum and minimum component size. @@ -929,8 +930,7 @@ namespace scribo // (8096 / 36) * coeff, s, q, i, w_work, - integral_sum_sum_2, - K); + integral_sum_sum_2); } } @@ -943,8 +943,7 @@ namespace scribo win_w[2] * 3 * coeff, // (810 / 9) * coeff, s, 1, 2, w_work, - integral_sum_sum_2, - K); + integral_sum_sum_2); } scribo::debug::logger().stop_local_time_logging("3. Multi-scale processing -"); @@ -1008,8 +1007,7 @@ namespace scribo template <typename I> mln_ch_value(I,bool) - sauvola_ms(const Image<I>& input_1_, unsigned w_1, - unsigned s, double K, + sauvola_ms(const Image<I>& input_1_, unsigned w_1, unsigned s, image2d<mln::util::couple<double,double> >& integral_sum_sum_2) { trace::entering("scribo::binarization::sauvola_ms"); @@ -1020,7 +1018,7 @@ namespace scribo mlc_is_not(mln_value(I), bool)::check(); mln_ch_value(I,bool) - output = impl::generic::sauvola_ms(exact(input_1_), w_1, s, K, + output = impl::generic::sauvola_ms(exact(input_1_), w_1, s, integral_sum_sum_2); trace::exiting("scribo::binarization::sauvola_ms"); @@ -1029,8 +1027,7 @@ namespace scribo template <typename I> mln_ch_value(I,bool) - sauvola_ms(const Image<I>& input_1_, unsigned w_1, - unsigned s, double K) + sauvola_ms(const Image<I>& input_1_, unsigned w_1, unsigned s) { trace::entering("scribo::binarization::sauvola_ms"); @@ -1043,7 +1040,7 @@ namespace scribo integral_t integral_sum_sum_2; mln_ch_value(I,bool) - output = sauvola_ms(input_1_, w_1, s, K, integral_sum_sum_2); + output = sauvola_ms(input_1_, w_1, s, integral_sum_sum_2); trace::exiting("scribo::binarization::sauvola_ms"); return output; @@ -1052,9 +1049,14 @@ namespace scribo template <typename I> mln_ch_value(I,bool) - sauvola_ms(const Image<I>& input_1, unsigned w_1, unsigned s) + sauvola_ms(const Image<I>& input_1, unsigned w_1, unsigned s, + double k2, double k3, double k4) { - return sauvola_ms(input_1, w_1, s, SCRIBO_DEFAULT_SAUVOLA_K); + binarization::internal::k2 = k2; + binarization::internal::k3 = k3; + binarization::internal::k4 = k4; + + return sauvola_ms(input_1, w_1, s); } diff --git a/scribo/scribo/binarization/sauvola_ms_split.hh b/scribo/scribo/binarization/sauvola_ms_split.hh index ff16a4e..cf74dd1 100644 --- a/scribo/scribo/binarization/sauvola_ms_split.hh +++ b/scribo/scribo/binarization/sauvola_ms_split.hh @@ -1,5 +1,5 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2010, 2011, 2012 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -59,7 +59,9 @@ namespace scribo \param[in] min_ntrue A site is set to 'True' in the output if it is set to 'True' at least \p min_ntrue components. Possible values: 1, 2, 3. - \param[in] K Sauvola's formula parameter. + \param[in] k2 Sauvola's formula parameter. + \param[in] k3 Sauvola's formula parameter. + \param[in] k4 Sauvola's formula parameter. \p w_1 is expressed according to the image at scale 0, i.e. the original size. @@ -69,12 +71,19 @@ namespace scribo template <typename I> mln_ch_value(I, bool) sauvola_ms_split(const Image<I>& input_1_, unsigned w_1, - unsigned s, unsigned min_ntrue, - double K); + unsigned s, unsigned min_ntrue, double k2, + double k3, double k4); + + /// \overload + /// k2, k3 and k4 are set to \p K. + template <typename I> + mln_ch_value(I, bool) + sauvola_ms_split(const Image<I>& input_1_, unsigned w_1, + unsigned s, unsigned min_ntrue, double K); /// \overload - /// K is set to 0.34. + /// k2, k3 and k4 are set to 0.34. template <typename I> mln_ch_value(I, bool) sauvola_ms_split(const Image<I>& input_1_, unsigned w_1, @@ -88,8 +97,8 @@ namespace scribo template <typename I> mln_ch_value(I, bool) sauvola_ms_split(const Image<I>& input_1_, unsigned w_1, - unsigned s, unsigned min_ntrue, - double K) + unsigned s, unsigned min_ntrue, double k2, + double k3, double k4) { trace::entering("scribo::binarization::sauvola_ms_split"); @@ -107,9 +116,9 @@ namespace scribo bin_t r_b, g_b, b_b; - r_b = sauvola_ms(r_i, w_1, s, K); - g_b = sauvola_ms(g_i, w_1, s, K); - b_b = sauvola_ms(b_i, w_1, s, K); + r_b = sauvola_ms(r_i, w_1, s); + g_b = sauvola_ms(g_i, w_1, s); + b_b = sauvola_ms(b_i, w_1, s); border::resize(r_b, input_1.border()); border::resize(g_b, input_1.border()); @@ -151,6 +160,16 @@ namespace scribo template <typename I> mln_ch_value(I, bool) sauvola_ms_split(const Image<I>& input_1, unsigned w_1, + unsigned s, unsigned min_ntrue, double K) + { + return sauvola_ms_split(input_1, w_1, s, min_ntrue, + K, K, K); + } + + + template <typename I> + mln_ch_value(I, bool) + sauvola_ms_split(const Image<I>& input_1, unsigned w_1, unsigned s, unsigned min_ntrue) { return sauvola_ms_split(input_1, w_1, s, min_ntrue, diff --git a/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh b/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh index d58b4b2..aea02d8 100644 --- a/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh +++ b/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh @@ -1,5 +1,5 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2010, 2011, 2012 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -86,10 +86,17 @@ namespace scribo Few parameters can be set for algorithms: - - Sauvola: + - Sauvola Multi-scale: * sauvola_win, the window size used in Sauvola based algorithms (default 101). - * sauvola_K, a user parameter for Sauvola's threshold formula + * sauvola_K2, a user parameter for Sauvola's threshold formula + at scale 2. + (default 0.34). + * sauvola_K3, a user parameter for Sauvola's threshold formula + at scale 3. + (default 0.34). + * sauvola_K4, a user parameter for Sauvola's threshold formula + at scale 4. (default 0.34). - Extract background/foreground @@ -126,7 +133,9 @@ namespace scribo Binarization_Algo binarization_algo; unsigned sauvola_win; - double sauvola_K; + double sauvola_k2; + double sauvola_k3; + double sauvola_k4; unsigned lambda; // Results @@ -162,7 +171,9 @@ namespace scribo enable_denoising(false), binarization_algo(SauvolaMs), sauvola_win(101), - sauvola_K(0.34), + sauvola_k2(0.34), + sauvola_k3(0.34), + sauvola_k4(0.34), lambda(0) { } @@ -252,7 +263,10 @@ namespace scribo { on_new_progress_label("Binarization (Sauvola Multi-scale)"); output = scribo::binarization::sauvola_ms(intensity_ima, - sauvola_win, 3, sauvola_K); + sauvola_win, 3, + sauvola_k2, + sauvola_k3, + sauvola_k4); } else // binarization_algo == Convert { diff --git a/scribo/scribo/toolchain/text_in_doc_preprocess.hh b/scribo/scribo/toolchain/text_in_doc_preprocess.hh index efa03dd..eb49bde 100644 --- a/scribo/scribo/toolchain/text_in_doc_preprocess.hh +++ b/scribo/scribo/toolchain/text_in_doc_preprocess.hh @@ -1,5 +1,5 @@ -// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2010, 2011, 2012 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -55,7 +55,8 @@ namespace scribo \param[in] input An image. \param[in] enable_fg_bg Enable/Disable background removal. - \param[in] K Binarization threshold parameter. (Default 0.34) + \param[in] K Binarization threshold parameter. Use the same + value for all scales. (Default 0.34) If \p enable_fg_bg is set to 'True' then a background removal is performed. Its parameter lambda is automatically set according @@ -93,10 +94,14 @@ namespace scribo bool verbose = false); /*! \brief Preprocess a document before looking for its content. + This methods relies on a multi-scale implementation of Sauvola's + binarization. \param[in] input An image. \param[in] lambda Parameter to the background removal. - \param[in] K Binarization threshold parameter. (Default 0.34) + \param[in] k2 Binarization threshold parameter for scale 2. (Default 0.34) + \param[in] k3 Binarization threshold parameter for scale 3. (Default 0.34) + \param[in] k4 Binarization threshold parameter for scale 4. (Default 0.34) \param[in,out] fg The foreground layer of \p input. If lambda is set to '0' no background removal is @@ -107,8 +112,16 @@ namespace scribo template <typename I> mln_ch_value(I,bool) text_in_doc_preprocess(const Image<I>& input, unsigned lambda, - double K, bool enable_fg_bg, Image<I>& fg, - bool enable_deskew, bool verbose = false); + double k2, double k3, double k4, bool enable_fg_bg, + Image<I>& fg, bool enable_deskew, + bool verbose = false); + + /// \overload + template <typename I> + mln_ch_value(I,bool) + text_in_doc_preprocess(const Image<I>& input_, unsigned lambda, + bool enable_fg_bg, Image<I>& fg, + bool enable_deskew, bool verbose); # ifndef MLN_INCLUDE_ONLY @@ -137,7 +150,7 @@ namespace scribo mln_concrete(I) tmp_fg; mln_ch_value(I,bool) - output = text_in_doc_preprocess(input, lambda, K, + output = text_in_doc_preprocess(input, lambda, K, K, K, enable_fg_bg, tmp_fg, enable_deskew, verbose); return output; @@ -156,8 +169,8 @@ namespace scribo template <typename I> mln_ch_value(I,bool) text_in_doc_preprocess(const Image<I>& input_, unsigned lambda, - double K, bool enable_fg_bg, Image<I>& fg, - bool enable_deskew, bool verbose) + double k2, double k3, double k4, bool enable_fg_bg, + Image<I>& fg, bool enable_deskew, bool verbose) { trace::entering("scribo::toolchain::text_in_doc_preprocess"); @@ -167,7 +180,9 @@ namespace scribo internal::text_in_doc_preprocess_functor<I> f; // Setup functor. - f.sauvola_K = K; + f.sauvola_k2 = k2; + f.sauvola_k3 = k3; + f.sauvola_k4 = k4; f.enable_fg_extraction = enable_fg_bg; f.lambda = lambda; f.enable_deskew = enable_deskew; @@ -182,6 +197,17 @@ namespace scribo } + template <typename I> + mln_ch_value(I,bool) + text_in_doc_preprocess(const Image<I>& input, unsigned lambda, + bool enable_fg_bg, Image<I>& fg, + bool enable_deskew, bool verbose) + { + text_in_doc_preprocess(input, lambda, SCRIBO_DEFAULT_SAUVOLA_K, + SCRIBO_DEFAULT_SAUVOLA_K, SCRIBO_DEFAULT_SAUVOLA_K, + enable_fg_bg, fg, enable_deskew, verbose); + } + # endif // ! MLN_INCLUDE_ONLY diff --git a/scribo/src/binarization/sauvola_ms.cc b/scribo/src/binarization/sauvola_ms.cc index 685337c..fc6a5a9 100644 --- a/scribo/src/binarization/sauvola_ms.cc +++ b/scribo/src/binarization/sauvola_ms.cc @@ -143,7 +143,7 @@ int main(int argc, char *argv[]) // Binarize image2d<bool> - output = scribo::binarization::sauvola_ms(input_1_gl, w_1, s, k); + output = scribo::binarization::sauvola_ms(input_1_gl, w_1, s); scribo::debug::logger().stop_local_time_logging("Binarized in"); diff --git a/scribo/src/binarization/sauvola_ms_debug.cc b/scribo/src/binarization/sauvola_ms_debug.cc index 251f0e8..d4dcc14 100644 --- a/scribo/src/binarization/sauvola_ms_debug.cc +++ b/scribo/src/binarization/sauvola_ms_debug.cc @@ -64,7 +64,7 @@ static const scribo::debug::opt_data opt_desc[] = // name, description, arguments, check args function, number of args, default arg { "debug-prefix", "Enable debug image outputs. Prefix image name with that " "given prefix.", "<prefix>", 0, 1, 0 }, - { "k", "Sauvola's formulae parameter", "<value>", 0, 1, "0.34" }, + { "all-k", "Sauvola's formulae parameter", "<value>", 0, 1, "0.34" }, { "k2", "Sauvola's formulae parameter", "<value>", 0, 1, "0.20" }, { "k3", "Sauvola's formulae parameter", "<value>", 0, 1, "0.30" }, @@ -136,14 +136,27 @@ int main(int argc, char *argv[]) unsigned w_1 = atoi(options.opt_value("win-size").c_str()); // First subsampling scale. unsigned s = atoi(options.opt_value("s").c_str()); - double k = atof(options.opt_value("k").c_str()); - binarization::internal::k2 = atof(options.opt_value("k2").c_str()); - binarization::internal::k3 = atof(options.opt_value("k3").c_str()); - binarization::internal::k4 = atof(options.opt_value("k4").c_str()); + + // Setting k parameter. + double k = atof(options.opt_value("all-k").c_str()); + binarization::internal::k2 = k; + binarization::internal::k3 = k; + binarization::internal::k4 = k; + + // Override k parameter for specific scales. + if (options.is_set("k2")) + binarization::internal::k2 = atof(options.opt_value("k2").c_str()); + if (options.is_set("k3")) + binarization::internal::k3 = atof(options.opt_value("k3").c_str()); + if (options.is_set("k4")) + binarization::internal::k4 = atof(options.opt_value("k4").c_str()); scribo::debug::logger() << "Using w_1=" << w_1 << " - s=" << s - << " - k=" << k << std::endl; + << " - k2=" << binarization::internal::k2 + << " - k3=" << binarization::internal::k3 + << " - k4=" << binarization::internal::k4 + << std::endl; scribo::binarization::internal::scale_image_output = "scale_image.pgm"; scribo::binarization::internal::threshold_image_output = "threshold_image.pbm"; @@ -165,7 +178,7 @@ int main(int argc, char *argv[]) // Binarize. image2d<bool> - output = scribo::binarization::sauvola_ms(input_1_gl, w_1, s, k); + output = scribo::binarization::sauvola_ms(input_1_gl, w_1, s); scribo::debug::logger().stop_local_time_logging("Binarized in"); diff --git a/scribo/src/binarization/sauvola_ms_fg.cc b/scribo/src/binarization/sauvola_ms_fg.cc index 98206a8..9f47b7d 100644 --- a/scribo/src/binarization/sauvola_ms_fg.cc +++ b/scribo/src/binarization/sauvola_ms_fg.cc @@ -60,7 +60,12 @@ static const scribo::debug::opt_data opt_desc[] = // name, description, arguments, check args function, number of args, default arg { "debug-prefix", "Enable debug image outputs. Prefix image name with that " "given prefix.", "<prefix>", 0, 1, 0 }, - { "k", "Sauvola's formulae parameter", "<value>", 0, 1, "0.34" }, + { "all-k", "Sauvola's formulae parameter", "<value>", 0, 1, "0.34" }, + + { "k2", "Sauvola's formulae parameter", "<value>", 0, 1, "0.20" }, + { "k3", "Sauvola's formulae parameter", "<value>", 0, 1, "0.30" }, + { "k4", "Sauvola's formulae parameter", "<value>", 0, 1, "0.50" }, + { "lambda", "Set the maximum area of the background objects. It is only " "useful if fg-extraction is enabled.", "<size>", 0, 1, "1024" }, { "s", "First subsampling ratio. Possible values: 2 or 3.", "ratio", @@ -100,10 +105,26 @@ int main(int argc, char *argv[]) // First subsampling scale. unsigned s = atoi(options.opt_value("s").c_str()); - double k = atof(options.opt_value("k").c_str()); - scribo::debug::logger() << "Using w_1=" << w_1 << " - s=" << s << " - k=" - << k << " - lambda=" << lambda << std::endl; + // Setting k parameter. + double k = atof(options.opt_value("all-k").c_str()); + binarization::internal::k2 = k; + binarization::internal::k3 = k; + binarization::internal::k4 = k; + + // Override k parameter for specific scales. + if (options.is_set("k2")) + binarization::internal::k2 = atof(options.opt_value("k2").c_str()); + if (options.is_set("k3")) + binarization::internal::k3 = atof(options.opt_value("k3").c_str()); + if (options.is_set("k4")) + binarization::internal::k4 = atof(options.opt_value("k4").c_str()); + + scribo::debug::logger() << "Using w_1=" << w_1 << " - s=" << s + << " - k2=" << binarization::internal::k2 + << " - k3=" << binarization::internal::k3 + << " - k4=" << binarization::internal::k4 + << std::endl; Magick::InitializeMagick(0); @@ -121,7 +142,7 @@ int main(int argc, char *argv[]) // Binarize image2d<bool> - output = scribo::binarization::sauvola_ms(fg_gl, w_1, s, k); + output = scribo::binarization::sauvola_ms(fg_gl, w_1, s); io::pbm::save(output, options.arg("output.pbm")); } diff --git a/scribo/src/binarization/sauvola_ms_split.cc b/scribo/src/binarization/sauvola_ms_split.cc index f1cc490..21915e9 100644 --- a/scribo/src/binarization/sauvola_ms_split.cc +++ b/scribo/src/binarization/sauvola_ms_split.cc @@ -55,7 +55,7 @@ static const scribo::debug::opt_data opt_desc[] = // name, description, arguments, check args function, number of args, default arg { "debug-prefix", "Enable debug image outputs. Prefix image name with that " "given prefix.", "<prefix>", 0, 1, 0 }, - { "k", "Sauvola's formulae parameter. Set it globally for all scales.", + { "all-k", "Sauvola's formulae parameter. Set it globally for all scales.", "<value>", 0, 1, "0.34" }, { "k2", "Sauvola's formulae parameter", "<value>", 0, 1, "0.20" }, @@ -98,15 +98,28 @@ int main(int argc, char *argv[]) // First subsampling scale. unsigned s = atoi(options.opt_value("s").c_str()); - double k = atof(options.opt_value("k").c_str()); unsigned min_ntrue = atoi(options.opt_value("min-ntrue").c_str()); - binarization::internal::k2 = atof(options.opt_value("k2").c_str()); - binarization::internal::k3 = atof(options.opt_value("k3").c_str()); - binarization::internal::k4 = atof(options.opt_value("k4").c_str()); - scribo::debug::logger() << "Using w_1=" << w_1 << " - s=" << s << " - k=" - << k << " - min_ntrue=" << min_ntrue << std::endl; + // Setting k parameter. + double k = atof(options.opt_value("all-k").c_str()); + binarization::internal::k2 = k; + binarization::internal::k3 = k; + binarization::internal::k4 = k; + + // Override k parameter for specific scales. + if (options.is_set("k2")) + binarization::internal::k2 = atof(options.opt_value("k2").c_str()); + if (options.is_set("k3")) + binarization::internal::k3 = atof(options.opt_value("k3").c_str()); + if (options.is_set("k4")) + binarization::internal::k4 = atof(options.opt_value("k4").c_str()); + + scribo::debug::logger() << "Using w_1=" << w_1 << " - s=" << s + << " - k2=" << binarization::internal::k2 + << " - k3=" << binarization::internal::k3 + << " - k4=" << binarization::internal::k4 + << std::endl; Magick::InitializeMagick(0); @@ -114,7 +127,7 @@ int main(int argc, char *argv[]) io::magick::load(input_1, options.arg("input.*")); image2d<bool> - output = scribo::binarization::sauvola_ms_split(input_1, w_1, s, min_ntrue, k); + output = scribo::binarization::sauvola_ms_split(input_1, w_1, s, min_ntrue); io::pbm::save(output, options.arg("output.pbm")); } -- 1.7.2.5
participants (1)
-
Guillaume Lazzara