$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
extract_lines.hh
1 // Copyright (C) 2009, 2010, 2011, 2012 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_TEXT_EXTRACT_LINES_HH
28 # define SCRIBO_TEXT_EXTRACT_LINES_HH
29 
33 
34 
35 # include <mln/core/concept/image.hh>
36 
37 # include <scribo/core/def/lbl_type.hh>
38 # include <scribo/core/line_set.hh>
39 
40 # include <scribo/primitive/extract/components.hh>
41 
42 # include <scribo/primitive/link/merge_double_link.hh>
43 # include <scribo/primitive/link/internal/dmax_width_and_height.hh>
44 # include <scribo/primitive/link/with_single_left_link_dmax_ratio.hh>
45 # include <scribo/primitive/link/with_single_right_link_dmax_ratio.hh>
46 
47 # include <scribo/filter/objects_small.hh>
48 
49 # include <scribo/primitive/group/apply.hh>
50 # include <scribo/primitive/group/from_single_link.hh>
51 
52 # include <scribo/filter/object_links_bbox_h_ratio.hh>
53 
54 # include <scribo/text/merging.hh>
55 
56 
57 namespace scribo
58 {
59 
60  namespace text
61  {
62 
63  using namespace mln;
64 
75  template <typename I, typename N>
76  line_set<mln_ch_value(I,scribo::def::lbl_type)>
77  extract_lines(const Image<I>& input, const Neighborhood<N>& nbh,
78  const mln_ch_value(I,bool)& separators);
79 
83  template <typename I, typename N>
84  line_set<mln_ch_value(I,scribo::def::lbl_type)>
85  extract_lines(const Image<I>& input, const Neighborhood<N>& nbh);
86 
87 
91  template <typename L>
92  line_set<mln_ch_value(L,scribo::def::lbl_type)>
93  extract_lines(const component_set<L>& input);
94 
95 
96 # ifndef MLN_INCLUDE_ONLY
97 
98 
99  template <typename I, typename N>
100  line_set<mln_ch_value(I,scribo::def::lbl_type)>
101  extract_lines(const Image<I>& input, const Neighborhood<N>& nbh)
102  {
103  mln_ch_value(I,bool) seps;
104  return extract_lines(input, nbh, seps);
105  }
106 
107 
108  template <typename I, typename N>
109  line_set<mln_ch_value(I,scribo::def::lbl_type)>
110  extract_lines(const Image<I>& input_, const Neighborhood<N>& nbh_,
111  const mln_ch_value(I,bool)& separators)
112  {
113  mln_trace("scribo::text::extract_lines");
114 
115  const I& input = exact(input_);
116  const N& nbh = exact(nbh_);
117 
118  mln_precondition(input.is_valid());
119  mln_precondition(nbh.is_valid());
120 
122  typedef mln_ch_value(I,scribo::def::lbl_type) L;
123  scribo::def::lbl_type ncomps;
124  component_set<L>
125  comps = scribo::primitive::extract::components(input, nbh, ncomps);
126 
128  comps = scribo::filter::components_small(comps, 3);
129 
131  if (exact(separators).is_valid())
132  comps.add_separators(separators);
133 
134  line_set<mln_ch_value(I,scribo::def::lbl_type)>
135  lines = extract_lines(comps);
136 
137  return lines;
138  }
139 
140 
141  template <typename L>
142  line_set<mln_ch_value(L,scribo::def::lbl_type)>
143  extract_lines(const component_set<L>& comps)
144  {
145  mln_trace("scribo::text::extract_lines");
146 
147  mln_precondition(comps.is_valid());
148 
150  object_links<L>
152  comps,
153 // primitive::link::internal::dmax_width_and_height(1),
154  primitive::link::internal::dmax_default(1),
155  anchor::MassCenter);
156 
157  object_links<L>
159  comps,
160 // primitive::link::internal::dmax_width_and_height(1),
161  primitive::link::internal::dmax_default(1),
162  anchor::MassCenter);
163 
164  // Validating left and right links.
165  object_links<L>
166  merged_links = primitive::link::merge_double_link(left_link,
167  right_link);
168 
169 
170  object_links<L> hratio_filtered_links
171  = filter::object_links_bbox_h_ratio(merged_links, 2.5f);
172 
173  object_groups<L>
174  groups = primitive::group::from_single_link(hratio_filtered_links);
175 
176  line_set<L> lines(groups);
177  lines = text::merging(lines);
178 
179  return lines;
180  }
181 
182 # endif // ! MLN_INCLUDE_ONLY
183 
184  } // end of namespace scribo::text
185 
186 } // end of namespace scribo
187 
188 #endif // ! SCRIBO_TEXT_EXTRACT_LINES_HH