* src/Makefile.am, * src/extract/Makefile.am, * src/extract/primitive/Makefile.am, * src/filter/Makefile.am, * src/preprocessing/Makefile.am, * src/table/Makefile.am: update build system.
* src/binarization/simple.cc, * src/dmap.cc, * src/extract_text_single_link.cc, * src/recognition.cc: Make them standalone programs - Improve 'usage' output, - cleanup includes - add a header.
* src/extract/primitive/extract_discontinued_hlines.cc, * src/extract/primitive/extract_discontinued_vlines.cc, * src/extract/primitive/extract_thick_hlines.cc, * src/extract/primitive/extract_thick_vlines.cc, * src/filter/large_objects.cc, * src/filter/small_objects.cc, * src/filter/thick_objects.cc, * src/filter/thin_objects.cc, * src/negate.cc, * src/preprocessing/unskew.cc, * src/superpose.cc: new samples.
* src/table_erase.cc, * src/table_extract.cc: move...
* src/table/erase.cc, * src/table/extract.cc: ... here. Make them standalone programs: - Improve 'usage' output, - cleanup includes
--- scribo/ChangeLog | 41 +++++++++++ scribo/src/Makefile.am | 18 +++--- scribo/src/binarization/simple.cc | 48 ++++++++++--- scribo/src/dmap.cc | 75 +++++++++++++++++-- scribo/src/extract/Makefile.am | 6 ++ scribo/src/extract/primitive/Makefile.am | 17 +++++ .../primitive/extract_discontinued_hlines.cc} | 59 ++++++++-------- .../primitive/extract_discontinued_vlines.cc} | 59 ++++++++-------- .../primitive/extract_thick_hlines.cc} | 54 ++++++++------ .../primitive/extract_thick_vlines.cc} | 54 ++++++++------ scribo/src/extract_text_single_link.cc | 28 ++++++-- scribo/src/filter/Makefile.am | 14 ++++ .../{table_erase.cc => filter/large_objects.cc} | 62 ++++++++-------- .../{table_erase.cc => filter/small_objects.cc} | 63 ++++++++-------- .../{table_erase.cc => filter/thick_objects.cc} | 63 ++++++++-------- .../src/{table_erase.cc => filter/thin_objects.cc} | 63 ++++++++-------- scribo/src/{table_extract.cc => negate.cc} | 44 +++++------ scribo/src/preprocessing/Makefile.am | 9 +++ .../{table_extract.cc => preprocessing/unskew.cc} | 45 +++++------- scribo/src/recognition.cc | 73 +++++++++---------- scribo/src/{table_extract.cc => superpose.cc} | 49 +++++++------ scribo/src/table/Makefile.am | 11 +++ scribo/src/{table_erase.cc => table/erase.cc} | 49 ++++++++----- scribo/src/{table_extract.cc => table/extract.cc} | 38 ++++++---- 24 files changed, 628 insertions(+), 414 deletions(-) create mode 100644 scribo/src/extract/Makefile.am create mode 100644 scribo/src/extract/primitive/Makefile.am copy scribo/src/{table_erase.cc => extract/primitive/extract_discontinued_hlines.cc} (58%) copy scribo/src/{table_erase.cc => extract/primitive/extract_discontinued_vlines.cc} (58%) copy scribo/src/{table_extract.cc => extract/primitive/extract_thick_hlines.cc} (59%) copy scribo/src/{table_extract.cc => extract/primitive/extract_thick_vlines.cc} (59%) create mode 100644 scribo/src/filter/Makefile.am copy scribo/src/{table_erase.cc => filter/large_objects.cc} (57%) copy scribo/src/{table_erase.cc => filter/small_objects.cc} (57%) copy scribo/src/{table_erase.cc => filter/thick_objects.cc} (57%) copy scribo/src/{table_erase.cc => filter/thin_objects.cc} (57%) copy scribo/src/{table_extract.cc => negate.cc} (60%) create mode 100644 scribo/src/preprocessing/Makefile.am copy scribo/src/{table_extract.cc => preprocessing/unskew.cc} (60%) copy scribo/src/{table_extract.cc => superpose.cc} (60%) create mode 100644 scribo/src/table/Makefile.am rename scribo/src/{table_erase.cc => table/erase.cc} (66%) rename scribo/src/{table_extract.cc => table/extract.cc} (70%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog index fae746e..7b25394 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,46 @@ 2009-05-28 Guillaume Lazzara lazzara@lrde.epita.fr
+ Update samples in Scribo. + + * src/Makefile.am, + * src/extract/Makefile.am, + * src/extract/primitive/Makefile.am, + * src/filter/Makefile.am, + * src/preprocessing/Makefile.am, + * src/table/Makefile.am: update build system. + + * src/binarization/simple.cc, + * src/dmap.cc, + * src/extract_text_single_link.cc, + * src/recognition.cc: + Make them standalone programs + - Improve 'usage' output, + - cleanup includes + - add a header. + + * src/extract/primitive/extract_discontinued_hlines.cc, + * src/extract/primitive/extract_discontinued_vlines.cc, + * src/extract/primitive/extract_thick_hlines.cc, + * src/extract/primitive/extract_thick_vlines.cc, + * src/filter/large_objects.cc, + * src/filter/small_objects.cc, + * src/filter/thick_objects.cc, + * src/filter/thin_objects.cc, + * src/negate.cc, + * src/preprocessing/unskew.cc, + * src/superpose.cc: new samples. + + * src/table_erase.cc, + * src/table_extract.cc: move... + + * src/table/erase.cc, + * src/table/extract.cc: ... here. + Make them standalone programs: + - Improve 'usage' output, + - cleanup includes + +2009-05-28 Guillaume Lazzara lazzara@lrde.epita.fr + Add new test images for Scribo.
* tests/img/table_to_be_repaired.pbm, diff --git a/scribo/src/Makefile.am b/scribo/src/Makefile.am index 72b202d..7d02f86 100644 --- a/scribo/src/Makefile.am +++ b/scribo/src/Makefile.am @@ -6,7 +6,9 @@ recognition_CXXFLAGS = -I$(HOME)/local/include $(HOME)/local/lib/libtesseract_fu recognition_LDFLAGS = -lpthread
SUBDIRS = \ - binarization + binarization \ + preprocessing \ + table
bin_PROGRAMS = \ dmap \ @@ -17,13 +19,12 @@ bin_PROGRAMS = \ extract_text_several_left_links \ extract_text_single_link \ morpho \ + negate \ recognition \ - table_erase \ - table_extract \ + superpose \ table_rebuild_opening \ table_rebuild_rank \ - thin_bboxes \ - unskew + thin_bboxes
dmap_SOURCES = dmap.cc extract_text_double_link_SOURCES = extract_text_double_link.cc @@ -32,12 +33,11 @@ extract_text_graph_SOURCES = extract_text_graph.cc extract_text_several_graph_SOURCES = extract_text_several_graph.cc extract_text_several_left_links_SOURCES = extract_text_several_left_links.cc extract_text_single_link_SOURCES = extract_text_single_link.cc -morpho_SOURCES = morpho.cc +morpho_SOURCES = morpho.cc +negate_SOURCES = negate.cc recognition_SOURCES = recognition.cc -table_erase_SOURCES = table_erase.cc -table_extract_SOURCES = table_extract.cc +superpose_SOURCES = superpose.cc table_rebuild_opening_SOURCES = table_rebuild_opening.cc table_rebuild_rank_SOURCES = table_rebuild_rank.cc thin_bboxes_SOURCES = thin_bboxes.cc -unskew_SOURCES = unskew.cc
diff --git a/scribo/src/binarization/simple.cc b/scribo/src/binarization/simple.cc index f738f43..77079e7 100644 --- a/scribo/src/binarization/simple.cc +++ b/scribo/src/binarization/simple.cc @@ -1,17 +1,46 @@ -#include <scribo/binarization/simple.hh> +// Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/// \file scribo/src/binarization/simple.cc +/// +/// Simple binarization in Scribo.
#include <mln/io/pgm/load.hh> #include <mln/io/pbm/save.hh>
+#include <scribo/binarization/simple.hh> +#include <scribo/debug/usage.hh>
- -void usage(char* argv[]) +const char *args_desc[][2] = { - std::cerr << "usage: " << argv[0] << " input.pgm output.pbm" << std::endl - << " Simple binarization in SCRIBO." << std::endl; - std::abort(); -} - + { "input.pgm", "A gray level image." }, + {0, 0} +};
int main(int argc, char *argv[]) @@ -20,7 +49,8 @@ int main(int argc, char *argv[]) using value::int_u8;
if (argc != 3) - usage(argv); + return usage(argv, "Simple binarization of a gray-level image.", "input.pbm output.pbm", + args_desc, "A binary image.");
trace::entering("main");
diff --git a/scribo/src/dmap.cc b/scribo/src/dmap.cc index 0375691..520bc92 100644 --- a/scribo/src/dmap.cc +++ b/scribo/src/dmap.cc @@ -1,26 +1,85 @@ -#include <mln/essential/2d.hh> +// Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +/// \file scribo/src/dmap.cc +/// +/// Compute a distance map and an influence zone image. + +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> #include <mln/core/var.hh> -#include <mln/fun/l2l/wrap.hh> + +#include <mln/labeling/blobs.hh> +#include <mln/labeling/colorize.hh> +#include <mln/labeling/wrap.hh> + #include <mln/transform/distance_and_influence_zone_geodesic.hh>
-int main(int, char *argv[]) +#include <mln/value/label_16.hh> +#include <mln/value/rgb8.hh> + +#include <mln/io/pbm/load.hh> +#include <mln/io/ppm/save.hh> +#include <mln/io/pgm/save.hh> + +int usage(char* argv[]) +{ + std::cerr << "usage: " << argv[0] << " input.pgm dmap.pgm iz.ppm" + << std::endl + << " Compute a distance map and an influence zone image." + << std::endl; + return 1; +} + + +int main(int argc, char *argv[]) { using namespace mln;
- using value::int_u16; using value::label_16; - using value::label_8; using value::rgb8;
+ if (argc != 4) + return usage(argv); + image2d<bool> ima; io::pbm::load(ima, argv[1]);
label_16 nlabels; image2d<label_16> lbl = labeling::blobs(ima, c8(), nlabels);
- mln_VAR(res, transform::distance_and_influence_zone_geodesic(lbl, c8(), mln_max(unsigned))); + mln_VAR(res, + transform::distance_and_influence_zone_geodesic(lbl, + c8(), + mln_max(unsigned)));
- io::pgm::save(level::transform(res.first(), fun::l2l::wrap<label_8>()), "dmap.pgm"); - io::ppm::save(labeling::colorize(value::rgb8(), res.second(), nlabels), "iz.ppm"); + io::pgm::save(labeling::wrap(res.first()), argv[2]); + io::ppm::save(labeling::colorize(value::rgb8(), res.second(), nlabels), + argv[3]);
} diff --git a/scribo/src/extract/Makefile.am b/scribo/src/extract/Makefile.am new file mode 100644 index 0000000..3913680 --- /dev/null +++ b/scribo/src/extract/Makefile.am @@ -0,0 +1,6 @@ +## Process this file through Automake to create Makefile.in. + +include $(top_srcdir)/scribo/scribo.mk + +SUBDIRS = \ + primitive diff --git a/scribo/src/extract/primitive/Makefile.am b/scribo/src/extract/primitive/Makefile.am new file mode 100644 index 0000000..4512d08 --- /dev/null +++ b/scribo/src/extract/primitive/Makefile.am @@ -0,0 +1,17 @@ +## Process this file through Automake to create Makefile.in. + +include $(top_srcdir)/scribo/scribo.mk + + +bin_PROGRAMS = \ + extract_discontinued_vlines \ + extract_discontinued_hlines \ + extract_thick_vlines \ + extract_thick_hlines + +extract_discontinued_vlines_SOURCES = extract_discontinued_vlines.cc +extract_discontinued_hlines_SOURCES = extract_discontinued_hlines.cc +extract_thick_vlines_SOURCES = extract_thick_vlines.cc +extract_thick_hlines_SOURCES = extract_thick_hlines.cc + + diff --git a/scribo/src/table_erase.cc b/scribo/src/extract/primitive/extract_discontinued_hlines.cc similarity index 58% copy from scribo/src/table_erase.cc copy to scribo/src/extract/primitive/extract_discontinued_hlines.cc index 15cf880..6b7c3c4 100644 --- a/scribo/src/table_erase.cc +++ b/scribo/src/extract/primitive/extract_discontinued_hlines.cc @@ -1,4 +1,5 @@ // Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,52 +26,50 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#include <iostream> +/// \file scribo/src/extract/primitive/extract_discontinued_hlines.cc +/// +/// Extract discontinued horizontal lines.
#include <mln/core/image/image2d.hh> -#include <mln/io/pbm/load.hh> -#include <mln/io/pbm/save.hh> -#include <mln/io/dump/save.hh> #include <mln/value/label_16.hh> #include <mln/core/alias/neighb2d.hh> +#include <mln/io/pbm/all.hh> +#include <mln/level/convert.hh>
-#include <scribo/table/extract.hh> +#include <scribo/extract/primitive/lines_h_discontinued.hh> +#include <scribo/debug/usage.hh>
-#include <scribo/primitive/lines_h_discontinued.hh> -#include <scribo/primitive/lines_v_discontinued.hh> - -int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} + { "input.pbm", "A binary image." }, + { "length", " Minimum line length." }, + { "rank", " Filter rank." }, + {0, 0} +};
-int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - using namespace scribo; using namespace mln; - using mln::value::label_16;
- if (argc < 1) - return usage(argv[0]); + if (argc != 5) + return usage(argv, "Extract discontinued horizontal lines", "input.pbm length rank output.pbm", + args_desc, "A binary image of horizontal lines.");
- scribo::make::internal::debug_filename_prefix = "table_erase"; + trace::entering("main");
image2d<bool> input; io::pbm::load(input, argv[1]); - logical::not_inplace(input); - - typedef util::couple<util::array<box2d>, - util::array<box2d> > tables_t;
- label_16 nhlines, nvlines; - util::array<box2d> vlines, hlines; - image2d<label_16> lbl_v = primitive::lines_v_discontinued(input, c8(), - nvlines, 51, 8); - image2d<label_16> lbl_h = primitive::lines_h_discontinued(input, c8(), - nhlines, 51, 6); + value::label_16 nlines; + image2d<bool> lines + = level::convert(bool(), + scribo::extract::primitive::lines_h_discontinued(input, + c8(), + nlines, + atoi(argv[2]), + atoi(argv[3]))); + io::pbm::save(lines, argv[4]);
- image2d<bool> input_notables = scribo::table::erase(input, tables); - io::pbm::save(input_notables, scribo::make::debug_filename("input_notables.pbm")); + trace::exiting("main"); } diff --git a/scribo/src/table_erase.cc b/scribo/src/extract/primitive/extract_discontinued_vlines.cc similarity index 58% copy from scribo/src/table_erase.cc copy to scribo/src/extract/primitive/extract_discontinued_vlines.cc index 15cf880..7bd3391 100644 --- a/scribo/src/table_erase.cc +++ b/scribo/src/extract/primitive/extract_discontinued_vlines.cc @@ -1,4 +1,5 @@ // Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,52 +26,50 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#include <iostream> +/// \file scribo/src/extract/primitive/extract_discontinued_vlines.cc +/// +/// Extract discontinued vertical lines.
#include <mln/core/image/image2d.hh> -#include <mln/io/pbm/load.hh> -#include <mln/io/pbm/save.hh> -#include <mln/io/dump/save.hh> #include <mln/value/label_16.hh> #include <mln/core/alias/neighb2d.hh> +#include <mln/io/pbm/all.hh> +#include <mln/level/convert.hh>
-#include <scribo/table/extract.hh> +#include <scribo/extract/primitive/lines_v_discontinued.hh> +#include <scribo/debug/usage.hh>
-#include <scribo/primitive/lines_h_discontinued.hh> -#include <scribo/primitive/lines_v_discontinued.hh> - -int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} + { "input.pbm", "A binary image." }, + { "length", " Minimum line length." }, + { "rank", " Filter rank." }, + {0, 0} +};
-int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - using namespace scribo; using namespace mln; - using mln::value::label_16;
- if (argc < 1) - return usage(argv[0]); + if (argc != 5) + return usage(argv, "Extract discontinued vertical lines", "input.pbm length rank output.pbm", + args_desc, "A binary image of vertical lines.");
- scribo::make::internal::debug_filename_prefix = "table_erase"; + trace::entering("main");
image2d<bool> input; io::pbm::load(input, argv[1]); - logical::not_inplace(input); - - typedef util::couple<util::array<box2d>, - util::array<box2d> > tables_t;
- label_16 nhlines, nvlines; - util::array<box2d> vlines, hlines; - image2d<label_16> lbl_v = primitive::lines_v_discontinued(input, c8(), - nvlines, 51, 8); - image2d<label_16> lbl_h = primitive::lines_h_discontinued(input, c8(), - nhlines, 51, 6); + value::label_16 nlines; + image2d<bool> lines + = level::convert(bool(), + scribo::extract::primitive::lines_v_discontinued(input, + c8(), + nlines, + atoi(argv[2]), + atoi(argv[3]))); + io::pbm::save(lines, argv[4]);
- image2d<bool> input_notables = scribo::table::erase(input, tables); - io::pbm::save(input_notables, scribo::make::debug_filename("input_notables.pbm")); + trace::exiting("main"); } diff --git a/scribo/src/table_extract.cc b/scribo/src/extract/primitive/extract_thick_hlines.cc similarity index 59% copy from scribo/src/table_extract.cc copy to scribo/src/extract/primitive/extract_thick_hlines.cc index b184e53..dfc8038 100644 --- a/scribo/src/table_extract.cc +++ b/scribo/src/extract/primitive/extract_thick_hlines.cc @@ -1,4 +1,5 @@ // Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,43 +26,48 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#include <iostream> +/// \file scribo/src/extract/primitive/extract_thick_hlines.cc +/// +/// Extract thick horizontal lines.
-#include <mln/essential/2d.hh> -#include <mln/io/dump/save.hh> +#include <mln/core/image/image2d.hh> +#include <mln/value/label_16.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/io/pbm/all.hh> +#include <mln/level/convert.hh>
-#include <scribo/table/extract.hh> +#include <scribo/extract/primitive/lines_h_thick.hh> +#include <scribo/debug/usage.hh>
- -int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} + { "input.pbm", "A binary image." }, + { "length", " Minimum line length." }, + {0, 0} +};
-int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - using namespace scribo; using namespace mln;
- if (argc < 1) - return usage(argv[0]); + if (argc != 4) + return usage(argv, "Extract thick horizontal lines", "input.pbm length output.pbm", + args_desc, "A binary image of horizontal lines.");
- scribo::make::internal::debug_filename_prefix = argv[0]; + trace::entering("main");
image2d<bool> input; io::pbm::load(input, argv[1]); - logical::not_inplace(input); - - trace::quiet = false; - - value::label_16 ncells; - image2dvalue::label_16 tables = scribo::table::extract(input, ncells).first();
- std::cout << "ncells (including background) = " << ncells << std::endl; - io::ppm::save(mln::labeling::colorize(value::rgb8(), tables, ncells), - scribo::make::debug_filename("table_cells.ppm")); + value::label_16 nlines; + image2d<bool> lines + = level::convert(bool(), + scribo::extract::primitive::lines_h_thick(input, + c8(), + nlines, + atoi(argv[2]))); + io::pbm::save(lines, argv[3]);
- io::dump::save(tables, scribo::make::debug_filename("table_cells.dump")); + trace::exiting("main"); } diff --git a/scribo/src/table_extract.cc b/scribo/src/extract/primitive/extract_thick_vlines.cc similarity index 59% copy from scribo/src/table_extract.cc copy to scribo/src/extract/primitive/extract_thick_vlines.cc index b184e53..dd20126 100644 --- a/scribo/src/table_extract.cc +++ b/scribo/src/extract/primitive/extract_thick_vlines.cc @@ -1,4 +1,5 @@ // Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,43 +26,48 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#include <iostream> +/// \file scribo/src/extract/primitive/extract_thick_vlines.cc +/// +/// Extract thick vertical lines.
-#include <mln/essential/2d.hh> -#include <mln/io/dump/save.hh> +#include <mln/core/image/image2d.hh> +#include <mln/value/label_16.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/io/pbm/all.hh> +#include <mln/level/convert.hh>
-#include <scribo/table/extract.hh> +#include <scribo/extract/primitive/lines_v_thick.hh> +#include <scribo/debug/usage.hh>
- -int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} + { "input.pbm", "A binary image." }, + { "length", " Minimum line length." }, + {0, 0} +};
-int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - using namespace scribo; using namespace mln;
- if (argc < 1) - return usage(argv[0]); + if (argc != 4) + return usage(argv, "Extract thick vertical lines", "input.pbm length output.pbm", + args_desc, "A binary image of vertical lines.");
- scribo::make::internal::debug_filename_prefix = argv[0]; + trace::entering("main");
image2d<bool> input; io::pbm::load(input, argv[1]); - logical::not_inplace(input); - - trace::quiet = false; - - value::label_16 ncells; - image2dvalue::label_16 tables = scribo::table::extract(input, ncells).first();
- std::cout << "ncells (including background) = " << ncells << std::endl; - io::ppm::save(mln::labeling::colorize(value::rgb8(), tables, ncells), - scribo::make::debug_filename("table_cells.ppm")); + value::label_16 nlines; + image2d<bool> lines + = level::convert(bool(), + scribo::extract::primitive::lines_v_thick(input, + c8(), + nlines, + atoi(argv[2]))); + io::pbm::save(lines, argv[3]);
- io::dump::save(tables, scribo::make::debug_filename("table_cells.dump")); + trace::exiting("main"); } diff --git a/scribo/src/extract_text_single_link.cc b/scribo/src/extract_text_single_link.cc index 55e5068..4b361a0 100644 --- a/scribo/src/extract_text_single_link.cc +++ b/scribo/src/extract_text_single_link.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,9 +25,23 @@ // reasons why the executable file might be covered by the GNU General // Public License.
+/// \file scribo/src/extract_text_single_link.cc +/// +/// Extract text lines objects using a single left link grouping method. + #include <iostream>
-#include <mln/essential/2d.hh> +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/neighb2d.hh> + +#include <mln/labeling/colorize.hh> + +#include <mln/util/array.hh> + +#include <mln/value/label_16.hh> +#include <mln/literal/colors.hh> + +#include <mln/io/pbm/load.hh>
#include <scribo/text/extract_bboxes.hh> #include <scribo/text/grouping/group_with_single_left_link.hh> @@ -38,19 +52,21 @@ #include <scribo/debug/save_linked_textbboxes_image.hh> #include <scribo/make/debug_filename.hh>
-int usage(const char *name) + +int usage(char *argv[]) { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; + std::cout << "Usage: " << argv[0] << " <input.pbm> " << std::endl; return 1; }
+ int main(int argc, char* argv[]) { using namespace scribo; using namespace mln;
- if (argc < 1) - return usage(argv[0]); + if (argc != 2) + return usage(argv);
scribo::make::internal::debug_filename_prefix = "extract_text_single_link";
diff --git a/scribo/src/filter/Makefile.am b/scribo/src/filter/Makefile.am new file mode 100644 index 0000000..9ebacf3 --- /dev/null +++ b/scribo/src/filter/Makefile.am @@ -0,0 +1,14 @@ +## Process this file through Automake to create Makefile.in. + +include $(top_srcdir)/scribo/scribo.mk + +bin_PROGRAMS = \ + large_objects \ + small_objects \ + thick_objects \ + thin_objects + +large_objects_SOURCES = large_objects.cc +small_objects_SOURCES = small_objects.cc +thick_objects_SOURCES = thick_objects.cc +thin_objects_SOURCES = thin_objects.cc diff --git a/scribo/src/table_erase.cc b/scribo/src/filter/large_objects.cc similarity index 57% copy from scribo/src/table_erase.cc copy to scribo/src/filter/large_objects.cc index 15cf880..f986c67 100644 --- a/scribo/src/table_erase.cc +++ b/scribo/src/filter/large_objects.cc @@ -1,4 +1,5 @@ // Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,52 +26,51 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#include <iostream> +/// \file scribo/src/filter/large_objects.cc +/// +/// Filter too large objects.
#include <mln/core/image/image2d.hh> -#include <mln/io/pbm/load.hh> -#include <mln/io/pbm/save.hh> -#include <mln/io/dump/save.hh> -#include <mln/value/label_16.hh> #include <mln/core/alias/neighb2d.hh> +#include <mln/level/convert.hh> +#include <mln/io/pbm/all.hh>
-#include <scribo/table/extract.hh> +#include <mln/value/label_16.hh>
-#include <scribo/primitive/lines_h_discontinued.hh> -#include <scribo/primitive/lines_v_discontinued.hh> +#include <scribo/filter/large_objects.hh> +#include <scribo/debug/usage.hh>
-int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} + { "input.pbm", "A binary image. 'True' for objects, 'False'\ +for the background." }, + { "max_area", "The maximum object area value. Objects with an area greater\ +than this value are removed." }, + {0, 0} +};
- -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - using namespace scribo; using namespace mln; - using mln::value::label_16;
- if (argc < 1) - return usage(argv[0]); + if (argc != 4) + return usage(argv, "Filter too large objects", "input.pbm max_area output.pbm", + args_desc, "A binary image.");
- scribo::make::internal::debug_filename_prefix = "table_erase"; + trace::entering("main");
- image2d<bool> input; + typedef image2d<bool> I; + I input; io::pbm::load(input, argv[1]); - logical::not_inplace(input);
- typedef util::couple<util::array<box2d>, - util::array<box2d> > tables_t; + value::label_16 nobjects; + typedef object_image(mln_ch_value_(I,value::label_16)) obj_ima_t; + obj_ima_t objects + = scribo::extract::primitive::objects(input, c8(), nobjects); + + obj_ima_t filtered = scribo::filter::large_objects(objects, atoi(argv[2])); + io::pbm::save(level::convert(bool(), filtered), argv[3]);
- label_16 nhlines, nvlines; - util::array<box2d> vlines, hlines; - image2d<label_16> lbl_v = primitive::lines_v_discontinued(input, c8(), - nvlines, 51, 8); - image2d<label_16> lbl_h = primitive::lines_h_discontinued(input, c8(), - nhlines, 51, 6); + trace::exiting("main");
- image2d<bool> input_notables = scribo::table::erase(input, tables); - io::pbm::save(input_notables, scribo::make::debug_filename("input_notables.pbm")); } diff --git a/scribo/src/table_erase.cc b/scribo/src/filter/small_objects.cc similarity index 57% copy from scribo/src/table_erase.cc copy to scribo/src/filter/small_objects.cc index 15cf880..8fe9e1b 100644 --- a/scribo/src/table_erase.cc +++ b/scribo/src/filter/small_objects.cc @@ -1,4 +1,5 @@ // Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,52 +26,50 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#include <iostream> +/// \file scribo/src/filter/small_objects.cc +/// +/// Filter too small objects.
#include <mln/core/image/image2d.hh> -#include <mln/io/pbm/load.hh> -#include <mln/io/pbm/save.hh> -#include <mln/io/dump/save.hh> -#include <mln/value/label_16.hh> #include <mln/core/alias/neighb2d.hh> +#include <mln/level/convert.hh> +#include <mln/io/pbm/all.hh> +#include <mln/value/label_16.hh>
-#include <scribo/table/extract.hh> - -#include <scribo/primitive/lines_h_discontinued.hh> -#include <scribo/primitive/lines_v_discontinued.hh> +#include <scribo/filter/small_objects.hh> +#include <scribo/debug/usage.hh>
-int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} - + { "input.pbm", "A binary image. 'True' for objects, 'False'\ +for the background." }, + { "min_area", "The minimum object area value. Objects with an area less than \ +or equal to this value are removed." }, + {0, 0} +};
-int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - using namespace scribo; using namespace mln; - using mln::value::label_16;
- if (argc < 1) - return usage(argv[0]); + if (argc != 4) + return usage(argv, "Filter too small objects", "input.pbm min_area output.pbm", + args_desc, "A binary image.");
- scribo::make::internal::debug_filename_prefix = "table_erase"; + trace::entering("main");
- image2d<bool> input; + typedef image2d<bool> I; + I input; io::pbm::load(input, argv[1]); - logical::not_inplace(input);
- typedef util::couple<util::array<box2d>, - util::array<box2d> > tables_t; + value::label_16 nobjects; + typedef object_image(mln_ch_value_(I,value::label_16)) obj_ima_t; + obj_ima_t objects + = scribo::extract::primitive::objects(input, c8(), nobjects); + + obj_ima_t filtered = scribo::filter::small_objects(objects, atoi(argv[2])); + io::pbm::save(level::convert(bool(), filtered), argv[3]);
- label_16 nhlines, nvlines; - util::array<box2d> vlines, hlines; - image2d<label_16> lbl_v = primitive::lines_v_discontinued(input, c8(), - nvlines, 51, 8); - image2d<label_16> lbl_h = primitive::lines_h_discontinued(input, c8(), - nhlines, 51, 6); + trace::exiting("main");
- image2d<bool> input_notables = scribo::table::erase(input, tables); - io::pbm::save(input_notables, scribo::make::debug_filename("input_notables.pbm")); } diff --git a/scribo/src/table_erase.cc b/scribo/src/filter/thick_objects.cc similarity index 57% copy from scribo/src/table_erase.cc copy to scribo/src/filter/thick_objects.cc index 15cf880..e09ef60 100644 --- a/scribo/src/table_erase.cc +++ b/scribo/src/filter/thick_objects.cc @@ -1,4 +1,5 @@ // Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,52 +26,50 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#include <iostream> +/// \file scribo/src/filter/thick_objects.cc +/// +/// Filter too thick objects.
#include <mln/core/image/image2d.hh> -#include <mln/io/pbm/load.hh> -#include <mln/io/pbm/save.hh> -#include <mln/io/dump/save.hh> -#include <mln/value/label_16.hh> #include <mln/core/alias/neighb2d.hh> +#include <mln/level/convert.hh> +#include <mln/io/pbm/all.hh> +#include <mln/value/label_16.hh>
-#include <scribo/table/extract.hh> - -#include <scribo/primitive/lines_h_discontinued.hh> -#include <scribo/primitive/lines_v_discontinued.hh> +#include <scribo/filter/thick_objects.hh> +#include <scribo/debug/usage.hh>
-int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} - + { "input.pbm", "A binary image. 'True' for objects, 'False'\ +for the background." }, + { "max_thick", "The maximum object thickness value. Objects with bounding\ +box hight or width higher than this value are removed." }, + {0, 0} +};
-int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - using namespace scribo; using namespace mln; - using mln::value::label_16;
- if (argc < 1) - return usage(argv[0]); + if (argc != 4) + return usage(argv, "Filter too thick objects", "input.pbm max_thick output.pbm", + args_desc, "A binary image.");
- scribo::make::internal::debug_filename_prefix = "table_erase"; + trace::entering("main");
- image2d<bool> input; + typedef image2d<bool> I; + I input; io::pbm::load(input, argv[1]); - logical::not_inplace(input);
- typedef util::couple<util::array<box2d>, - util::array<box2d> > tables_t; + value::label_16 nobjects; + typedef object_image(mln_ch_value_(I,value::label_16)) obj_ima_t; + obj_ima_t objects + = scribo::extract::primitive::objects(input, c8(), nobjects); + + obj_ima_t filtered = scribo::filter::thick_objects(objects, atoi(argv[2])); + io::pbm::save(level::convert(bool(), filtered), argv[3]);
- label_16 nhlines, nvlines; - util::array<box2d> vlines, hlines; - image2d<label_16> lbl_v = primitive::lines_v_discontinued(input, c8(), - nvlines, 51, 8); - image2d<label_16> lbl_h = primitive::lines_h_discontinued(input, c8(), - nhlines, 51, 6); + trace::exiting("main");
- image2d<bool> input_notables = scribo::table::erase(input, tables); - io::pbm::save(input_notables, scribo::make::debug_filename("input_notables.pbm")); } diff --git a/scribo/src/table_erase.cc b/scribo/src/filter/thin_objects.cc similarity index 57% copy from scribo/src/table_erase.cc copy to scribo/src/filter/thin_objects.cc index 15cf880..138d9f5 100644 --- a/scribo/src/table_erase.cc +++ b/scribo/src/filter/thin_objects.cc @@ -1,4 +1,5 @@ // Copyright (C) 2009 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,52 +26,50 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#include <iostream> +/// \file scribo/src/filter/thin_objects.cc +/// +/// Filter too thin objects.
#include <mln/core/image/image2d.hh> -#include <mln/io/pbm/load.hh> -#include <mln/io/pbm/save.hh> -#include <mln/io/dump/save.hh> -#include <mln/value/label_16.hh> #include <mln/core/alias/neighb2d.hh> +#include <mln/level/convert.hh> +#include <mln/io/pbm/all.hh> +#include <mln/value/label_16.hh>
-#include <scribo/table/extract.hh> - -#include <scribo/primitive/lines_h_discontinued.hh> -#include <scribo/primitive/lines_v_discontinued.hh> +#include <scribo/filter/thin_objects.hh> +#include <scribo/debug/usage.hh>
-int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} - + { "input.pbm", "A binary image. 'True' for objects, 'False'\ +for the background." }, + { "min_thin", "The minimum object thinness value. Objects with bounding\ +box hight or width less than or equal to this value are removed." }, + {0, 0} +};
-int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - using namespace scribo; using namespace mln; - using mln::value::label_16;
- if (argc < 1) - return usage(argv[0]); + if (argc != 4) + return usage(argv, "Filter too thin objects", "input.pbm min_thin output.pbm", + args_desc, "A binary image.");
- scribo::make::internal::debug_filename_prefix = "table_erase"; + trace::entering("main");
- image2d<bool> input; + typedef image2d<bool> I; + I input; io::pbm::load(input, argv[1]); - logical::not_inplace(input);
- typedef util::couple<util::array<box2d>, - util::array<box2d> > tables_t; + value::label_16 nobjects; + typedef object_image(mln_ch_value_(I,value::label_16)) obj_ima_t; + obj_ima_t objects + = scribo::extract::primitive::objects(input, c8(), nobjects); + + obj_ima_t filtered = scribo::filter::thin_objects(objects, atoi(argv[2])); + io::pbm::save(level::convert(bool(), filtered), argv[3]);
- label_16 nhlines, nvlines; - util::array<box2d> vlines, hlines; - image2d<label_16> lbl_v = primitive::lines_v_discontinued(input, c8(), - nvlines, 51, 8); - image2d<label_16> lbl_h = primitive::lines_h_discontinued(input, c8(), - nhlines, 51, 6); + trace::exiting("main");
- image2d<bool> input_notables = scribo::table::erase(input, tables); - io::pbm::save(input_notables, scribo::make::debug_filename("input_notables.pbm")); } diff --git a/scribo/src/table_extract.cc b/scribo/src/negate.cc similarity index 60% copy from scribo/src/table_extract.cc copy to scribo/src/negate.cc index b184e53..4761759 100644 --- a/scribo/src/table_extract.cc +++ b/scribo/src/negate.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,43 +25,39 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#include <iostream> +/// \file scribo/src/negate.cc +/// +/// Negate a binary image.
-#include <mln/essential/2d.hh> -#include <mln/io/dump/save.hh> +#include <mln/core/image/image2d.hh> +#include <mln/logical/not.hh> +#include <mln/io/pbm/all.hh>
-#include <scribo/table/extract.hh> +#include <scribo/debug/usage.hh>
-int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} + { "input.pbm", "A binary image." }, + {0, 0} +};
-int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - using namespace scribo; + mln::trace::entering("main"); using namespace mln;
- if (argc < 1) - return usage(argv[0]); - - scribo::make::internal::debug_filename_prefix = argv[0]; + if (argc != 3) + return usage(argv, "Negate a binary image", "input.pbm output.pbm", + args_desc, "A binary image.");
image2d<bool> input; io::pbm::load(input, argv[1]); - logical::not_inplace(input);
- trace::quiet = false; + io::pbm::save(logical::not_(input), argv[2]);
- value::label_16 ncells; - image2dvalue::label_16 tables = scribo::table::extract(input, ncells).first(); + mln::trace::exiting("main");
- std::cout << "ncells (including background) = " << ncells << std::endl; - io::ppm::save(mln::labeling::colorize(value::rgb8(), tables, ncells), - scribo::make::debug_filename("table_cells.ppm")); - - io::dump::save(tables, scribo::make::debug_filename("table_cells.dump")); } + diff --git a/scribo/src/preprocessing/Makefile.am b/scribo/src/preprocessing/Makefile.am new file mode 100644 index 0000000..903e076 --- /dev/null +++ b/scribo/src/preprocessing/Makefile.am @@ -0,0 +1,9 @@ +## Process this file through Automake to create Makefile.in. + +include $(top_srcdir)/scribo/scribo.mk + +bin_PROGRAMS = \ + unskew + +unskew_SOURCES = unskew.cc + diff --git a/scribo/src/table_extract.cc b/scribo/src/preprocessing/unskew.cc similarity index 60% copy from scribo/src/table_extract.cc copy to scribo/src/preprocessing/unskew.cc index b184e53..716ceb6 100644 --- a/scribo/src/table_extract.cc +++ b/scribo/src/preprocessing/unskew.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,43 +25,38 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#include <iostream> +/// \file scribo/src/unskew.cc +/// +/// Unskew a binary document.
-#include <mln/essential/2d.hh> -#include <mln/io/dump/save.hh> +#include <mln/core/image/image2d.hh> +#include <mln/io/pbm/all.hh>
-#include <scribo/table/extract.hh> +#include <scribo/preprocessing/unskew.hh> +#include <scribo/debug/usage.hh>
-int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} + { "input.pbm", "A binary image. 'True' for objects, 'false' for background." }, + {0, 0} +}; +
-int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - using namespace scribo; + mln::trace::entering("main"); using namespace mln;
- if (argc < 1) - return usage(argv[0]); - - scribo::make::internal::debug_filename_prefix = argv[0]; + if (argc != 3) + return usage(argv, "Unskew a binary image", "input.pbm output.pbm", + args_desc, "A binary image.");
image2d<bool> input; io::pbm::load(input, argv[1]); - logical::not_inplace(input); - - trace::quiet = false; - - value::label_16 ncells; - image2dvalue::label_16 tables = scribo::table::extract(input, ncells).first();
- std::cout << "ncells (including background) = " << ncells << std::endl; - io::ppm::save(mln::labeling::colorize(value::rgb8(), tables, ncells), - scribo::make::debug_filename("table_cells.ppm")); + io::pbm::save(scribo::preprocessing::unskew(input), argv[2]);
- io::dump::save(tables, scribo::make::debug_filename("table_cells.dump")); + mln::trace::exiting("main"); } diff --git a/scribo/src/recognition.cc b/scribo/src/recognition.cc index 4c270f5..8bac8d2 100644 --- a/scribo/src/recognition.cc +++ b/scribo/src/recognition.cc @@ -25,45 +25,41 @@ // reasons why the executable file might be covered by the GNU General // Public License.
+/// \file scribo/src/recognition.cc +/// +/// Text extraction and recognition. + #include <iostream>
#include <mln/core/image/image2d.hh>
-#include <mln/labeling/colorize.hh> -#include <mln/labeling/wrap.hh> - -#include <mln/util/timer.hh> #include <mln/util/array.hh>
#include <mln/io/txt/save.hh> #include <mln/io/pbm/load.hh> -#include <mln/io/ppm/save.hh> -#include <mln/io/pgm/save.hh>
#include <mln/value/label_16.hh>
#include <mln/core/alias/neighb2d.hh>
-#include <scribo/text/extract_bboxes.hh> +#include <scribo/extract/primitive/objects.hh> + #include <scribo/text/grouping/group_with_several_left_links.hh> #include <scribo/text/grouping/group_with_several_right_links.hh> -#include <scribo/debug/save_linked_textbboxes_image.hh> #include <scribo/text/grouping/group_from_double_link.hh> -#include <scribo/filter/small_components.hh> -#include <scribo/filter/thin_bboxes.hh> +#include <scribo/filter/small_objects.hh> +#include <scribo/filter/thin_objects.hh> #include <scribo/text/recognition.hh>
-#include <scribo/debug/save_textbboxes_image.hh> -#include <scribo/make/debug_filename.hh> +#include <scribo/debug/usage.hh>
-#include <scribo/preprocessing/unskew.hh> - - -int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> <output.txt>" << std::endl; - return 1; -} + { "input.pbm", "A binary image. 'True' for objects, 'False'\ +for the background." }, + {0, 0} +}; +
int main(int argc, char* argv[]) @@ -71,36 +67,35 @@ int main(int argc, char* argv[]) using namespace scribo; using namespace mln;
- if (argc < 3) - return usage(argv[0]); + if (argc != 2) + return usage(argv, "Text extraction and recognition", "input.pbm", + args_desc, "The text is printed on the standard output.");
- scribo::make::internal::debug_filename_prefix = argv[2]; + trace::entering("main");
image2d<bool> input; io::pbm::load(input, argv[1]);
- input = preprocessing::unskew(input); - /// Extract text. + typedef mln_ch_value_(image2d<bool>,value::label_16) lbl_t; value::label_16 nbboxes; - scribo::util::text<image2dvalue::label_16 > text - = text::extract_bboxes(input, c8(), nbboxes); - text = filter::small_components(text,4); - text = filter::thin_bboxes(text,2); + object_image(lbl_t) + objects = scribo::extract::primitive::objects(input, c8(), nbboxes); + + /// Filter non interesting objects + objects = filter::small_objects(objects, 4); + objects = filter::thin_objects<lbl_t>(objects, 2); + + /// Group objects. mln::util::array<unsigned> left_link - = text::grouping::group_with_several_left_links(text, 30); + = text::grouping::group_with_several_left_links<lbl_t>(objects, 30); mln::util::array<unsigned> right_link - = text::grouping::group_with_several_right_links(text, 30); - text = text::grouping::group_from_double_link(text, left_link, right_link); - - io::ppm::save(mln::labeling::colorize(value::rgb8(), - labeling::wrap(text.label_image())), - scribo::make::debug_filename("lbl_color.ppm")); - io::pgm::save(labeling::wrap(text.label_image()), - scribo::make::debug_filename("lbl.pgm")); + = text::grouping::group_with_several_right_links(objects, 30); + objects = text::grouping::group_from_double_link(objects, left_link, right_link);
- image2d<char> ima_txt = scribo::text::recognition(text, "fra"); + /// Try to recognize text in grouped objects. + scribo::text::recognition(objects, "fra");
- io::txt::save(ima_txt, argv[2]); + trace::exiting("main"); }
diff --git a/scribo/src/table_extract.cc b/scribo/src/superpose.cc similarity index 60% copy from scribo/src/table_extract.cc copy to scribo/src/superpose.cc index b184e53..2e1cfce 100644 --- a/scribo/src/table_extract.cc +++ b/scribo/src/superpose.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory +// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -25,43 +25,44 @@ // reasons why the executable file might be covered by the GNU General // Public License.
-#include <iostream> +/// \file scribo/src/superpose.cc +/// +/// Superpose two binary images.
-#include <mln/essential/2d.hh> -#include <mln/io/dump/save.hh> +#include <mln/core/image/image2d.hh> +#include <mln/debug/superpose.hh> +#include <mln/logical/not.hh> +#include <mln/io/pbm/all.hh> +#include <mln/io/ppm/save.hh>
-#include <scribo/table/extract.hh> +#include <scribo/debug/usage.hh>
-int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} + { "input.pbm", "A binary image." }, + { "data.pbm", "A binary image." }, + {0, 0} +};
-int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - using namespace scribo; + mln::trace::entering("main"); using namespace mln;
- if (argc < 1) - return usage(argv[0]); - - scribo::make::internal::debug_filename_prefix = argv[0]; + if (argc != 4) + return usage(argv, "Superpose two binary images", "input.pbm data.pbm output.ppm", + args_desc, "A color image. Data from 'data.pbm' is colored in red.");
image2d<bool> input; io::pbm::load(input, argv[1]); - logical::not_inplace(input);
- trace::quiet = false; + image2d<bool> data; + io::pbm::load(data, argv[2]);
- value::label_16 ncells; - image2dvalue::label_16 tables = scribo::table::extract(input, ncells).first(); + io::ppm::save(debug::superpose(input, data), argv[3]);
- std::cout << "ncells (including background) = " << ncells << std::endl; - io::ppm::save(mln::labeling::colorize(value::rgb8(), tables, ncells), - scribo::make::debug_filename("table_cells.ppm")); - - io::dump::save(tables, scribo::make::debug_filename("table_cells.dump")); + mln::trace::exiting("main"); } + diff --git a/scribo/src/table/Makefile.am b/scribo/src/table/Makefile.am new file mode 100644 index 0000000..2575429 --- /dev/null +++ b/scribo/src/table/Makefile.am @@ -0,0 +1,11 @@ +## Process this file through Automake to create Makefile.in. + +include $(top_srcdir)/scribo/scribo.mk + +bin_PROGRAMS = \ + erase \ + extract + +erase_SOURCES = erase.cc +extract_SOURCES = extract.cc + diff --git a/scribo/src/table_erase.cc b/scribo/src/table/erase.cc similarity index 66% rename from scribo/src/table_erase.cc rename to scribo/src/table/erase.cc index 15cf880..dd9a21d 100644 --- a/scribo/src/table_erase.cc +++ b/scribo/src/table/erase.cc @@ -36,14 +36,18 @@
#include <scribo/table/extract.hh>
-#include <scribo/primitive/lines_h_discontinued.hh> -#include <scribo/primitive/lines_v_discontinued.hh> +#include <scribo/extract/primitive/lines_h_discontinued.hh> +#include <scribo/extract/primitive/lines_v_discontinued.hh>
-int usage(const char *name) +#include <scribo/debug/usage.hh> + +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} + { "input.pbm", "A binary image. 'True' for objects, 'False'\ +for the background." }, + {0, 0} +}; +
int main(int argc, char* argv[]) @@ -52,25 +56,30 @@ int main(int argc, char* argv[]) using namespace mln; using mln::value::label_16;
- if (argc < 1) - return usage(argv[0]); + if (argc != 3) + return usage(argv, "Remove tables from a binary image.", + "input.pbm output.pbm", + args_desc, "A binary image without tables.");
- scribo::make::internal::debug_filename_prefix = "table_erase"; + trace::entering("main");
image2d<bool> input; io::pbm::load(input, argv[1]); - logical::not_inplace(input);
- typedef util::couple<util::array<box2d>, - util::array<box2d> > tables_t; + typedef image2d<label_16> lbl_t;
label_16 nhlines, nvlines; - util::array<box2d> vlines, hlines; - image2d<label_16> lbl_v = primitive::lines_v_discontinued(input, c8(), - nvlines, 51, 8); - image2d<label_16> lbl_h = primitive::lines_h_discontinued(input, c8(), - nhlines, 51, 6); - - image2d<bool> input_notables = scribo::table::erase(input, tables); - io::pbm::save(input_notables, scribo::make::debug_filename("input_notables.pbm")); + object_image(lbl_t) + lbl_v = extract::primitive::lines_v_discontinued(input, c8(), + nvlines, 51, 8); + object_image(lbl_t) + lbl_h = extract::primitive::lines_h_discontinued(input, c8(), + nhlines, 51, 6); + + image2d<bool> input_notables + = scribo::table::erase(input, + mln::make::couple(lbl_v.bboxes(),lbl_h.bboxes())); + io::pbm::save(input_notables, argv[2]); + + trace::exiting("main"); } diff --git a/scribo/src/table_extract.cc b/scribo/src/table/extract.cc similarity index 70% rename from scribo/src/table_extract.cc rename to scribo/src/table/extract.cc index b184e53..7e3b57d 100644 --- a/scribo/src/table_extract.cc +++ b/scribo/src/table/extract.cc @@ -27,17 +27,25 @@
#include <iostream>
-#include <mln/essential/2d.hh> +#include <mln/core/image/image2d.hh> +#include <mln/io/pbm/load.hh> +#include <mln/io/ppm/save.hh> #include <mln/io/dump/save.hh> +#include <mln/value/label_16.hh> +#include <mln/labeling/colorize.hh> +#include <mln/value/rgb8.hh>
#include <scribo/table/extract.hh>
+#include <scribo/debug/usage.hh>
-int usage(const char *name) +const char *args_desc[][2] = { - std::cout << "Usage: " << name << " <input.pbm> " << std::endl; - return 1; -} + { "input.pbm", "A binary image. 'True' for objects, 'False'\ +for the background." }, + { "output.dump", "A label image stored as milena dump image." }, + {0, 0} +};
int main(int argc, char* argv[]) @@ -45,23 +53,23 @@ int main(int argc, char* argv[]) using namespace scribo; using namespace mln;
- if (argc < 1) - return usage(argv[0]); + if (argc != 4) + return usage(argv, "Extract tables from a binary image.", + "input.pbm output.dump output.ppm", + args_desc, "A color images. 'White' color means \ +the background, other colors indicates cells.");
- scribo::make::internal::debug_filename_prefix = argv[0]; + trace::entering("main");
image2d<bool> input; io::pbm::load(input, argv[1]); - logical::not_inplace(input); - - trace::quiet = false;
value::label_16 ncells; image2dvalue::label_16 tables = scribo::table::extract(input, ncells).first();
- std::cout << "ncells (including background) = " << ncells << std::endl; - io::ppm::save(mln::labeling::colorize(value::rgb8(), tables, ncells), - scribo::make::debug_filename("table_cells.ppm")); + io::ppm::save(mln::labeling::colorize(value::rgb8(), tables, ncells), argv[3]); + + io::dump::save(tables, argv[2]);
- io::dump::save(tables, scribo::make::debug_filename("table_cells.dump")); + trace::exiting("main"); }