26 #ifndef MLN_MAKE_RAG_AND_LABELED_WSL_HH
27 # define MLN_MAKE_RAG_AND_LABELED_WSL_HH
40 # include <mln/core/concept/image.hh>
41 # include <mln/core/concept/neighborhood.hh>
42 # include <mln/core/image/image2d.hh>
43 # include <mln/core/alias/box2d.hh>
44 # include <mln/extension/adjust_fill.hh>
45 # include <mln/util/graph.hh>
46 # include <mln/util/couple.hh>
91 template <
typename I,
typename N>
92 util::couple<util::graph,mln_concrete(I)>
94 const Neighborhood<N>& nbh_,
95 const mln_value(I)& nbasins);
99 # ifndef MLN_INCLUDE_ONLY
105 template <
typename I,
typename N>
108 rag_and_labeled_wsl_tests(
const Image<I>& wshd,
109 const Neighborhood<N>& nbh,
112 mln_precondition(exact(wshd).is_valid());
113 mln_precondition(exact(nbh).is_valid());
127 template <
typename I,
typename N>
129 util::couple<util::graph,mln_concrete(I)>
131 const Neighborhood<N>& nbh_,
132 const mln_value(I)& nbasins)
134 trace::entering(
"make::impl::generic::rag_and_labeled_wsl");
136 internal::rag_and_labeled_wsl_tests(wshd_, nbh_, nbasins);
137 const I& wshd = exact(wshd_);
138 const N& nbh = exact(nbh_);
139 typedef mln_value(I) L;
141 extension::adjust_fill(wshd, nbh, 0u);
143 mln_concrete(I) output(wshd.domain());
147 data::fill(output, mln_max(mln_value(I)).prev());
149 std::map<util::
couple<L,L>, mln_value(I)> c2la;
150 util::array<util::
couple<L,L> > la2c;
151 mln_value(I) nlabels = literal::zero;
154 mln_piter(I) p(wshd.domain());
155 mln_niter(N) n(nbh, p);
163 if (wshd.has(n) && wshd(n) != 0u)
170 mln_invariant(l2 == 0u);
175 if (l2 == 0u || l1 == 0u)
182 if (c2la.find(c) == c2la.end())
193 g.add_vertices(nbasins.next());
194 for (
unsigned i = 0; i < la2c.nelements(); ++i)
195 g.add_edge(la2c[i].first(), la2c[i].second());
197 trace::exiting(
"make::impl::generic::rag_and_labeled_wsl");
210 template <
typename I,
typename N>
212 util::couple<util::graph,mln_concrete(I)>
213 rag_and_labeled_wsl_dispatch(
const Image<I>& wshd,
214 const Neighborhood<N>& nbh,
215 const mln_value(I)& nbasins)
217 return make::impl::generic::rag_and_labeled_wsl(wshd, nbh, nbasins);
226 template <
typename I,
typename N>
228 util::couple<util::graph,mln_concrete(I)>
231 const mln_value(I)& nbasins)
233 trace::entering(
"make::rag_and_labeled_wsl");
235 internal::rag_and_labeled_wsl_tests(wshd, nbh, nbasins);
238 result = internal::rag_and_labeled_wsl_dispatch(wshd, nbh, nbasins);
240 trace::exiting(
"make::rag_and_labeled_wsl");
245 # endif // ! MLN_INCLUDE_ONLY
253 #endif // ! MLN_MAKE_RAG_AND_LABELED_WSL_HH