$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
compute_image.hh
1 // Copyright (C) 2009, 2013 EPITA Research and Development Laboratory
2 // (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_COMPUTE_IMAGE_HH
28 # define MLN_LABELING_COMPUTE_IMAGE_HH
29 
39 
40 # include <mln/core/concept/image.hh>
41 # include <mln/core/concept/accumulator.hh>
42 # include <mln/core/concept/meta_accumulator.hh>
43 
44 # include <mln/labeling/compute.hh>
45 
46 
47 namespace mln
48 {
49 
50  namespace labeling
51  {
52 
66  template <typename A, typename I, typename L>
67  mln_ch_value(L, mln_result(A))
68  compute_image(const util::array<mln_result(A)>& a,
69  const Image<I>& input,
70  const Image<L>& labels,
71  const mln_value(L)& nlabels);
72 
86  template <typename A, typename I, typename L>
87  inline
88  mln_ch_value(L, mln_result(A))
89  compute_image(const Accumulator<A>& accu,
90  const Image<I>& input,
91  const Image<L>& labels,
92  const mln_value(L)& nlabels);
93 
94 
108  template <typename A, typename I, typename L>
109  inline
110  mln_ch_value(L, mln_meta_accu_result(A, mln_value(I)))
111  compute_image(const Meta_Accumulator<A>& accu,
112  const Image<I>& input,
113  const Image<L>& labels,
114  const mln_value(L)& nlabels);
115 
116 
117 # ifndef MLN_INCLUDE_ONLY
118 
119  namespace internal
120  {
121 
122  template <typename A, typename L>
123  mln_ch_value(L, A)
124  compute_image(const util::array<A>& a,
125  const Image<L>& labels_,
126  const mln_value(L)& nlabels)
127  {
128  const L& labels = exact(labels_);
129  (void) nlabels;
130 
131  typedef mln_ch_value(L, A) O;
132  O output;
133  initialize(output, labels);
134 
135  mln_piter(L) p(labels.domain());
136  for_all(p)
137  {
138  mln_assertion(labels(p) <= nlabels);
139  output(p) = a[labels(p)];
140  }
141 
142  return output;
143  }
144 
145  } // end of namespace mln::labeling::internal
146 
147 
148  template <typename A, typename I, typename L>
149  inline
150  mln_ch_value(L, mln_result(A))
151  compute_image(const util::array<mln_result(A)>& a,
152  const Image<L>& labels,
153  const mln_value(L)& nlabels)
154  {
155  (void) nlabels;
156 
157  mln_trace("labeling::compute_image");
158 
159  mln_ch_value(L, mln_result(A)) output =
160  labeling::internal::compute_image(a, labels, nlabels);
161 
162  return output;
163  }
164 
165  template <typename A, typename I, typename L>
166  inline
167  mln_ch_value(L, mln_result(A))
168  compute_image(const Accumulator<A>& accu,
169  const Image<I>& input,
170  const Image<L>& labels,
171  const mln_value(L)& nlabels)
172  {
173  mln_trace("labeling::compute_image");
174 
175  util::array<mln_result(A)> res =
176  compute(accu, input, labels, nlabels);
177 
178  mln_ch_value(L, mln_result(A)) output =
179  internal::compute_image(res, labels, nlabels);
180 
181  return output;
182  }
183 
184  template <typename A, typename I, typename L>
185  inline
186  mln_ch_value(L, mln_meta_accu_result(A, mln_value(I)))
187  compute_image(const Meta_Accumulator<A>& accu,
188  const Image<I>& input,
189  const Image<L>& labels,
190  const mln_value(L)& nlabels)
191  {
192  mln_trace("labeling::compute_image");
193 
194  typedef mln_meta_accu_result(A, mln_value(I)) T;
195 
196  util::array<T> res =
197  compute(accu, input, labels, nlabels);
198 
199  mln_ch_value(L, T) output =
200  labeling::internal::compute_image(res, labels, nlabels);
201 
202  return output;
203  }
204 
205 # endif // ! MLN_INCLUDE_ONLY
206 
207  } // end of namespace mln::labeling
208 
209 } // end of namespace mln
210 
211 #endif // ! MLN_LABELING_COMPUTE_IMAGE_HH