27 #ifndef MLN_MORPHO_RD_HH
28 # define MLN_MORPHO_RD_HH
38 # include <mln/core/concept/image.hh>
39 # include <mln/core/concept/neighborhood.hh>
40 # include <mln/trait/value_.hh>
41 # include <mln/data/fill.hh>
42 # include <mln/data/compare.hh>
43 # include <mln/util/ord.hh>
52 template <
typename I,
typename N>
54 Rd(
const Image<I>& f,
const Image<I>& g,
const Neighborhood<N>& nbh);
57 # ifndef MLN_INCLUDE_ONLY
64 std::vector<unsigned> compute_histo(
const I& ima)
66 std::vector<unsigned> h(256, 0);
67 mln_piter(I)
p(ima.domain());
75 std::vector<mln_psite(I)> histo_reverse_sort(const I& ima)
77 std::vector<unsigned> h = compute_histo(ima);
79 std::vector<int> loc(256);
81 for (
int l = 254; l >= 0; --l)
82 loc[l] = loc[l+1] + h[l+1];
83 std::vector<mln_psite(I)>
vec(ima.domain().nsites());
85 mln_piter(I) p(ima.domain());
87 vec[loc[ima(p)]++] = p;
92 template <typename I, typename N>
95 typedef mln_psite(I) point;
96 typedef mln_value(I)
value;
107 mln_ch_value(I,
bool) is_proc;
108 mln_ch_value(I, point) parent;
109 std::vector<point> S;
112 Rd(const I& f, const I& g, const N& nbh)
113 : f(f), g(g), nbh(nbh),
120 S = histo_reverse_sort(g);
124 for (
unsigned i = 0; i < S.size(); ++i)
129 mln_niter(N) n(nbh, p);
132 if (f.domain().has(n))
133 assert(is_proc(n) == is_proc__(n, p));
134 if (f.has(n) && is_proc(n))
141 for (
int i = S.size() - 1; i >= 0; --i)
146 if (
o(p) == mln_max(value))
156 bool is_proc__(
const point& n,
const point& p)
const
162 void make_set(
const point& p)
177 bool equiv(
const point& r,
const point& p)
179 return g(r) == g(p) || g(p) >=
o(r);
183 void do_union(
const point& n,
const point& p)
195 o(p) = mln_max(value);
206 template <
typename I,
typename N>
209 Rd(
const Image<I>& f,
const Image<I>& g,
const Neighborhood<N>& nbh)
216 # endif // ! MLN_INCLUDE_ONLY
223 #endif // ! MLN_MORPHO_RD_HH