$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
objects_thick.hh
1 // Copyright (C) 2009, 2010, 2011, 2014 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_THICK_HH
28 # define SCRIBO_FILTER_OBJECTS_THICK_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/neighborhood.hh>
36 
37 # include <mln/util/array.hh>
38 
39 # include <scribo/core/component_set.hh>
40 # include <scribo/primitive/extract/components.hh>
41 
42 
43 
44 namespace scribo
45 {
46 
47  namespace filter
48  {
49 
50  using namespace mln;
51 
62  //
63  template <typename I, typename N, typename V>
64  inline
65  mln_concrete(I)
66  objects_thick(const Image<I>& input_,
67  const Neighborhood<N>& nbh_,
68  const V& label_type,
69  unsigned max_thickness);
70 
71 
80  //
81  template <typename L>
82  inline
83  component_set<L>
84  objects_thick(const component_set<L>& components,
85  unsigned max_thickness);
86 
87 
88 # ifndef MLN_INCLUDE_ONLY
89 
90  namespace internal
91  {
92 
95  template <typename L>
96  struct thick_object_filter
97  : Function_v2b< thick_object_filter<L> >
98  {
99 
104  thick_object_filter(const component_set<L>& components,
105  unsigned max_thickness)
106  : components_(components), max_thickness_(max_thickness)
107  {
108  }
109 
110 
115  bool operator()(const mln_value(L)& l) const
116  {
117  if (l == literal::zero)
118  return false;
119  return components_(l).bbox().nrows() < max_thickness_
120  && components_(l).bbox().ncols() < max_thickness_;
121  }
122 
123 
125  component_set<L> components_;
126 
128  unsigned max_thickness_;
129  };
130 
131 
132  } // end of namespace scribo::filter::internal
133 
134 
135  template <typename I, typename N, typename V>
136  inline
137  mln_concrete(I)
138  objects_thick(const Image<I>& input_,
139  const Neighborhood<N>& nbh_,
140  const V& /* label_type */,
141  unsigned max_thickness)
142  {
143  mln_trace("scribo::filter::objects_thick");
144 
145  const I& input = exact(input_);
146  const N& nbh = exact(nbh_);
147 
148  mln_precondition(input.is_valid());
149  mln_precondition(nbh.is_valid());
150 
151  V nlabels;
152  typedef mln_ch_value(I,V) lbl_t;
153  component_set<lbl_t> components
154  = primitive::extract::components(input, nbh, nlabels);
155 
156  typedef internal::thick_object_filter<lbl_t> func_t;
157  func_t fv2b(components, max_thickness);
158  components.relabel(fv2b);
159 
160  mln_concrete(I) output = duplicate(input);
161  data::fill((output | pw::value(components) == literal::zero).rw(), false);
162 
163  return output;
164  }
165 
166 
167  template <typename L>
168  inline
169  component_set<L>
170  objects_thick(const component_set<L>& components,
171  unsigned max_thickness)
172  {
173  mln_trace("scribo::filter::objects_thick");
174 
175  mln_precondition(components.is_valid());
176 
177  typedef internal::thick_object_filter<L> func_t;
178  func_t is_not_too_thick(components, max_thickness);
179 
180  component_set<L> output = components.duplicate();
181  output.update_tags(is_not_too_thick, component::Ignored);
182 
183  return output;
184  }
185 
186 # endif // ! MLN_INCLUDE_ONLY
187 
188  } // end of namespace scribo::filter
189 
190 } // end of namespace scribo
191 
192 
193 #endif // ! SCRIBO_FILTER_OBJECTS_THICK_HH