Commit 064910db authored by Roland Levillain's avatar Roland Levillain
Browse files

New apps on generic skeletonization.

	* apps/generic-skel/image2d-skel-unconstrained.cc,
	* apps/generic-skel/image2d-skel-with-end-points.cc,
	* apps/generic-skel/image2d-skel.hh:
	New.
	* apps/generic-skel/test-image2d-skel-unconstrained.in,
	* apps/generic-skel/test-image2d-skel-with-end-points.in:
	New tests.
	* apps/generic-skel/Makefile.am: New.
	* apps/Makefile.am (SUBDIRS): Add generic-skel.
parent d56e10be
2010-08-20 Roland Levillain <roland@lrde.epita.fr>
New apps on generic skeletonization.
* apps/generic-skel/image2d-skel-unconstrained.cc,
* apps/generic-skel/image2d-skel-with-end-points.cc,
* apps/generic-skel/image2d-skel.hh:
New.
* apps/generic-skel/test-image2d-skel-unconstrained.in,
* apps/generic-skel/test-image2d-skel-with-end-points.in:
New tests.
* apps/generic-skel/Makefile.am: New.
* apps/Makefile.am (SUBDIRS): Add generic-skel.
2011-04-12 Roland Levillain <roland@lrde.epita.fr>
 
apps/graph-morpho: Catch up with current mln::topo::is_n_face.
# Copyright (C) 2008, 2009, 2011 EPITA Research and Development
# Copyright (C) 2008, 2009, 2010, 2011 EPITA Research and Development
# Laboratory (LRDE).
#
# This file is part of Olena.
......@@ -16,7 +16,8 @@
# along with Olena. If not, see <http://www.gnu.org/licenses/>.
# Applied examples of Milena.
SUBDIRS = mesh-segm-skel graph-morpho constrained-connectivity morphers
SUBDIRS = mesh-segm-skel generic-skel graph-morpho constrained-connectivity \
morphers
# Examples from papers.
SUBDIRS += papers
# 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/>.
# Find Milena and trimesh headers.
AM_CPPFLAGS = -I$(top_srcdir)/milena
# Produce fast code.
APPS_CXXFLAGS = @APPS_CXXFLAGS@
AM_CXXFLAGS = $(APPS_CXXFLAGS)
bin_PROGRAMS = image2d-skel-unconstrained image2d-skel-with-end-points
image2d_skel_unconstrained_SOURCES = image2d-skel-unconstrained.cc image2d-skel.hh
image2d_skel_with_end_points_SOURCES = image2d-skel-with-end-points.cc image2d-skel.hh
EXTRA_DIST = test-image2d-skel-unconstrained.in test-image2d-skel-with-end-points.in
# Use Make to generate Doxyfile instead of `configure', as advised by
# Autoconf's manual (see section ``Installation Directory
# Variables'').
edit = sed -e 's|@top_srcdir[@]|$(top_srcdir)|g'
test-image2d-skel-unconstrained test-image2d-skel-with-end-points: Makefile
rm -f $@ $@.tmp
srcdir=''; \
test -f ./$@.in || srcdir=$(srcdir)/; \
$(edit) $${srcdir}$@.in >$@.tmp
chmod +x $@.tmp
chmod a-w $@.tmp
mv $@.tmp $@
test-image2d-skel-unconstrained: $(srcdir)/test-image2d-skel-unconstrained.in
test-image2d-skel-with-end-points: $(srcdir)/test-image2d-skel-with-end-points.in
TESTS = test-image2d-skel-unconstrained test-image2d-skel-with-end-points
CLEANFILES = test-image2d-skel-unconstrained test-image2d-skel-with-end-points
MOSTLYCLEANFILES = \
picasso-skel-unconstrained.pbm \
picasso-skel-with-end-points.pbm \
tiny-skel-unconstrained.pbm \
tiny-skel-with-end-points.pbm
// 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
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library 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 this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library 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.
/// \file
/// \brief A program computing an unconstrained skeleton of a 2D image.
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/topo/skeleton/breadth_first_thinning.hh>
#include <mln/io/pbm/all.hh>
#include "image2d-skel.hh"
int
main(int argc, char* argv[])
{
using namespace mln;
if (argc != 3)
{
std::cerr << "usage: " << argv[0] << " input.pbm output.pbm"
<< std::endl;
std::exit(1);
}
std::string input_filename = argv[1];
std::string output_filename = argv[2];
typedef image2d<bool> I;
typedef neighb2d N;
// Add a border of (at least) 1 pixel, to a guarantee a meaningful
// result of the computation of connectivity numbers (called within
// is_simple_2d); indeed, this computation always expects each pixel
// to have 8 neighboring sites.
border::thickness = 1;
I input = io::pbm::load(input_filename);
// FIXME: Use a dual neighborhood instead?
// Foreground neighborhood.
neighb2d nbh_fg = c4();
// Background neighborhood.
neighb2d nbh_bg = c8();
// Simplicity criterion functor.
::is_simple_2d<I, N> is_simple(nbh_fg, nbh_bg);
// Detach procedure.
::detach<I> detach;
// (Lack of) constraint.
fun::p2b::tautology constraint;
I output = topo::skeleton::breadth_first_thinning(input, nbh_fg,
is_simple, detach,
constraint);
io::pbm::save(output, output_filename);
}
// 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
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library 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 this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library 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.
/// \file
/// \brief A program computing a skeleton of a 2D image, preserving
/// end points.
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/topo/skeleton/breadth_first_thinning.hh>
#include <mln/io/pbm/all.hh>
#include "image2d-skel.hh"
int
main(int argc, char* argv[])
{
using namespace mln;
if (argc != 3)
{
std::cerr << "usage: " << argv[0] << " input.pbm output.pbm"
<< std::endl;
std::exit(1);
}
std::string input_filename = argv[1];
std::string output_filename = argv[2];
typedef image2d<bool> I;
typedef neighb2d N;
// Add a border of (at least) 1 pixel, to a guarantee a meaningful
// result of the computation of connectivity numbers (called within
// is_simple_2d); indeed, this computation always expects each pixel
// to have 8 neighboring sites.
border::thickness = 1;
I input = io::pbm::load(input_filename);
// Foreground neighborhood.
neighb2d nbh_fg = c4();
// Background neighborhood.
neighb2d nbh_bg = c8();
// Simplicity criterion functor.
::is_simple_2d<I, N> is_simple(nbh_fg, nbh_bg);
// Detach procedure.
::detach<I> detach;
// Constraint: do not remove end points.
is_not_end_point<I, N> constraint(nbh_fg, input);
I output = topo::skeleton::breadth_first_thinning(input, nbh_fg,
is_simple, detach,
constraint);
io::pbm::save(output, output_filename);
}
// 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
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library 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 this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library 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 APPS_GENERIC_SKEL_IMAGE2D_SKEL_HH
# define APPS_GENERIC_SKEL_IMAGE2D_SKEL_HH
/// \file
/// \brief Definitions for a simplicity criterion and a constraint
/// to be used in the breadth-first thinning of a 2D regular image.
# include <mln/topo/is_simple_2d.hh>
// FIXME: Split this file?
/** \brief An equivalent (for mln::image2d) of the
mln::topo::is_simple_cell functor, 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_2d : public mln::Function_v2b< is_simple_2d<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_2d(const mln::Neighborhood<N>& nbh_fg,
const mln::Neighborhood<N>& nbh_bg)
: nbh_fg_(mln::exact(nbh_fg)), nbh_bg_(mln::exact(nbh_bg)),
ima_(0)
{
}
/// 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_2d(const mln::Neighborhood<N>& nbh_fg,
const mln::Neighborhood<N>& nbh_bg,
const mln::Image<I>& ima)
: nbh_fg_(mln::exact(nbh_fg)), nbh_bg_(mln::exact(nbh_bg)),
ima_(mln::exact(&ima))
{
}
/// Set the underlying image.
void set_image(const mln::Image<I>& ima)
{
ima_ = mln::exact(&ima);
}
/// Based on connectivity numbers.
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;
}
private:
/// The foreground neighborhood.
const N& nbh_fg_;
/// The background neighborhood.
const N& nbh_bg_;
/// The image.
const I* ima_;
};
template <typename I>
class detach
{
public:
/// Build a functor.
detach()
: ima_(0)
{
}
/// Build a functor, and assign an image to it.
///
/// \apram ima The image.
detach(mln::Image<I>& ima)
: ima_(mln::exact(&ima))
{
}
/// Set the underlying image.
void set_image(mln::Image<I>& ima)
{
ima_ = mln::exact(&ima);
}
void operator()(const mln_psite(I)& p) const
{
(*ima_)(p) = false;
}
private:
/// The image.
I* ima_;
};
template <typename I, typename N>
struct is_not_end_point : public mln::Function_v2b< is_not_end_point<I, N> >
{
/// Build a functor, and assign an image to it.
///
/// \param nbh_fg The foreground neighborhood.
/// \apram ima The image.
is_not_end_point(const mln::Neighborhood<N>& nbh,
const mln::Image<I>& ima)
: nbh_(mln::exact(nbh)),
ima_(mln::exact(ima))
{
}
// Is \a p not a 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_;
};
#endif // ! APPS_GENERIC_SKEL_IMAGE2D_SKEL_HH
#! /bin/sh
# 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/>.
set -ex
img_dir=@top_srcdir@/milena/img
./image2d-skel-unconstrained $img_dir/tiny.pbm tiny-skel-unconstrained.pbm
./image2d-skel-unconstrained $img_dir/picasso.pbm picasso-skel-unconstrained.pbm
#! /bin/sh
# 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/>.
set -ex
img_dir=@top_srcdir@/milena/img
./image2d-skel-with-end-points $img_dir/tiny.pbm tiny-skel-with-end-points.pbm
./image2d-skel-with-end-points $img_dir/picasso.pbm picasso-skel-with-end-points.pbm
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