
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-10-19 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Update fllt. * fllt.hh: Update. --- fllt.hh | 184 +++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 142 insertions(+), 42 deletions(-) Index: trunk/milena/sandbox/garrigues/fllt.hh =================================================================== --- trunk/milena/sandbox/garrigues/fllt.hh (revision 1359) +++ trunk/milena/sandbox/garrigues/fllt.hh (revision 1360) @@ -44,11 +44,13 @@ # include <mln/core/image_if.hh> # include <mln/debug/println.hh> +# include <mln/convert/to_image.hh> # include <mln/level/compute.hh> # include <mln/accu/min.hh> # include <mln/labeling/regional_minima.hh> +# include <mln/labeling/level.hh> # include <mln/fun/ops.hh> # include <mln/pw/value.hh> @@ -57,6 +59,8 @@ namespace mln { +// LOWER LEVEL SET : region = c4, border = c8 +// UPPER LEVEL SET : region = c8, border = c4 // 1) // x0 <- a not tagged local mininum of ima. @@ -94,44 +98,24 @@ // set the gray-level of the pixels of R to g. // GO TO 1) - template <typename V> - void compute_level_set(image2d<V>& ima) - { - typedef point2d P; - typedef image2d<V> I; - typedef mln::image_if< - mln::image2d<V>, - mln::fun::greater_p2b_expr_<mln::pw::value_<mln::image2d<V> >, - mln::pw::cst_<V> > - > I_IF; - - - set_p<P> R, N, A; - V g, gn; - point2d x0; - image2d<V> min_locals(ima.domain()); - image2d<bool> tagged(ima.domain()); - - unsigned nlabels; - labeling::regional_minima(ima, c4(), min_locals, nlabels); - - debug::println(min_locals); - debug::println(min_locals | (pw::value(min_locals) > pw::cst(0))); - - mln_piter(I_IF) p((min_locals | (pw::value(min_locals) > pw::cst(0))).domain()); - for_all(p) + void step1 (const image2d<V>& ima, + point2d p, + V& g, + point2d& x0) { - if (tagged(p)) - continue; - - // 1) // x0 <- a not tagged local mininum of ima. x0 = p; // g <- u(x0) g = ima(x0); + } - // 2) + template <typename P> + void step2 (set_p<P>& A, + set_p<P>& R, + set_p<P>& N, + point2d& x0) + { // A <- {x0} A.clear(); A.insert(x0); @@ -139,10 +123,20 @@ R.clear(); // N <- {} N.clear(); + } - // 3) + + template <typename V, typename P> + void step3 (const image2d<V>& ima, + image2d<bool>& tagged, + set_p<P>& A, + set_p<P>& R, + set_p<P>& N, + V& gn) + { // N <- N union {x neighbor of a pixel in a\R} mln_piter(set_p<P>) qa(A); + for_all(qa) { mln_niter(neighb2d) n(c4(), qa); @@ -162,38 +156,144 @@ R.insert(qa); tagged(qa) = true; } + } - // 4) - // IF g < gn - if (g < gn) + /// IF g < gn. + template <typename V, typename P> + void step4_1 (const image2d<V>& ima, + image2d<bool>& tagged, + set_p<P>& A, + set_p<P>& R, + set_p<P>& N, + V& gn) { + image2d<int> tmp; + unsigned n; + labeling::level(convert::to_image(N), true, c8(), tmp, n); + // IF number of conected components of the border > 1 // follow each border to find which is the exterior border // and which are the holes. Keep one pixel of each holes. - // + // Remove from N border of holes. // Recompute gn <- min u(x) x belongs to A - // + // g <- gn // A <- {x belongs to N / u(x) == g} // N <- N\{x belongs to N / u(x) == g} - // GO TO 3) + } - // IF g == gn - if (g == gn) + + /// IF g == gn. + template <typename V, typename P> + void step4_2 (const image2d<V>& ima, + set_p<P>& A, + set_p<P>& N, + V& g) { + // A <- {x belongs to N / u(x) == g} // N <- N\{x belongs to N / u(x) == g} + + set_p<P> N_tmp (N); + + A.clear(); + N.clear(); + mln_piter(set_p<P>) p(N_tmp); + for_all(p) + { + if (ima (p) == g) + { + A.insert(p); + N.insert(p); + } + } + } + + /// IF g > gn. + template <typename V, typename P> + void step4_3 (image2d<V>& u, + set_p<P>& R, + V& g) + { + // set the gray-level of the pixels of R to g. + mln_piter(set_p<P>) p(R); + for_all(p) + { + mln_assertion (tagged(p)); + u (p) = g; + } + } + + + + + + template <typename V> + void compute_level_set(const image2d<V>& ima) + { + typedef point2d P; + typedef image2d<V> I; + typedef mln::image_if< + mln::image2d<V>, + mln::fun::greater_p2b_expr_<mln::pw::value_<mln::image2d<V> >, + mln::pw::cst_<V> > + > I_IF; + + + set_p<P> R, N, A; + V g, gn; + point2d x0; + image2d<V> min_locals(ima.domain()); + // image2d<V> u = clone(ima); + image2d<bool> tagged(ima.domain()); + + unsigned nlabels; + labeling::regional_minima(ima, c4(), min_locals, nlabels); + + debug::println(min_locals); + debug::println(min_locals | (pw::value(min_locals) > pw::cst(0))); + + /// Algorithm. + { + mln_piter(I_IF) p((min_locals | (pw::value(min_locals) > pw::cst(0))).domain()); + for_all(p) + { + if (tagged(p)) + continue; + + step1(ima, p, g, x0); + step2(A, R, N, x0); + while (1) + { + step3(ima, tagged, A, R, N, gn); + /// step4. + if (g < gn) + { +// step4_1(); // GO TO 3) + continue; } - // IF g > gn + + if (g == gn) + { + step4_2(ima, A, N, g); + // GO TO 3) + continue; + } + + if (g > gn) { - // set the gray-level of the pixels of R to g. + /// FIXME ima -> u + // step4_3(ima, R, g); // GO TO 1) + break; + } + } } } }
participants (1)
-
Guillaume Duhamel