last-svn-commit-203-gcb5723f Add helpers to compute skeletons by thinning on regular 2D images.

* mln/topo/is_simple_point2d.hh, * mln/topo/detach_point.hh, * mln/topo/is_not_end_point.hh: New. * headers.mk: Regen. --- milena/ChangeLog | 10 ++ milena/headers.mk | 3 + .../mln/{fun/p2b/chess.hh => topo/detach_point.hh} | 54 ++++----- .../estimate.hh => mln/topo/is_not_end_point.hh} | 90 ++++++------- milena/mln/topo/is_simple_point2d.hh | 140 ++++++++++++++++++++ 5 files changed, 220 insertions(+), 77 deletions(-) copy milena/mln/{fun/p2b/chess.hh => topo/detach_point.hh} (65%) copy milena/{sandbox/theo/estimate.hh => mln/topo/is_not_end_point.hh} (52%) create mode 100644 milena/mln/topo/is_simple_point2d.hh diff --git a/milena/ChangeLog b/milena/ChangeLog index 69123c5..f0bb818 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,15 @@ 2010-09-15 Roland Levillain <roland@lrde.epita.fr> + Add helpers to compute skeletons by thinning on regular 2D images. + + * mln/topo/is_simple_point2d.hh, + * mln/topo/detach_point.hh, + * mln/topo/is_not_end_point.hh: + New. + * headers.mk: Regen. + +2010-09-15 Roland Levillain <roland@lrde.epita.fr> + Add tracing mechanism to breadth-first thinning. * mln/topo/skeleton/breadth_first_thinning.hh: Here. diff --git a/milena/headers.mk b/milena/headers.mk index 110caa6..a4314f5 100644 --- a/milena/headers.mk +++ b/milena/headers.mk @@ -995,6 +995,7 @@ mln/topo/centered_iter_adapter.hh \ mln/topo/complex.hh \ mln/topo/complex_iterators.hh \ mln/topo/detach.hh \ +mln/topo/detach_point.hh \ mln/topo/essential.hh \ mln/topo/face.hh \ mln/topo/face_data.hh \ @@ -1005,8 +1006,10 @@ mln/topo/internal/complex_relative_iterator_sequence.hh \ mln/topo/internal/complex_set_iterator_base.hh \ mln/topo/is_facet.hh \ mln/topo/is_n_face.hh \ +mln/topo/is_not_end_point.hh \ mln/topo/is_simple_2d.hh \ mln/topo/is_simple_cell.hh \ +mln/topo/is_simple_point2d.hh \ mln/topo/n_face.hh \ mln/topo/n_face_iter.hh \ mln/topo/n_faces_set.hh \ diff --git a/milena/mln/fun/p2b/chess.hh b/milena/mln/topo/detach_point.hh similarity index 65% copy from milena/mln/fun/p2b/chess.hh copy to milena/mln/topo/detach_point.hh index 53aae9c..818f7cd 100644 --- a/milena/mln/fun/p2b/chess.hh +++ b/milena/mln/topo/detach_point.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,51 +23,43 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_FUN_P2B_CHESS_HH -# define MLN_FUN_P2B_CHESS_HH +#ifndef MLN_TOPO_DETACH_POINT_HH +# define MLN_TOPO_DETACH_POINT_HH /// \file -/// -/// FIXME. +/// \brief Detaching a point from a binary image. -# include <mln/core/concept/function.hh> -# include <mln/core/alias/point2d.hh> +// FIXME: Not generic. Swap arguments and use Image<I> and +// mln_psite(I) as types. +# include <mln/core/image/image2d.hh> +# include <mln/core/alias/point2d.hh> namespace mln { - namespace fun + namespace topo { - - namespace p2b - { - - // FIXME: Doc! - - struct chess : public Function_v2b< chess > - { - typedef bool result; - bool operator()(const point2d& p) const; - }; + + /// \brief Detach a point from a binary image. + inline + void + detach_point(const mln::point2d& p, mln::image2d<bool>& ima); # ifndef MLN_INCLUDE_ONLY - inline - bool - chess::operator()(const point2d& p) const - { - return (p.row() + p.col()) % 2 == 0; - } - -# endif // ! MLN_INCLUDE_ONLY + inline + void + detach_point(const mln::point2d& p, mln::image2d<bool>& ima) + { + ima(p) = false; + } - } // end of namespace mln::fun::p2b +# endif // MLN_INCLUDE_ONLY - } // end of namespace mln::fun + } // end of namespace mln::topo } // end of namespace mln - -#endif // ! MLN_FUN_P2B_CHESS_HH +#endif // ! MLN_TOPO_DETACH_POINT_HH diff --git a/milena/sandbox/theo/estimate.hh b/milena/mln/topo/is_not_end_point.hh similarity index 52% copy from milena/sandbox/theo/estimate.hh copy to milena/mln/topo/is_not_end_point.hh index bfd98aa..3c419ec 100644 --- a/milena/sandbox/theo/estimate.hh +++ b/milena/mln/topo/is_not_end_point.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2010 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 @@ -25,66 +25,64 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_LABELING_ESTIMATE_HH -# define MLN_LABELING_ESTIMATE_HH +#ifndef MLN_TOPO_IS_NOT_END_POINT_HH +# define MLN_TOPO_IS_NOT_END_POINT_HH -/*! \file mln/labeling/estimate.hh - * - * \brief Compute the estimate pixel value. - */ +/// \file +/// \brief Non end point predicate in binary images. +# include <mln/core/concept/function.hh> # include <mln/core/concept/image.hh> # include <mln/core/concept/neighborhood.hh> -# include <mln/canvas/labeling.hh> - -# include <mln/accu/compute.hh> -// # include <mln/core/image_if_value.hh> - namespace mln { - namespace labeling + namespace topo { - - /*! \brief Label a binary image and compute some estimations over - * the components. - * - * \param[in] input The image. - * - * The free parameter \c A is a type of accumulator. - * - * FIXME: Not yet impled. - */ - template <typename A, typename I> - void - estimate(const Image<I>& input); - - -# ifndef MLN_INCLUDE_ONLY - - template <typename A, typename I> - void - estimate(const Image<I>& input) + /// \brief Functor determining whether a point is not an end point + /// in image of type \p I, based on neighborhood of type \p N. + template <typename I, typename N> + struct is_not_end_point : public Function_v2b< is_not_end_point<I, N> > { - trace::entering("labeling::estimate"); - mlc_equal(mln_trait_image_kind(I), mln::trait::image::kind::binary)::check(); - mln_precondition(exact(input).is_valid()); - - std::cerr << "Sorry: mln::labeling::estimate is not yet implemented!" << std::endl; + /// Build a functor, and assign an image to it. + /// + /// \param nbh_fg The foreground neighborhood. + /// \apram ima The image. + is_not_end_point(const Neighborhood<N>& nbh, + const Image<I>& ima) + : nbh_(exact(nbh)), + ima_(exact(ima)) + { + } + + // Is \a p not na end point? + bool operator()(const mln_psite(I)& p) const + { + // Number of foreground neighbors pixels. + unsigned nneighbs = 0; + mln_niter(N) n(nbh_, p); + for_all(n) + if (ima_.has(n) && ima_(n)) + ++nneighbs; + return nneighbs != 1; + } + + private: + /// The foreground neighborhood. + const N& nbh_; + /// The image. + const I& ima_; + }; - // FIXME: Was: - // mln_accu_with(A, util::pix<I>)::result res = accu::compute<A>(input | val); +# ifndef MLN_INCLUDE_ONLY - trace::exiting("labeling::estimate"); - } -# endif // ! MLN_INCLUDE_ONLY +# endif // MLN_INCLUDE_ONLY - } // end of namespace mln::labeling + } // end of namespace topo } // end of namespace mln - -#endif // ! MLN_LABELING_ESTIMATE_HH +#endif // ! MLN_TOPO_IS_NOT_END_POINT_HH diff --git a/milena/mln/topo/is_simple_point2d.hh b/milena/mln/topo/is_simple_point2d.hh new file mode 100644 index 0000000..145b9d8 --- /dev/null +++ b/milena/mln/topo/is_simple_point2d.hh @@ -0,0 +1,140 @@ +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef MLN_TOPO_IS_SIMPLE_POINT2D_HH +# define MLN_TOPO_IS_SIMPLE_POINT2D_HH + +/// \file +/// \brief Testing whether an mln::point2d is a simple point. + +# include <mln/core/concept/function.hh> +# include <mln/core/concept/image.hh> +# include <mln/core/concept/neighborhood.hh> + +# include <mln/topo/is_simple_2d.hh> + + +namespace mln +{ + + namespace topo + { + + /** \brief A predicate for the simplicity of an mln::point2d based + on based on the mask-based criterion mln::topo::is_simple_2d. + + This functor acts as an adapter, since mln::topo::is_simple_2d + does not fit (yet) in the canvas of + mln::topo::skeleton::breadth_first_thinning. Moreover, this + code is a bit easier to read since it does not make use of a + dual neighborhood (having a long and complex type). */ + template <typename I, typename N> + class is_simple_point2d : public Function_v2b< is_simple_point2d<I, N> > + { + public: + /// Result type of the functor. + typedef bool result; + + /// Build a functor. + /// + /// \param nbh_fg The foreground neighborhood. + /// \param nbh_bg The background neighborhood. + is_simple_point2d(const Neighborhood<N>& nbh_fg, + const Neighborhood<N>& nbh_bg); + + /// Build a functor, and assign an image to it. + /// + /// \param nbh_fg The foreground neighborhood. + /// \param nbh_bg The background neighborhood. + /// \apram ima The image. + is_simple_point2d(const Neighborhood<N>& nbh_fg, + const Neighborhood<N>& nbh_bg, + const Image<I>& ima); + + /// Set the underlying image. + void set_image(const Image<I>& ima); + + /// \brief Tell whether \a p is a simple point or not. + /// + /// This computation is based on connectivity numbers. + bool operator()(const mln_psite(I)& p) const; + + private: + /// The foreground neighborhood. + const N& nbh_fg_; + /// The background neighborhood. + const N& nbh_bg_; + /// The image. + const I* ima_; + }; + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename N> + inline + is_simple_point2d<I, N>::is_simple_point2d(const Neighborhood<N>& nbh_fg, + const Neighborhood<N>& nbh_bg) + : nbh_fg_(exact(nbh_fg)), nbh_bg_(exact(nbh_bg)), + ima_(0) + { + } + + template <typename I, typename N> + inline + is_simple_point2d<I, N>::is_simple_point2d(const Neighborhood<N>& nbh_fg, + const Neighborhood<N>& nbh_bg, + const Image<I>& ima) + : nbh_fg_(exact(nbh_fg)), nbh_bg_(exact(nbh_bg)), + ima_(exact(&ima)) + { + } + + template <typename I, typename N> + inline + void + is_simple_point2d<I, N>::set_image(const Image<I>& ima) + { + ima_ = exact(&ima); + } + + template <typename I, typename N> + inline + bool + is_simple_point2d<I, N>::operator()(const mln_psite(I)& p) const + { + return + connectivity_number_2d(*ima_, nbh_fg_, p, true ) == 1 && + connectivity_number_2d(*ima_, nbh_bg_, p, false) == 1; + } + +# endif // MLN_INCLUDE_ONLY + + } // end of namespace mln::topo + +} // end of namespace mln + +#endif // ! MLN_TOPO_IS_SIMPLE_POINT2D_HH -- 1.5.6.5
participants (1)
-
Roland Levillain