$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
objects_h_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_OBJECTS_H_THIN_HH
28 # define SCRIBO_FILTER_OBJECTS_H_THIN_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/filter/internal/compute.hh>
39 
40 namespace scribo
41 {
42 
43  namespace filter
44  {
45 
46  using namespace mln;
47 
58  //
59  template <typename I, typename N, typename V>
60  inline
61  mln_concrete(I)
62  objects_h_thin(const Image<I>& input_,
63  const Neighborhood<N>& nbh_,
64  const V& label_type,
65  unsigned min_thinness);
66 
75  //
76  template <typename L>
77  inline
78  component_set<L>
79  objects_h_thin(const component_set<L>& comps,
80  unsigned min_thinness);
81 
82 
83 # ifndef MLN_INCLUDE_ONLY
84 
85  namespace internal
86  {
87 
88 
91  template <typename L>
92  struct objects_h_thin_filter
93  : Function_v2b< objects_h_thin_filter<L> >
94  {
95  typedef accu::shape::bbox<mln_psite(L)> box_accu_t;
96 
102  //
103  objects_h_thin_filter(const component_set<L>& comps,
104  unsigned min_thinness)
105  : comps_(comps), min_thinness_(min_thinness)
106  {
107  }
108 
109 
113  //
114  objects_h_thin_filter(unsigned min_thinness)
115  : min_thinness_(min_thinness)
116  {
117  }
118 
120  //
121  void update_objects(const component_set<L>& comps)
122  {
123  comps_ = comps;
124  }
125 
126 
131  //
132  bool operator()(const mln_value(L)& l) const
133  {
134  if (l == literal::zero)
135  return false;
136  return comps_(l).bbox().width() > min_thinness_;
137  }
138 
140  component_set<L> comps_;
141 
143  unsigned min_thinness_;
144  };
145 
146 
147  } // end of namespace scribo::filter::internal
148 
149 
150  template <typename I, typename N, typename V>
151  inline
152  mln_concrete(I)
153  objects_h_thin(const Image<I>& input_,
154  const Neighborhood<N>& nbh_,
155  const V& label_type,
156  unsigned min_thinness)
157  {
158  mln_trace("scribo::filter::objects_h_thin");
159 
160  const I& input = exact(input_);
161  const N& nbh = exact(nbh_);
162 
163  mln_precondition(input.is_valid());
164  mln_precondition(nbh.is_valid());
165 
166  internal::objects_h_thin_filter<V> functor(min_thinness);
167  mln_concrete(I)
168  output = internal::compute(input, nbh, label_type, functor);
169 
170 
171  return output;
172  }
173 
174 
175  template <typename L>
176  inline
177  component_set<L>
178  objects_h_thin(const component_set<L>& comps,
179  unsigned min_thinness)
180  {
181  mln_trace("scribo::filter::objects_h_thin");
182 
183  internal::objects_h_thin_filter<L>
184  is_not_too_h_thin(comps, min_thinness);
185 
186  component_set<L> output = internal::compute(comps, is_not_too_h_thin);
187 
188  return output;
189  }
190 
191 # endif // ! MLN_INCLUDE_ONLY
192 
193  } // end of namespace scribo::filter
194 
195 } // end of namespace scribo
196 
197 
198 #endif // ! SCRIBO_FILTER_OBJECTS_H_THIN_HH