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