last-svn-commit-137-gdb55e63 Add the binarization tool submitted to H-DIBCO 2010.

* src/Makefile.am, * src/contest/Makefile.am, * src/contest/hdibco-2010/Makefile.am: New. * src/contest/hdibco-2010/sauvola_ms_hdibco.cc: New. Source code of the submitted program for H-DIBCO 2010. --- scribo/ChangeLog | 11 ++ scribo/src/Makefile.am | 1 + .../{tests/toolchain => src/contest}/Makefile.am | 2 +- .../contest/hdibco-2010}/Makefile.am | 8 +- .../hdibco-2010/sauvola_ms_hdibco.cc} | 100 +++++++------------ 5 files changed, 56 insertions(+), 66 deletions(-) copy scribo/{tests/toolchain => src/contest}/Makefile.am (98%) copy scribo/{tests/toolchain => src/contest/hdibco-2010}/Makefile.am (87%) copy scribo/src/{binarization/pgm_sauvola_ms.cc => contest/hdibco-2010/sauvola_ms_hdibco.cc} (53%) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index f2eb3c3..3888981 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,16 @@ 2010-06-03 Guillaume Lazzara <z@lrde.epita.fr> + Add the binarization tool submitted to H-DIBCO 2010. + + * src/Makefile.am, + * src/contest/Makefile.am, + * src/contest/hdibco-2010/Makefile.am: New. + + * src/contest/hdibco-2010/sauvola_ms_hdibco.cc: New. Source code + of the submitted program for H-DIBCO 2010. + +2010-06-03 Guillaume Lazzara <z@lrde.epita.fr> + Update tools in scribo/src. * src/Makefile.am: Add postprocessing subdir. diff --git a/scribo/src/Makefile.am b/scribo/src/Makefile.am index b3a7859..774740a 100644 --- a/scribo/src/Makefile.am +++ b/scribo/src/Makefile.am @@ -22,6 +22,7 @@ include $(top_srcdir)/scribo/scribo.mk SUBDIRS = \ binarization \ + contest \ debug \ primitive \ filter \ diff --git a/scribo/tests/toolchain/Makefile.am b/scribo/src/contest/Makefile.am similarity index 98% copy from scribo/tests/toolchain/Makefile.am copy to scribo/src/contest/Makefile.am index 826fb86..81f314b 100644 --- a/scribo/tests/toolchain/Makefile.am +++ b/scribo/src/contest/Makefile.am @@ -20,4 +20,4 @@ include $(top_srcdir)/scribo/tests/tests.mk SUBDIRS = \ - nepomuk \ No newline at end of file + hdibco-2010 \ No newline at end of file diff --git a/scribo/tests/toolchain/Makefile.am b/scribo/src/contest/hdibco-2010/Makefile.am similarity index 87% copy from scribo/tests/toolchain/Makefile.am copy to scribo/src/contest/hdibco-2010/Makefile.am index 826fb86..44add64 100644 --- a/scribo/tests/toolchain/Makefile.am +++ b/scribo/src/contest/hdibco-2010/Makefile.am @@ -19,5 +19,9 @@ include $(top_srcdir)/scribo/tests/tests.mk -SUBDIRS = \ - nepomuk \ No newline at end of file +check_PROGRAMS = sauvola_ms_hdibco + +sauvola_ms_hdibco_SOURCES = sauvola_ms_hdibco.cc + + +TESTS = $(check_PROGRAMS) diff --git a/scribo/src/binarization/pgm_sauvola_ms.cc b/scribo/src/contest/hdibco-2010/sauvola_ms_hdibco.cc similarity index 53% copy from scribo/src/binarization/pgm_sauvola_ms.cc copy to scribo/src/contest/hdibco-2010/sauvola_ms_hdibco.cc index 38ff2e6..68fdaac 100644 --- a/scribo/src/binarization/pgm_sauvola_ms.cc +++ b/scribo/src/contest/hdibco-2010/sauvola_ms_hdibco.cc @@ -1,5 +1,4 @@ -// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -24,86 +23,61 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. +#include <cctype> #include <mln/core/image/image2d.hh> #include <mln/value/int_u8.hh> #include <mln/io/pgm/load.hh> +#include <mln/io/ppm/load.hh> #include <mln/io/pbm/save.hh> #include <scribo/binarization/sauvola_ms.hh> -#include <scribo/debug/usage.hh> - -bool check_args(int argc, char * argv[]) -{ - if (argc < 3 || argc > 6) - return false; - - if (argc >= 5) - { - int s = atoi(argv[4]); - - if (s < 1 || s > 3) - { - std::cout << "s must be set to 2 or 3." - << std::endl; - return false; - } - } - - return true; -} - - -const char *args_desc[][2] = -{ - { "input.pgm", "A graylevel image." }, - { "out.pbm", "A binary image." }, - { "w", "Window size at scale 1. (default: 101)" }, - { "s", "First subsampling ratio (default: 3)." }, - { "k", "Sauvola's formuale parameter (default: 0.34)" }, - {0, 0} -}; - - - +#include <scribo/postprocessing/fill_object_holes.hh> +#include <scribo/preprocessing/denoise.hh> int main(int argc, char *argv[]) { using namespace mln; using namespace scribo; - if (!check_args(argc, argv)) - return scribo::debug::usage(argv, - "Multi-Scale Binarization of a color image based on Sauvola's algorithm.", - "input.pgm output.pbm <w> <s> <k>", - args_desc); - trace::entering("main"); + if (argc != 3) + { + std::cout << "Usage: " << argv[0] << " <input.{pgm,ppm}> <output.pbm>" << std::endl; + std::cout << "--------------" << std::endl; + std::cout << "EPITA/LRDE - 2010" << std::endl; + return 1; + } - // Window size - unsigned w_1; - if (argc >= 4) - w_1 = atoi(argv[3]); // Scale 1 - else - w_1 = 101u; + std::string ext = argv[1]; + ext = ext.substr(ext.length() - 3, 3); + for (unsigned i = 0; i < ext.length(); ++i) + ext[i] = tolower(ext[i]); - // First subsampling scale. - unsigned s; - if (argc >= 5) - s = atoi(argv[4]); - else - s = 3u; + // Load + image2d<value::int_u8> input; - double k; - if (argc >= 6) - k = atof(argv[5]); - else - k = 0.34f; + if (ext == "pgm") + io::pgm::load(input, argv[1]); + else if (ext == "ppm") + { + image2d<value::rgb8> input_color; + io::ppm::load(input_color, argv[1]); - image2d<value::int_u8> input_1; - io::pgm::load(input_1, argv[1]); + // Convert to Gray level image. + input = data::transform(input_color, mln::fun::v2v::rgb_to_int_u<8>()); + } + else + { + std::cout << "Invalid input file format! Expecting PGM or PPM images." << std::endl; + return 1; + } + // Binarize image2d<bool> - output = scribo::binarization::sauvola_ms(input_1, w_1, s, k); + output = scribo::binarization::sauvola_ms(input, 101, 3, 0.4); + + output = scribo::preprocessing::denoise_bg(output, c8(), 4); + output = scribo::postprocessing::fill_object_holes(output, 0.01f); io::pbm::save(output, argv[2]); } -- 1.5.6.5

