$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
approx/dilation.hh
1 // Copyright (C) 2009, 2012 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_MORPHO_APPROX_DILATION_HH
28 # define MLN_MORPHO_APPROX_DILATION_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 
36 # include <mln/core/routine/duplicate.hh>
37 # include <mln/data/compare.hh>
38 
39 # include <mln/transform/distance_front.hh>
40 # include <mln/pw/all.hh>
41 
42 # include <mln/core/alias/neighb2d.hh>
43 # include <mln/make/w_window2d_int.hh>
44 # include <mln/win/disk2d.hh>
45 
46 # include <mln/core/alias/neighb3d.hh>
47 # include <mln/make/w_window3d_int.hh>
48 # include <mln/win/sphere3d.hh>
49 
50 
51 
52 namespace mln
53 {
54 
55  namespace morpho
56  {
57 
58  namespace approx
59  {
60 
65  template <typename I, typename W>
66  mln_concrete(I)
67  dilation(const Image<I>& input, const Window<W>& win);
68 
69 
70 
71 # ifndef MLN_INCLUDE_ONLY
72 
73 
74  // Implementations.
75 
76  namespace impl
77  {
78 
79 
80  // By distance thresholding.
81 
82  template <typename I>
83  mln_concrete(I)
84  dilation_by_distance_thresholding_2d(const Image<I>& input_,
85  const Window< win::disk2d >& win_)
86  {
87  mln_trace("morpho::approx::impl::dilation_by_distance_thresholding_2d");
88 
89  const I& input = exact(input_);
90  const win::disk2d& win = exact(win_);
91 
92  mln_precondition(input.is_valid());
93  mln_precondition(win.is_valid());
94 
95  int ws[] = { 00, 11, 0, 11, 0,
96  11, 7, 5, 7, 11,
97  00, 5, 0, 5, 0,
98  11, 7, 5, 7, 11,
99  00, 11, 0, 11, 0 };
100  const unsigned coef = 5;
101 
102  unsigned
103  radius = coef * win.diameter() / 2,
104  dmax = radius + 1;
105 
106  mln_ch_value(I, unsigned) dmap = transform::distance_front(input,
107  c4(), make::w_window2d_int(ws),
108  dmax);
109  mln_concrete(I) output;
110  output = duplicate((pw::value(dmap) <= pw::cst(radius)) | input.domain());
111 
112  return output;
113  }
114 
115 
116 
117  template <typename I>
118  mln_concrete(I)
119  dilation_by_distance_thresholding_3d(const Image<I>& input_,
120  const Window< win::sphere3d >& win_)
121  {
122  mln_trace("morpho::approx::impl::dilation_by_distance_thresholding_3d");
123 
124  const I& input = exact(input_);
125  const win::sphere3d& win = exact(win_);
126 
127  mln_precondition(input.is_valid());
128  mln_precondition(win.is_valid());
129 
130  int ws[] = { 00, 21, 00,
131  21, 17, 21,
132  00, 21, 00,
133 
134  17, 12, 17,
135  12, 00, 12,
136  17, 12, 17,
137 
138  00, 21, 00,
139  21, 17, 21,
140  00, 21, 00 };
141  const unsigned coef = 12;
142 
143  unsigned
144  radius = coef * win.diameter() / 2,
145  dmax = radius + 1;
146 
147  mln_ch_value(I, unsigned) dmap = transform::distance_front(input,
148  c6(), make::w_window3d_int(ws),
149  dmax);
150  mln_concrete(I) output;
151  output = duplicate((pw::value(dmap) <= pw::cst(radius)) | input.domain());
152 
153  return output;
154  }
155 
156 
157  } // end of namespace mln::morpho::approx::impl
158 
159 
160 
161  // Dispatch.
162 
163  namespace internal
164  {
165 
166  template <typename I>
167  mln_concrete(I)
168  dilation_dispatch(trait::image::kind::logic,
169  const I& input,
170  const win::disk2d& win)
171  {
172  return impl::dilation_by_distance_thresholding_2d(input, win);
173  }
174 
175  template <typename I>
176  mln_concrete(I)
177  dilation_dispatch(trait::image::kind::logic,
178  const I& input,
179  const win::sphere3d& win)
180  {
181  return impl::dilation_by_distance_thresholding_3d(input, win);
182  }
183 
184  // Entry point.
185 
186  template <typename I, typename W>
187  mln_concrete(I)
188  dilation_dispatch(const I& input, const W& win)
189  {
190  return dilation_dispatch(mln_trait_image_kind(I)(),
191  input, win);
192  }
193 
194  } // end of namespace mln::morpho::approx::internal
195 
196 
197  // Facade.
198 
199  template <typename I, typename W>
200  inline
201  mln_concrete(I)
202  dilation(const Image<I>& input, const Window<W>& win)
203  {
204  mln_trace("morpho::approx::dilation");
205 
206  mln_precondition(exact(input).is_valid());
207  mln_precondition(exact(win).is_valid());
208 
209  mln_concrete(I) output;
210  output = internal::dilation_dispatch(exact(input), exact(win));
211 
212  if (exact(win).is_centered())
213  mln_postcondition(output >= input);
214 
215  return output;
216  }
217 
218 
219 # endif // ! MLN_INCLUDE_ONLY
220 
221  } // end of namespace mln::morpho::approx
222 
223  } // end of namespace mln::morpho
224 
225 } // end of namespace mln
226 
227 
228 #endif // ! MLN_MORPHO_APPROX_DILATION_HH