$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
canvas.hh
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 #ifndef SCRIBO_PRIMITIVE_EXTRACT_CANVAS_HH
27 # define SCRIBO_PRIMITIVE_EXTRACT_CANVAS_HH
28 
32 
33 # include <mln/core/concept/image.hh>
34 # include <mln/labeling/background.hh>
35 # include <mln/util/array.hh>
36 # include <mln/util/couple.hh>
37 # include <mln/value/label_8.hh>
38 # include <mln/util/couple.hh>
39 
40 # include <scribo/table/align_lines_verticaly.hh>
41 # include <scribo/table/align_lines_horizontaly.hh>
42 # include <scribo/table/connect_vertical_lines.hh>
43 # include <scribo/table/connect_horizontal_lines.hh>
44 # include <scribo/table/repair_horizontal_lines.hh>
45 # include <scribo/table/repair_vertical_lines.hh>
46 
47 # include <scribo/debug/save_table_image.hh>
48 
49 
50 
51 namespace scribo
52 {
53 
54  namespace primitive
55  {
56 
57  namespace extract
58  {
59  using namespace mln;
60 
62 
72  template <typename I, typename V>
73  mln_ch_value(I,bool)
74  canvas(const Image<I>& input_,
75  const mln::util::array<box<mln_site(I)> >& hlines_,
76  const mln::util::array<box<mln_site(I)> >& vlines_,
77  unsigned max_dist_lines);
78 
79 
80 # ifndef MLN_INCLUDE_ONLY
81 
82 
83  template <typename I, typename V>
84  mln_ch_value(I,bool)
85  canvas(const Image<I>& input_,
86  const mln::util::array<box<mln_site(I)> >& hlines,
87  const mln::util::array<box<mln_site(I)> >& vlines,
88  unsigned max_dist_lines)
89  {
90  mln_trace("scribo::primitive::canvas");
91  const I& input = exact(input_);
92 
93  mlc_equal(mln_value(I), bool)::check();
94  mln_precondition(input.is_valid());
95 
96  typedef mln::util::array<box<mln_site(I)> > lines_t;
98  lines = mln::make::couple(hlines, vlines);
99 
100  mln::util::array<int> rows = align_lines_horizontaly(input, hlines, 5);
101  mln::util::array<int> cols = align_lines_verticaly(input, vlines, 5);
102 
103  repair_vertical_lines(input, lines, 30);
104  repair_horizontal_lines(input, lines, 30);
105 
106  // Connect vertical lines with horizontal lines.
107  connect_vertical_lines(rows, lines, input, max_dist_lines);
108  connect_horizontal_lines(cols, lines, input, max_dist_lines);
109 
110  mln_ch_value(I,bool) res;
111  initialize(res, input);
112  data::fill(res, false);
113  for_all_elements(i, lines.first())
114  mln::draw::box(res, lines.first()[i], true);
115  for_all_elements(i, lines.second())
116  mln::draw::box(res, lines.second()[i], true);
117 
118  return res;
119  }
120 
121 
122 # endif // ! MLN_INCLUDE_ONLY
123 
124  } // end of namespace scribo::primitive::extract
125 
126  } // end of namespace scribo::primitive
127 
128 } // end of namespace scribo
129 
130 #endif // ! SCRIBO_PRIMITIVE_EXTRACT_CANVAS_HH