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