$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rebuild_rank.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 #include <mln/data/compute.hh>
36 #include <mln/accu/maj_h.hh>
37 
38 #include <scribo/table/rebuild.hh>
39 #include <scribo/table/erase.hh>
40 #include <scribo/primitive/extract/lines_h_discontinued.hh>
41 #include <scribo/primitive/extract/lines_v_discontinued.hh>
42 #include <scribo/make/debug_filename.hh>
43 
44 int usage(const char *name)
45 {
46  std::cout << "Usage: " << name << " <input.pbm> " << std::endl;
47  return 1;
48 }
49 
50 
51 int main(int argc, char* argv[])
52 {
53  using namespace scribo;
54  using namespace mln;
55 
56  if (argc < 1)
57  return usage(argv[0]);
58 
59  scribo::make::internal::debug_filename_prefix = argv[0];
60 
61  image2d<bool> input;
62  io::pbm::load(input, argv[1]);
63  logical::not_inplace(input);
64 
65  typedef object_image(image2d<value::label_16>) lines_t;
66 
67  value::label_16 nbboxes;
68  lines_t hlines
69  = scribo::primitive::extract::lines_h_discontinued(input,
70  c8(),
71  nbboxes,
72  51,
73  6);
74  lines_t vlines
75  = scribo::primitive::extract::lines_v_discontinued(input,
76  c8(),
77  nbboxes,
78  51,
79  6);
80 
81  value::label_8 ncells;
82  image2d<value::label_8> tables
83  = scribo::table::rebuild(input,
84  mln::make::couple(vlines.bboxes(), hlines.bboxes()),
85  30,
86  ncells).first();
87 
88 
89  std::cout << "ncells (including background) = " << ncells << std::endl;
90  image2d<value::rgb8> table_color = mln::labeling::colorize(value::rgb8(), tables, ncells);
91 
92  value::label_8 bg = data::compute(accu::maj_h<value::label_8>(), tables);
93 
94  image2d<value::rgb8> sup = data::convert(value::rgb8(), input);
95  data::paste((table_color | (pw::value(tables) != pw::cst(bg)))
96  | (pw::value(sup) == pw::cst(literal::black)), sup);
97  io::ppm::save(sup, scribo::make::debug_filename("table_color_sup.ppm"));
98 
99  io::ppm::save(table_color,
100  scribo::make::debug_filename("table_cells.ppm"));
101  io::pgm::save(tables, scribo::make::debug_filename("table_cells.pgm"));
102 
103  image2d<value::rgb8> input_rgb = data::convert(value::rgb8(), input);
104  data::fill((input_rgb | (pw::value(tables) == pw::cst(0u))).rw(), literal::red);
105  io::ppm::save(input_rgb, scribo::make::debug_filename("table_superposed.ppm"));
106 
107  image2d<bool> in_wo_tables = table::erase(input, hlines, vlines);
108  io::pbm::save(in_wo_tables,
109  scribo::make::debug_filename("input_wo_tables.pbm"));
110 
111 }