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
00027 #ifndef MLN_TOPO_SKELETON_CREST_HH
00028 # define MLN_TOPO_SKELETON_CREST_HH
00029
00033
00034 # include <mln/core/concept/image.hh>
00035 # include <mln/core/concept/neighborhood.hh>
00036 # include <mln/data/fill.hh>
00037
00038
00039 namespace mln
00040 {
00041
00042 namespace topo
00043 {
00044
00045 namespace skeleton
00046 {
00047
00048
00060
00090 template <typename I, typename D, typename N>
00091 mln_concrete(I)
00092 crest(const Image<I>& input, const Image<D>& dist_map,
00093 const Neighborhood<N>& nbh, unsigned psi_threshold);
00094
00097 template <typename I, typename D, typename N>
00098 mln_concrete(I)
00099 crest(const Image<I>& input, const Image<D>& dist_map,
00100 const Neighborhood<N>& nbh);
00101
00102
00103
00104 # ifndef MLN_INCLUDE_ONLY
00105
00106
00107 template <typename I, typename D, typename N>
00108 mln_concrete(I)
00109 crest(const Image<I>& input_, const Image<D>& dist_map_,
00110 const Neighborhood<N>& nbh_, unsigned psi_threshold)
00111 {
00112 trace::entering("topo::skeleton::crest");
00113 const I& input = exact(input_);
00114 const D& dist_map = exact(dist_map_);
00115 const N& nbh = exact(nbh_);
00116
00117 mlc_equal(mln_value(I), bool)::check();
00118 mln_precondition(input.is_valid());
00119 mln_precondition(dist_map.is_valid());
00120 mln_precondition(nbh.is_valid());
00121
00122 mln_concrete(I) is_crest;
00123 initialize(is_crest, input);
00124 data::fill(is_crest, false);
00125
00126 mln_piter(I) p(input.domain());
00127 mln_niter(N) n(nbh, p);
00128 for_all(p)
00129 {
00130 if (!input(p) || dist_map(p) < static_cast<mln_value(D)>(0))
00131 continue;
00132
00133 unsigned nb_eq = 0;
00134 unsigned nb_lt = 0;
00135 for_all(n)
00136 if (input.domain().has(n)
00137
00138
00139
00140
00141 && dist_map(n) > static_cast<mln_value(D)>(0))
00142 {
00143 if (dist_map(n) == dist_map(p))
00144 ++nb_eq;
00145 else if (dist_map(n) < dist_map(p))
00146 ++nb_lt;
00147 }
00148
00149 if ((nb_lt + nb_eq) >= psi_threshold)
00150 is_crest(p) = true;
00151 }
00152
00153 trace::exiting("topo::skeleton::crest");
00154 return is_crest;
00155 }
00156
00157
00158 template <typename I, typename D, typename N>
00159 mln_concrete(I)
00160 crest(const Image<I>& input, const Image<D>& dist_map,
00161 const Neighborhood<N>& nbh)
00162 {
00163 return crest(input, dist_map, nbh, 6);
00164 }
00165
00166 # endif // ! MLN_INCLUDE_ONLY
00167
00168
00169 }
00170
00171 }
00172
00173 }
00174
00175 #endif // ! MLN_TOPO_SKELETON_CREST_HH