26 #ifndef MLN_MORPHO_RD_HH
27 # define MLN_MORPHO_RD_HH
37 # include <mln/core/concept/image.hh>
38 # include <mln/core/concept/neighborhood.hh>
39 # include <mln/trait/value_.hh>
40 # include <mln/data/fill.hh>
41 # include <mln/data/compare.hh>
42 # include <mln/util/ord.hh>
51 template <
typename I,
typename N>
53 Rd(
const Image<I>& f,
const Image<I>& g,
const Neighborhood<N>& nbh);
56 # ifndef MLN_INCLUDE_ONLY
63 std::vector<unsigned> compute_histo(
const I& ima)
65 std::vector<unsigned> h(256, 0);
66 mln_piter(I) p(ima.domain());
74 std::vector<mln_psite(I)> histo_reverse_sort(const I& ima)
76 std::vector<unsigned> h = compute_histo(ima);
78 std::vector<int> loc(256);
80 for (
int l = 254; l >= 0; --l)
81 loc[l] = loc[l+1] + h[l+1];
82 std::vector<mln_psite(I)>
vec(ima.domain().nsites());
84 mln_piter(I) p(ima.domain());
86 vec[loc[ima(p)]++] = p;
91 template <typename I, typename N>
94 typedef mln_psite(I) point;
95 typedef mln_value(I) value;
106 mln_ch_value(I,
bool) is_proc;
107 mln_ch_value(I, point) parent;
108 std::vector<point> S;
111 Rd(const I& f, const I& g, const N& nbh)
112 : f(f), g(g), nbh(nbh),
119 S = histo_reverse_sort(g);
123 for (
unsigned i = 0; i < S.size(); ++i)
128 mln_niter(N) n(nbh, p);
131 if (f.domain().has(n))
132 assert(is_proc(n) == is_proc__(n, p));
133 if (f.has(n) && is_proc(n))
140 for (
int i = S.size() - 1; i >= 0; --i)
145 if (o(p) == mln_max(value))
155 bool is_proc__(
const point& n,
const point& p)
const
161 void make_set(
const point& p)
167 point find_root(
const point& x)
172 return parent(x) = find_root(parent(x));
176 bool equiv(
const point& r,
const point& p)
178 return g(r) == g(p) || g(p) >= o(r);
182 void do_union(
const point& n,
const point& p)
184 point r = find_root(n);
194 o(p) = mln_max(value);
205 template <
typename I,
typename N>
208 Rd(
const Image<I>& f,
const Image<I>& g,
const Neighborhood<N>& nbh)
211 impl::Rd<I,N> run(exact(f), exact(g), exact(nbh));
215 # endif // ! MLN_INCLUDE_ONLY
222 #endif // ! MLN_MORPHO_RD_HH