olena: olena-2.0-728-g8a48d80 Reintroduce is_simple_2d and connectivity_number_2d into mln::topo.

* mln/topo/is_simple_2d.hh (mln::topo::is_simple_2d) (mln::topo::connectivity_number_2d): New. * apps/generic-skel/image2d-skel.hh (is_simple_2d::operator()): Adjust. --- milena/ChangeLog | 10 ++++ milena/apps/generic-skel/image2d-skel.hh | 6 +-- milena/mln/topo/is_simple_2d.hh | 73 +++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 4 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index c344a82..fc897d2 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,13 @@ +2013-08-28 Roland Levillain <roland@lrde.epita.fr> + + Reintroduce is_simple_2d and connectivity_number_2d into mln::topo. + + * mln/topo/is_simple_2d.hh (mln::topo::is_simple_2d) + (mln::topo::connectivity_number_2d): + New. + * apps/generic-skel/image2d-skel.hh (is_simple_2d::operator()): + Adjust. + 2011-05-31 Roland Levillain <roland@lrde.epita.fr> Factor connectivity_numbers_3d and connectivity_numbers_3d_tbb. diff --git a/milena/apps/generic-skel/image2d-skel.hh b/milena/apps/generic-skel/image2d-skel.hh index 6cd8c50..0d0864e 100644 --- a/milena/apps/generic-skel/image2d-skel.hh +++ b/milena/apps/generic-skel/image2d-skel.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2010, 2013 EPITA Research and Development Laboratory (LRDE) // // This file is part of the Milena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -88,8 +88,8 @@ public: bool operator()(const mln_psite(I)& p) const { return - mln::connectivity_number_2d(*ima_, nbh_fg_, p, true ) == 1 && - mln::connectivity_number_2d(*ima_, nbh_bg_, p, false) == 1; + mln::topo::connectivity_number_2d(*ima_, nbh_fg_, p, true ) == 1 && + mln::topo::connectivity_number_2d(*ima_, nbh_bg_, p, false) == 1; } private: diff --git a/milena/mln/topo/is_simple_2d.hh b/milena/mln/topo/is_simple_2d.hh index 41403fe..30cccf5 100644 --- a/milena/mln/topo/is_simple_2d.hh +++ b/milena/mln/topo/is_simple_2d.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2008, 2009, 2011, 2012 EPITA Research and Development +// Copyright (C) 2008, 2009, 2011, 2012, 2013 EPITA Research and Development // Laboratory (LRDE) // // This file is part of Olena. @@ -50,6 +50,22 @@ namespace mln namespace topo { + /** Compute the 2D connectivity number of a point. + + \param ima The image the point belongs to. + \param nbh The connectivity used (4- or 8-connectivity). + \param p The location of the point. + \param b If true, consider foreground (i.e. true) values of + the neighborhood; otherwise, consider background + (i.e. false) values. + + \return The 2D connectivity number. */ + template<typename I, typename N> + inline + unsigned + connectivity_number_2d(const Image<I>& ima, const Neighborhood<N>& nbh, + const mln_psite(I)& p, bool b); + /// Test if a point is simple or not. A point of an object is simple /// if in its c8 neiborhood, there is exactly one connected component of the /// object, and only one connected component of the background @@ -62,6 +78,13 @@ namespace mln /// - | - /// | P | Here p is never simple. /// | | | + + template<typename I, typename N> + bool + is_simple_2d(const Image<I>& ima, const Neighborhood<N>& nbh, + const mln_psite(I)& p); + + template <typename N> struct is_simple_2d_t { @@ -92,6 +115,9 @@ namespace mln namespace internal { + // Connectivity numbers computed with + // tools/compute_local_configurations.cc. + static const unsigned char connectivity_number_c8[256] = { 0, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, @@ -141,6 +167,51 @@ namespace mln } // end of namespace mln::topo::internal + + + template<typename I, typename N> + inline + unsigned + connectivity_number_2d(const Image<I>& ima_, const Neighborhood<N>& nbh_, + const mln_psite(I)& p, bool b) + { + const I& ima = exact(ima_); + const N& nbh = exact(nbh_); + + unsigned res = 0; + mln_fwd_niter(neighb2d) n(c8(), p); + for_all(n) + { + res = (res << 1); + if (ima.has(n) && ima(n) == b) + res = res | 1; + } + + unsigned number; + if (nbh == c4()) + number = internal::connectivity_number_c4[res]; + else if (nbh == c8()) + number = internal::connectivity_number_c8[res]; + else + abort(); + + return number; + } + + template<typename I, typename N> + inline + bool + is_simple_2d(const Image<I>& ima, const Neighborhood<N>& nbh_, + const mln_psite(I)& p) + { + const N& nbh = exact(nbh_); + return + connectivity_number_2d(ima, nbh.foreground(), p, true ) == 1 && + connectivity_number_2d(ima, nbh.background(), p, false) == 1; + } + + + template <typename N> is_simple_2d_t<N>::is_simple_2d_t(const Neighborhood<N>& nbh) : nbh_(exact(nbh)) -- 1.7.10.4
participants (1)
-
Roland Levillain