26 #ifndef MLN_MORPHO_APPROX_DILATION_HH
27 # define MLN_MORPHO_APPROX_DILATION_HH
33 # include <mln/core/concept/image.hh>
35 # include <mln/core/routine/duplicate.hh>
36 # include <mln/data/compare.hh>
38 # include <mln/transform/distance_front.hh>
39 # include <mln/pw/all.hh>
41 # include <mln/core/alias/neighb2d.hh>
42 # include <mln/make/w_window2d_int.hh>
43 # include <mln/win/disk2d.hh>
45 # include <mln/core/alias/neighb3d.hh>
46 # include <mln/make/w_window3d_int.hh>
47 # include <mln/win/sphere3d.hh>
61 template <
typename I,
typename W>
63 dilation(const Image<I>& input, const Window<W>& win);
67 # ifndef MLN_INCLUDE_ONLY
80 dilation_by_distance_thresholding_2d(const Image<I>& input_,
81 const Window< win::
disk2d >& win_)
83 trace::entering(
"morpho::approx::impl::dilation_by_distance_thresholding_2d");
85 const I& input = exact(input_);
88 mln_precondition(input.is_valid());
89 mln_precondition(win.is_valid());
91 int ws[] = { 00, 11, 0, 11, 0,
96 const unsigned coef = 5;
99 radius = coef * win.diameter() / 2,
102 mln_ch_value(I,
unsigned) dmap = transform::distance_front(input,
103 c4(), make::w_window2d_int(ws),
105 mln_concrete(I) output;
106 output =
duplicate((pw::value(dmap) <= pw::cst(radius)) | input.domain());
108 trace::exiting("morpho::approx::impl::dilation_by_distance_thresholding_2d");
114 template <typename I>
116 dilation_by_distance_thresholding_3d(const Image<I>& input_,
117 const Window< win::
sphere3d >& win_)
119 trace::entering(
"morpho::approx::impl::dilation_by_distance_thresholding_3d");
121 const I& input = exact(input_);
124 mln_precondition(input.is_valid());
125 mln_precondition(win.is_valid());
127 int ws[] = { 00, 21, 00,
138 const unsigned coef = 12;
141 radius = coef * win.diameter() / 2,
144 mln_ch_value(I,
unsigned) dmap = transform::distance_front(input,
145 c6(), make::w_window3d_int(ws),
147 mln_concrete(I) output;
148 output =
duplicate((pw::value(dmap) <= pw::cst(radius)) | input.domain());
150 trace::exiting("morpho::approx::impl::dilation_by_distance_thresholding_3d");
164 template <
typename I>
166 dilation_dispatch(trait::image::kind::logic,
170 return impl::dilation_by_distance_thresholding_2d(input, win);
173 template <
typename I>
175 dilation_dispatch(trait::image::kind::logic,
179 return impl::dilation_by_distance_thresholding_3d(input, win);
184 template <
typename I,
typename W>
186 dilation_dispatch(const I& input, const W& win)
188 return dilation_dispatch(mln_trait_image_kind(I)(),
197 template <
typename I,
typename W>
200 dilation(const Image<I>& input, const Window<W>& win)
202 trace::entering(
"morpho::approx::dilation");
204 mln_precondition(exact(input).is_valid());
205 mln_precondition(exact(win).is_valid());
207 mln_concrete(I) output;
208 output = internal::dilation_dispatch(exact(input), exact(win));
210 if (exact(win).is_centered())
211 mln_postcondition(output >= input);
213 trace::exiting("morpho::approx::dilation");
218 # endif // ! MLN_INCLUDE_ONLY
227 #endif // ! MLN_MORPHO_APPROX_DILATION_HH