Commit 359105b5 authored by Roland Levillain's avatar Roland Levillain
Browse files

New skeletonization algorithm: priority-driven thinning.

	* mln/topo/skeleton/priority_driven_thinning.hh: New.
	* headers.mk: Regen.
parent 3f55de79
2010-09-15 Roland Levillain <roland@lrde.epita.fr>
New skeletonization algorithm: priority-driven thinning.
* mln/topo/skeleton/priority_driven_thinning.hh: New.
* headers.mk: Regen.
2010-09-15 Roland Levillain <roland@lrde.epita.fr>
 
Add helpers to compute skeletons by thinning on regular 2D images.
......@@ -1075,6 +1075,7 @@ mln/topo/n_faces_set.hh \
mln/topo/skeleton/breadth_first_thinning.hh \
mln/topo/skeleton/crest.hh \
mln/topo/skeleton/is_simple_point.hh \
mln/topo/skeleton/priority_driven_thinning.hh \
mln/topo/static_n_face_iter.hh \
mln/trait/accumulator/print.hh \
mln/trait/accumulator/props.hh \
......
// Copyright (C) 2009, 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_SKELETON_PRIORITY_DRIVEN_THINNING_HH
# define MLN_TOPO_SKELETON_PRIORITY_DRIVEN_THINNING_HH
/// \file
/// \brief Computing a skeleton by using priority-driven thinning on a
/// binary image.
# include <algorithm>
# include <mln/core/routine/duplicate.hh>
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/site_set/p_queue_fast.hh>
# include <mln/core/site_set/p_priority.hh>
# include <mln/fun/p2b/tautology.hh>
namespace mln
{
namespace topo
{
namespace skeleton
{
/** \brief Skeleton by Priority-Driven Thinning.
A generic implementation of the computation of a skeleton
using a priority-driven thinning on a binary image.
\param input The input image.
\param nbh The adjacency relation between triangles.
\param is_simple The predicate on the simplicity of points
(sites). This functor must provide a method
<tt>void set_image(const Image<I>&)</tt>.
\param detach A function used to detach a cell from \a input.
\param priority A priority function expressed as an image.
\param constraint A constraint on point (site); if it
returns \c false for a point, this point
will not be removed. */
template <typename I, typename N, typename F, typename G, typename J,
typename H>
mln_concrete(I)
priority_driven_thinning(const Image<I>& input,
const Neighborhood<N>& nbh,
Function_v2b<F>& is_simple,
G detach,
const Image<J>& priority,
const Function_v2b<H>& constraint);
/** \brief Skeleton by Priority-Driven Thinning with no constraint.
A generic implementation of the computation of a skeleton
using a priority-driven thinning on a binary image.
\param input The input image.
\param nbh The adjacency relation between triangles.
\param is_simple The predicate on the simplicity of points
(sites). This functor must provide a method
<tt>void set_image(const Image<I>&)</tt>.
\param detach A function used to detach a cell from
\a input.
\param priority A priority function expressed as an image. */
template <typename I, typename N, typename F, typename G, typename J>
mln_concrete(I)
priority_driven_thinning(const Image<I>& input,
const Neighborhood<N>& nbh,
Function_v2b<F>& is_simple,
G detach,
const Image<J>& priority);
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename N, typename F, typename G, typename J,
typename H>
inline
mln_concrete(I)
priority_driven_thinning(const Image<I>& input_,
const Neighborhood<N>& nbh_,
Function_v2b<F>& is_simple_,
G detach,
const Image<J>& priority_,
const Function_v2b<H>& constraint_)
{
trace::entering("topo::skeleton::priority_driven_thinning");
const I& input = exact(input_);
const N& nbh = exact(nbh_);
F& is_simple = exact(is_simple_);
const J& priority = exact(priority_);
const H& constraint = exact(constraint_);
mln_concrete(I) output = duplicate(input);
// Attach the work image to IS_SIMPLE.
is_simple.set_image(output);
typedef mln_psite(I) psite;
typedef p_queue_fast<psite> queue_t;
typedef p_priority<mln_value(J), queue_t> p_queue_t;
p_queue_t p_queue;
// Populate P_QUEUE with candidate simple points.
mln_piter(I) p_(output.domain());
for_all(p_)
{
/* CONSTRAINTS and IS_SIMPLE are site-to-boolean (p2b)
predicate functors; passing an iterator as argument might
not be possible (C++ cannot resolve template routines if
an implicit conversion of the argument is needed). Help
the compiler and pass an actual, explicit psite. */
psite p = p_;
if (output(p) && constraint(p) && is_simple(p))
p_queue.push(priority(p), p);
}
while (!p_queue.is_empty())
{
psite p = p_queue.pop_front();
/* FIXME: We compute the cell and attachment of P twice:
during the call to is_simple() and within detach().
How could we reuse this elegantly, without breaking
the genericity of the skeleton algorithm?
Also, keep in mind that functors can maintain an
internal state and make side effects, meaning that
e.g. constraint(p) might not be constant for a
given p during the thinning. */
if (output(p) && constraint(p) && is_simple(p))
{
detach(p, output);
mln_niter(N) n_(nbh, p);
for_all(n_)
{
// Same remark as above regarding P and P_.
psite n = n_;
if (output.domain().has(n)
&& output(n) && constraint(n) && is_simple(n))
p_queue.push(priority(n), n);
}
}
}
trace::exiting("topo::skeleton::priority_driven_thinning");
return output;
}
template <typename I, typename N, typename F, typename G, typename J>
inline
mln_concrete(I)
priority_driven_thinning(const Image<I>& input,
const Neighborhood<N>& nbh,
Function_v2b<F>& is_simple,
G detach,
const Image<J>& priority)
{
return priority_driven_thinning(input, nbh, is_simple, detach,
priority, fun::p2b::tautology());
}
# endif // MLN_INCLUDE_ONLY
} // end of namespace mln::topo::skeleton
} // end of namespace mln::topo
} // end of namespace mln
#endif // ! MLN_TOPO_SKELETON_PRIORITY_DRIVEN_THINNING_HH
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment