$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rebuild_opening.cc
1 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #include <iostream>
27 
28 #include <mln/core/image/image2d.hh>
29 #include <mln/core/image/dmorph/image_if.hh>
30 #include <mln/value/label_8.hh>
31 #include <mln/value/label_16.hh>
32 #include <mln/pw/all.hh>
33 #include <mln/io/pbm/all.hh>
34 #include <mln/util/couple.hh>
35 
36 #include <scribo/table/rebuild.hh>
37 #include <scribo/table/erase.hh>
38 #include <scribo/primitive/extract/lines_h_thick.hh>
39 #include <scribo/primitive/extract/lines_v_thick.hh>
40 #include <scribo/make/debug_filename.hh>
41 
42 int usage(const char *name)
43 {
44  std::cout << "Usage: " << name << " <input.pbm> " << std::endl;
45  return 1;
46 }
47 
48 
49 int main(int argc, char* argv[])
50 {
51  using namespace scribo;
52  using namespace mln;
53 
54  if (argc < 1)
55  return usage(argv[0]);
56 
57  scribo::make::internal::debug_filename_prefix = argv[0];
58 
59  image2d<bool> input;
60  io::pbm::load(input, argv[1]);
61  logical::not_inplace(input);
62 
63  typedef object_image(image2d<value::label_16>) lines_t;
64 
65  value::label_16 nbboxes;
66  lines_t hlines
67  = scribo::primitive::extract::lines_h_thick(input,
68  c8(),
69  nbboxes,
70  51);
71  lines_t vlines
72  = scribo::primitive::extract::lines_v_thick(input,
73  c8(),
74  nbboxes,
75  51);
76 
77  value::label_8 ncells;
78  image2d<value::label_8> tables
79  = scribo::table::rebuild(input,
80  mln::make::couple(vlines.bboxes(), hlines.bboxes()),
81  30,
82  ncells).first();
83 
84 
85  std::cout << "ncells (including background) = " << ncells << std::endl;
86  io::ppm::save(mln::labeling::colorize(value::rgb8(), tables, ncells),
87  scribo::make::debug_filename("table_cells.ppm"));
88  io::pgm::save(tables, scribo::make::debug_filename("table_cells.pgm"));
89 
90  image2d<value::rgb8> input_rgb = data::convert(value::rgb8(), input);
91  data::fill((input_rgb | (pw::value(tables) == pw::cst(0u))).rw(), literal::red);
92  io::ppm::save(input_rgb, scribo::make::debug_filename("table_superposed.ppm"));
93 
94  image2d<bool> in_wo_tables = table::erase(input, hlines, vlines);
95  io::pbm::save(in_wo_tables,
96  scribo::make::debug_filename("input_wo_tables.pbm"));
97 }