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