$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rebuild.hh
1 // Copyright (C) 2009, 2010, 2011 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef SCRIBO_TABLE_REBUILD_HH
28 # define SCRIBO_TABLE_REBUILD_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/alias/neighb2d.hh>
36 # include <mln/labeling/background.hh>
37 # include <mln/util/array.hh>
38 # include <mln/util/couple.hh>
39 # include <mln/value/label_8.hh>
40 # include <mln/literal/colors.hh>
41 
42 # include <scribo/table/align_lines_verticaly.hh>
43 # include <scribo/table/align_lines_horizontaly.hh>
44 # include <scribo/table/connect_vertical_lines.hh>
45 # include <scribo/table/connect_horizontal_lines.hh>
46 # include <scribo/table/repair_horizontal_lines.hh>
47 # include <scribo/table/repair_vertical_lines.hh>
48 
49 # include <scribo/debug/save_table_image.hh>
50 
51 
52 
53 namespace scribo
54 {
55 
56  namespace table
57  {
58 
59 
77  template <typename I, typename L>
80  component_set<L> > >
81  rebuild(const Image<I>& input,
82  const component_set<L>& vlines,
83  const component_set<L>& hlines,
84  unsigned max_dist_lines,
85  mln_value(L)& ncells);
86 
87 
88 # ifndef MLN_INCLUDE_ONLY
89 
90 
91  template <typename I, typename L>
94  component_set<L> > >
95  rebuild(const Image<I>& input_,
96  const component_set<L>& vlines,
97  const component_set<L>& hlines,
98  unsigned max_dist_lines,
99  mln_value(L)& ncells)
100  {
101  mln_trace("scribo::table::rebuild");
102  const I& input = exact(input_);
103 
104  mlc_equal(mln_value(I), bool)::check();
105  mln_precondition(input.is_valid());
106 
107 # ifndef SCRIBO_DEBUG
108  scribo::debug::save_table_image(input, vlines, hlines,
109  literal::red, "table-raw.ppm");
110 # endif
111 
112  mln::util::array<int> rows = align_lines_horizontaly(input, vlines, 5);
113  mln::util::array<int> cols = align_lines_verticaly(input, hlines, 5);
114 
115 # ifndef SCRIBO_DEBUG
116  scribo::debug::save_table_image(input, vlines, hlines,
117  literal::red, "table-aligned.ppm");
118 # endif
119 
120  repair_vertical_lines(input, vlines, 10);
121  repair_horizontal_lines(input, hlines, 10);
122 
123 # ifndef SCRIBO_DEBUG
124  scribo::debug::save_table_image(input, vlines, hlines,
125  literal::red, "table-repaired.ppm");
126 # endif
127 
128  // Connect vertical lines with horizontal lines.
129  connect_vertical_lines(rows, vlines, hlines, input, max_dist_lines);
130  connect_horizontal_lines(cols, vlines, hlines, input, max_dist_lines);
131 
132 # ifndef SCRIBO_DEBUG
133  scribo::debug::save_table_image(input, vlines, hlines,
134  literal::red, "table-connected.ppm");
135 # endif
136 
137 
138  mln_ch_value(I,bool) res;
139  initialize(res, input);
140  data::fill(res, false);
141  for_all_comps(i, vlines)
142  mln::draw::box(res, vlines(i).bbox(), true);
143  for_all_comps(i, hlines)
144  mln::draw::box(res, hlines(i).bbox(), true);
145 
146  L lbl = labeling::background(res, c8(), ncells);
147 
148  return mln::make::couple(lbl,
149  mln::make::couple(vlines, hlines));
150  }
151 
152 
153 # endif // ! MLN_INCLUDE_ONLY
154 
155  } // end of namespace scribo::table
156 
157 } // end of namespace scribo
158 
159 #endif // ! SCRIBO_TABLE_REBUILD_HH