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_LABELING_REGIONAL_MAXIMA_HH
00028 # define MLN_LABELING_REGIONAL_MAXIMA_HH
00029
00033
00034 # include <mln/core/concept/image.hh>
00035 # include <mln/core/concept/neighborhood.hh>
00036 # include <mln/canvas/labeling/sorted.hh>
00037 # include <mln/data/fill.hh>
00038 # include <mln/data/sort_psites.hh>
00039
00040
00041 namespace mln
00042 {
00043
00044 namespace labeling
00045 {
00046
00056 template <typename I, typename N, typename L>
00057 mln_ch_value(I, L)
00058 regional_maxima(const Image<I>& input, const Neighborhood<N>& nbh,
00059 L& nlabels);
00060
00061
00062
00063 # ifndef MLN_INCLUDE_ONLY
00064
00065 namespace impl
00066 {
00067
00068
00069
00070 template <typename I>
00071 struct regional_maxima_functor
00072 {
00073 typedef mln_psite(I) P;
00074
00075
00076
00077 const I& input;
00078
00079
00080
00081 void init() { data::fill(attr, true); }
00082 bool handles(const P&) const { return true; }
00083 bool labels(const P& p) const { return attr(p); }
00084 bool equiv(const P& n, const P& p) const { return input(n) ==
00085 input(p); }
00086 void do_no_union(const P& n, const P& p) { mln_invariant(input(n) >
00087 input(p));
00088 attr(p) = false; (void)n; }
00089 void init_attr(const P&) {}
00090 void merge_attr(const P& r, const P& p) { attr(p) = attr(p) &&
00091 attr(r); }
00092
00093
00094
00095 void init_() { data::fill(attr, true); }
00096 bool handles_(unsigned) const { return true; }
00097 bool labels_(unsigned p) const { return attr.element(p); }
00098 bool equiv_(unsigned n, unsigned p) const { return input.element(n) ==
00099 input.element(p); }
00100 void do_no_union_(unsigned n, unsigned p) { mln_invariant(input.element(n) >
00101 input.element(p));
00102 attr.element(p) = false;
00103 (void) n;
00104 }
00105 void init_attr_(unsigned) {}
00106 void merge_attr_(unsigned r, unsigned p) { attr.element(p) = attr.element(p) &&
00107 attr.element(r); }
00108
00109
00110
00111 mln_ch_value(I, bool) attr;
00112
00113 regional_maxima_functor(const I& input)
00114 : input(input)
00115 {
00116 initialize(attr, input);
00117 }
00118 };
00119
00120
00121 }
00122
00123
00124
00125
00126
00127
00128 template <typename I, typename N, typename L>
00129 mln_ch_value(I, L)
00130 regional_maxima(const Image<I>& input_, const Neighborhood<N>& nbh_,
00131 L& nlabels)
00132 {
00133 trace::entering("labeling::regional_maxima");
00134
00135 const I& input = exact(input_);
00136 const N& nbh = exact(nbh_);
00137 mln_precondition(input.is_valid());
00138
00139 typedef impl::regional_maxima_functor<I> F;
00140 F f(exact(input));
00141 mln_ch_value(I, L)
00142 output = canvas::labeling::sorted(input, nbh, nlabels, f, true);
00143
00144 trace::exiting("labeling::regional_maxima");
00145 return output;
00146 }
00147
00148 # endif // ! MLN_INCLUDE_ONLY
00149
00150 }
00151
00152 }
00153
00154
00155 #endif // ! MLN_LABELING_REGIONAL_MAXIMA_HH