$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
relabel.hh
1 // Copyright (C) 2008, 2009, 2010, 2013 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 MLN_LABELING_RELABEL_HH
28 # define MLN_LABELING_RELABEL_HH
29 
33 
34 
35 # include <mln/core/concept/image.hh>
36 
37 # include <mln/make/relabelfun.hh>
38 
39 # include <mln/data/transform.hh>
40 # include <mln/data/transform_inplace.hh>
41 
42 
43 
44 namespace mln
45 {
46 
47  namespace labeling
48  {
49 
62  template <typename I, typename F>
63  mln_concrete(I)
64  relabel(const Image<I>& label,
65  const mln_value(I)& nlabels,
66  mln_value(I)& new_nlabels,
67  const Function_v2b<F>& fv2b);
68 
69 
80  template <typename I, typename F>
81  mln_concrete(I)
82  relabel(const Image<I>& label,
83  const mln_value(I)& nlabels,
84  const Function_v2v<F>& fv2v);
85 
86 
96  template <typename I, typename F>
97  void
98  relabel_inplace(Image<I>& label,
99  const mln_value(I)& nlabels,
100  const Function_v2b<F>& fv2b);
101 
102 
112  template <typename I, typename F>
113  void
114  relabel_inplace(Image<I>& label,
115  const mln_value(I)& nlabels,
116  const Function_v2v<F>& fv2v);
117 
118 
119 # ifndef MLN_INCLUDE_ONLY
120 
121 
122 
123  namespace internal
124  {
125 
126  template <typename I>
127  void
128  relabel_tests(const Image<I>& label,
129  mln_value(I)& new_nlabels)
130  {
131  // FIXME: we may want to check that it is exactly a label.
132 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
133  mln_precondition(exact(label).is_valid());
134  (void) label;
135  (void) new_nlabels;
136  }
137 
138  template <typename I, typename F>
139  void
140  relabel_tests(const Image<I>& label,
141  const mln_value(I)& nlabels,
142  mln_value(I)& new_nlabels,
143  const Function<F>& f)
144  {
145  // FIXME: we may want to check that it is exactly a label.
146 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
147  mln_precondition(exact(label).is_valid());
148  (void) label;
149  (void) nlabels;
150  (void) new_nlabels;
151  (void) f;
152  }
153 
154  template <typename I, typename F>
155  void
156  relabel_tests(const Image<I>& label,
157  const mln_value(I)& nlabels,
158  const Function<F>& f)
159  {
160  // FIXME: we may want to check that it is exactly a label.
161 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
162  mln_precondition(exact(label).is_valid());
163  (void) label;
164  (void) nlabels;
165  (void) f;
166  }
167 
168  template <typename I, typename F>
169  inline
170  void
171  relabel_inplace_tests(Image<I>& label,
172  const mln_value(I)& nlabels,
173  const Function<F>& f)
174  {
175  // FIXME: we may want to check that it is exactly a label.
176 // mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
177  mln_precondition(exact(label).is_valid());
178  (void) label;
179  (void) nlabels;
180  (void) f;
181  }
182 
183  } // end of namespace mln::labeling::internal
184 
185 
186 
187  template <typename I, typename F>
188  inline
189  mln_concrete(I)
190  relabel(const Image<I>& label,
191  const mln_value(I)& nlabels,
192  const Function_v2v<F>& fv2v)
193  {
194  mln_trace("labeling::relabel");
195 
196 
197  mlc_not_equal(mln_result(F),bool)::check();
198  internal::relabel_tests(label, nlabels, fv2v);
199 
200  mln_concrete(I) output = data::transform(label, fv2v);
201 
202  return output;
203  }
204 
205 
206 
207  template <typename I, typename F>
208  inline
209  mln_concrete(I)
210  relabel(const Image<I>& label,
211  const mln_value(I)& nlabels,
212  mln_value(I)& new_nlabels,
213  const Function_v2b<F>& fv2b)
214  {
215  mln_trace("labeling::relabel");
216 
217  internal::relabel_tests(label, nlabels, new_nlabels, fv2b);
218 
219  typedef fun::i2v::array<mln_value(I)> fv2v_t;
220  fv2v_t fv2v = make::relabelfun(fv2b, nlabels, new_nlabels);
221  mln_concrete(I) output = labeling::relabel(label, new_nlabels, fv2v);
222 
223  return output;
224  }
225 
226 
227  template <typename I, typename F>
228  inline
229  void
230  relabel_inplace(Image<I>& label,
231  const mln_value(I)& nlabels,
232  const Function_v2v<F>& fv2v)
233  {
234  mln_trace("labeling::relabel_inplace");
235 
236  mlc_not_equal(mln_result(F),bool)::check();
237  internal::relabel_inplace_tests(label, nlabels, fv2v);
238 
239  data::transform_inplace(label, fv2v);
240 
241  }
242 
243 
244 
245  template <typename I, typename F>
246  inline
247  void
248  relabel_inplace(Image<I>& label,
249  const mln_value(I)& nlabels,
250  const Function_v2b<F>& fv2b)
251  {
252  mln_trace("labeling::relabel_inplace");
253 
254  internal::relabel_inplace_tests(label, nlabels, fv2b);
255 
256  typedef fun::i2v::array<mln_value(I)> fv2v_t;
257  mln_value(I) tmp;
258  fv2v_t fv2v = make::relabelfun(fv2b, nlabels, tmp);
259  labeling::relabel_inplace(label, tmp, fv2v);
260 
261  }
262 
263 # endif // ! MLN_INCLUDE_ONLY
264 
265  } // end of namespace mln::labeling
266 
267 } // end of namespace mln
268 
269 
270 #endif // ! MLN_LABELING_RELABEL_HH