$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lines_h_single.hh
1 // Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 EPITA Research and
2 // Development 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_PRIMITIVE_EXTRACT_LINES_H_SINGLE_HH
28 # define SCRIBO_PRIMITIVE_EXTRACT_LINES_H_SINGLE_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/neighborhood.hh>
36 
37 # include <scribo/core/component_set.hh>
38 # include <scribo/primitive/extract/components.hh>
39 
40 
41 namespace scribo
42 {
43 
44  namespace primitive
45  {
46 
47  namespace extract
48  {
49 
50 
51  using namespace mln;
52 
72  template <typename I, typename N, typename V>
73  component_set<mln_ch_value(I,V)>
74  lines_h_single(const Image<I>& input,
75  const Neighborhood<N>& nbh, const V& nlines,
76  unsigned min_line_length,
77  float w_h_ratio);
78 
79 
96  template <typename L>
97  component_set<L>
98  lines_h_single(const component_set<L>& components,
99  unsigned min_line_length,
100  float w_h_ratio);
101 
102 
103 # ifndef MLN_INCLUDE_ONLY
104 
105  namespace internal
106  {
107 
108  template <typename L>
109  struct is_line_h_single
110  : Function_v2b<is_line_h_single<L> >
111  {
112  typedef bool result;
113 
114  is_line_h_single(const component_set<L>& components,
115  float w_h_ratio, unsigned min_line_length)
116  : w_h_ratio_(w_h_ratio), min_line_length_(min_line_length),
117  components_(components)
118  {
119  }
120 
121 
122  bool operator()(const mln_value(L)& label) const
123  {
124  const mln_domain(L)& box = components_(label).bbox();
125 
126  unsigned
127  height = box.pmax().row() - box.pmin().row() + 1,
128  width = box.pmax().col() - box.pmin().col() + 1;
129 
130  return ((width / (float)height) > w_h_ratio_
131  && width > min_line_length_);
132  }
133 
134  float w_h_ratio_;
135  unsigned min_line_length_;
136 
137  component_set<L> components_;
138  };
139 
140 
141  } // end of namespace mln::internal
142 
143 
144 
145 
146  template <typename I, typename N, typename V>
147  component_set<mln_ch_value(I,V)>
148  lines_h_single(const Image<I>& input_,
149  const Neighborhood<N>& nbh_, const V& /* nlines */,
150  unsigned min_line_length,
151  float w_h_ratio)
152  {
153  mln_trace("scribo::primitive::lines_h_single");
154 
155  const I& input = exact(input_);
156  const N& nbh = exact(nbh_);
157  mln_precondition(input.is_valid());
158  mln_precondition(nbh.is_valid());
159 
160  typedef mln_ch_value(I,V) L;
161  V ncomps;
162  component_set<L>
163  output = primitive::extract::components(input, nbh, ncomps);
164  (void) ncomps;
165 
166  internal::is_line_h_single<L>
167  is_line(output, w_h_ratio, min_line_length);
168 
169  output.update_tags(is_line, component::Ignored);
170 
171  return output;
172  }
173 
174 
175 
176 
177  template <typename L>
178  component_set<L>
179  lines_h_single(const component_set<L>& components,
180  unsigned min_line_length,
181  float w_h_ratio)
182  {
183  mln_trace("scribo::primitive::lines_h_single");
184 
185  mln_precondition(components.is_valid());
186 
187  internal::is_line_h_single<L>
188  is_line(components, w_h_ratio, min_line_length);
189 
190  component_set<L> output = components.duplicate();
191  output.update_tags(is_line, component::Ignored);
192 
193  return output;
194  }
195 
196 
197 # endif // ! MLN_INCLUDE_ONLY
198 
199 
200  } // end of namespace scribo::primitive::extract
201 
202  } // end of namespace scribo::primitive
203 
204 } // end of namespace scribo
205 
206 #endif // ! SCRIBO_PRIMITIVE_EXTRACT_LINES_H_SINGLE_HH