00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MLN_MORPHO_EROSION_TOLERANT_HH
00027 # define MLN_MORPHO_EROSION_TOLERANT_HH
00028
00035
00036 # include <mln/accu/count_value.hh>
00037 # include <mln/accu/logic/land.hh>
00038 # include <mln/accu/logic/land_basic.hh>
00039 # include <mln/accu/stat/min.hh>
00040 # include <mln/accu/stat/min_h.hh>
00041 # include <mln/accu/transform.hh>
00042 # include <mln/morpho/general.hh>
00043 # include <mln/morpho/includes.hh>
00044 # include <mln/morpho/erosion.hh>
00045
00046 namespace mln
00047 {
00048
00049 namespace morpho
00050 {
00051
00053 template <typename I, typename W>
00054 mln_concrete(I)
00055 erosion_tolerant(const Image<I>& input, const Window<W>& win,
00056 unsigned rank);
00057
00058
00059 # ifndef MLN_INCLUDE_ONLY
00060
00061
00062
00063
00064 namespace impl
00065 {
00066
00067 template <typename I, typename W>
00068 mln_concrete(I)
00069 erosion_tolerant_on_set(const Image<I>& input_,
00070 const Window<W>& win_,
00071 unsigned rank)
00072 {
00073 trace::entering("morpho::impl::erosion_tolerant_on_set");
00074
00075 typedef mln_concrete(I) O;
00076 const I& input = exact(input_);
00077 const W& win = exact(win_);
00078
00079 extension::adjust_fill(input, win, true);
00080
00081 mln_ch_value(I, unsigned)
00082 tmp = accu::transform(input,
00083 accu::count_value<mln_value(I)>(false),
00084 win);
00085
00086 O output;
00087 output = duplicate(input);
00088
00089 mln_piter(I) p(input.domain());
00090 for_all(p)
00091 if (input(p) == true && tmp(p) >= rank)
00092 output(p) = false;
00093
00094 trace::exiting("morpho::impl::erosion_tolerant_on_set");
00095 return output;
00096 }
00097
00098
00099
00100 template <typename I, typename W>
00101 mln_concrete(I)
00102 erosion_tolerant_on_set_fastest(const Image<I>& input_,
00103 const Window<W>& win_,
00104 unsigned rank)
00105 {
00106 trace::entering("morpho::impl::erosion_tolerant_on_set_fastest");
00107
00108 typedef mln_concrete(I) O;
00109 const I& input = exact(input_);
00110 const W& win = exact(win_);
00111
00112 extension::adjust_fill(input, win, true);
00113
00114 typedef mln_ch_value(I, unsigned) tmp_t;
00115 tmp_t tmp = accu::transform(input,
00116 accu::count_value<mln_value(I)>(false),
00117 win);
00118
00119 O output;
00120 output = duplicate(input);
00121
00122 mln_pixter(const I) p(input);
00123 for_all(p)
00124 if (p.val() == true)
00125 if (tmp.element(p.offset()) >= rank)
00126 output.element(p.offset()) = false;
00127
00128 trace::exiting("morpho::impl::erosion_tolerant_on_set_fastest");
00129 return output;
00130 }
00131
00132 }
00133
00134
00135
00136
00137
00138
00139 namespace internal
00140 {
00141
00142 template <typename I, typename W>
00143 mln_concrete(I)
00144 erosion_tolerant_dispatch(trait::image::kind::any,
00145 trait::image::speed::any,
00146 const I& input, const W& win, unsigned rank)
00147 {
00148 mlc_abort(I)::check();
00149
00150 typedef mln_concrete(I) output_t;
00151 return output_t();
00152 }
00153
00154
00155 template <typename I, typename W>
00156 mln_concrete(I)
00157 erosion_tolerant_dispatch(trait::image::kind::logic,
00158 trait::image::speed::any,
00159 const I& input, const W& win, unsigned rank)
00160 {
00161 return impl::erosion_tolerant_on_set(input,
00162 win,
00163 rank);
00164 }
00165
00166 template <typename I, typename W>
00167 mln_concrete(I)
00168 erosion_tolerant_dispatch(trait::image::kind::logic,
00169 trait::image::speed::fastest,
00170 const I& input, const W& win, unsigned rank)
00171 {
00172 return impl::erosion_tolerant_on_set_fastest(input,
00173 win,
00174 rank);
00175 }
00176
00177
00178 template <typename I, typename W>
00179 inline
00180 mln_concrete(I)
00181 erosion_tolerant_dispatch(const Image<I>& input,
00182 const Window<W>& win,
00183 unsigned rank)
00184 {
00185 return erosion_tolerant_dispatch(mln_trait_image_kind(I)(),
00186 mln_trait_image_speed(I)(),
00187 exact(input), exact(win), rank);
00188 }
00189
00190 }
00191
00192
00193
00194
00195
00196
00197 template <typename I, typename W>
00198 inline
00199 mln_concrete(I)
00200 erosion_tolerant(const Image<I>& input, const Window<W>& win,
00201 unsigned rank)
00202 {
00203 trace::entering("morpho::erosion_tolerant");
00204 mln_precondition(exact(input).is_valid());
00205 mln_precondition(exact(win).is_valid());
00206
00207 mln_concrete(I)
00208 output = internal::erosion_tolerant_dispatch(input, win, rank);
00209
00210 trace::exiting("morpho::erosion_tolerant");
00211 return output;
00212 }
00213
00214 # endif // ! MLN_INCLUDE_ONLY
00215
00216 }
00217
00218 }
00219
00220
00221 #endif // ! MLN_MORPHO_EROSION_TOLERANT_HH