Le 3 juin 2010 à 16:15, Guillaume Lazzara a écrit : [...] I noticed this when I was working on the autoconfication of Olena's subprojects; in both this file:
diff --git a/scribo/tests/toolchain/Makefile.am b/scribo/src/contest/Makefile.am similarity index 98% copy from scribo/tests/toolchain/Makefile.am copy to scribo/src/contest/Makefile.am index 826fb86..81f314b 100644 --- a/scribo/tests/toolchain/Makefile.am +++ b/scribo/src/contest/Makefile.am @@ -20,4 +20,4 @@ include $(top_srcdir)/scribo/tests/tests.mk
SUBDIRS = \ - nepomuk \ No newline at end of file + hdibco-2010 \ No newline at end of file
and this one:
diff --git a/scribo/tests/toolchain/Makefile.am b/scribo/src/contest/hdibco-2010/Makefile.am similarity index 87% copy from scribo/tests/toolchain/Makefile.am copy to scribo/src/contest/hdibco-2010/Makefile.am index 826fb86..44add64 100644 --- a/scribo/tests/toolchain/Makefile.am +++ b/scribo/src/contest/hdibco-2010/Makefile.am @@ -19,5 +19,9 @@
include $(top_srcdir)/scribo/tests/tests.mk
-SUBDIRS = \ - nepomuk \ No newline at end of file +check_PROGRAMS = sauvola_ms_hdibco + +sauvola_ms_hdibco_SOURCES = sauvola_ms_hdibco.cc + + +TESTS = $(check_PROGRAMS)
shouldn't you be including $(top_srcdir)/scribo/scribo.mk instead of $(top_srcdir)/scribo/tests/tests.mk? IMHO, this would be more consistent with the organization of the other directories under scribo/src/ (just my two cents). ;)
participants (2)
-
Guillaume Lazzara
-
Roland Levillain