$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
objects_thin.hh
1 // Copyright (C) 2009, 2010, 2011 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_FILTER_COMPONENTS_THIN_HH
28 # define SCRIBO_FILTER_COMPONENTS_THIN_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/neighborhood.hh>
36 # include <mln/core/image/dmorph/image_if.hh>
37 # include <mln/pw/all.hh>
38 
39 # include <mln/util/array.hh>
40 
41 # include <mln/data/transform.hh>
42 
43 # include <scribo/core/component_set.hh>
44 # include <scribo/primitive/extract/components.hh>
45 # include <scribo/filter/internal/compute.hh>
46 
47 namespace scribo
48 {
49 
50  namespace filter
51  {
52 
53  using namespace mln;
54 
65  //
66  template <typename I, typename N, typename V>
67  inline
68  mln_concrete(I)
69  components_thin(const Image<I>& input_,
70  const Neighborhood<N>& nbh_,
71  const V& label_type,
72  unsigned min_thickness);
73 
83  //
84  template <typename L>
85  inline
86  component_set<L>
87  components_thin(const component_set<L>& components,
88  unsigned min_thickness);
89 
90 
91 # ifndef MLN_INCLUDE_ONLY
92 
93  namespace internal
94  {
95 
96 
99  template <typename L>
100  struct components_thin_filter
101  : Function_v2b< components_thin_filter<L> >
102  {
107  components_thin_filter(const component_set<L>& components,
108  unsigned min_thickness)
109  : components_(components), min_thickness_(min_thickness)
110  {
111  }
112 
113 
118  bool operator()(const mln_value(L)& l) const
119  {
120  if (l == literal::zero)
121  return false;
122  return components_(l).bbox().nrows() > min_thickness_
123  && components_(l).bbox().ncols() > min_thickness_;
124  }
125 
127  component_set<L> components_;
128 
130  unsigned min_thickness_;
131  };
132 
133 
134  } // end of namespace scribo::filter::internal
135 
136 
137  template <typename I, typename N, typename V>
138  inline
139  mln_concrete(I)
140  components_thin(const Image<I>& input_,
141  const Neighborhood<N>& nbh_,
142  const V& label_type,
143  unsigned min_thickness)
144  {
145  mln_trace("scribo::filter::components_thin");
146 
147  const I& input = exact(input_);
148  const N& nbh = exact(nbh_);
149 
150  mln_precondition(input.is_valid());
151  mln_precondition(nbh.is_valid());
152  (void) label_type;
153 
154  V nlabels;
155  typedef mln_ch_value(I,V) lbl_t;
156  component_set<lbl_t> comps
157  = primitive::extract::components(input, nbh, nlabels);
158 
159  typedef internal::components_thin_filter<lbl_t> func_t;
160  func_t fv2b(comps, min_thickness);
161  mln_concrete(I)
162  output = mln::data::transform(comps.labeled_image(), fv2b);
163 
164  return output;
165  }
166 
167 
168  template <typename L>
169  inline
170  component_set<L>
171  components_thin(const component_set<L>& components,
172  unsigned min_thickness)
173  {
174  mln_trace("scribo::filter::components_thin");
175 
176  mln_precondition(components.is_valid());
177 
178  typedef internal::components_thin_filter<L> func_t;
179  func_t is_not_too_thin(components, min_thickness);
180 
181  component_set<L> output = components.duplicate();
182  output.update_tags(is_not_too_thin, component::Ignored);
183 
184  return output;
185  }
186 
187 # endif // ! MLN_INCLUDE_ONLY
188 
189  } // end of namespace scribo::filter
190 
191 } // end of namespace scribo
192 
193 
194 #endif // ! SCRIBO_FILTER_COMPONENTS_THIN_HH