Commit b4bda081 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add morpho algebraic closing.

	* mln/morpho/attribute/volume.hh: New.
	* mln/morpho/closing_algebraic.hh: Copy to...
	* mln/morpho/opening_algebraic.hh: ...this new file.
	Make it a closing.
	* mln/canvas/morpho/algebraic_filter.hh (todo): New.
	* tests/morpho/closing_volume.cc: Test that the new version
	with morpho::attribute::volume gives the same result as the
	former version.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@3344 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 33062e6c
2009-02-11 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add morpho algebraic closing.
* mln/morpho/attribute/volume.hh: New.
* mln/morpho/closing_algebraic.hh: Copy to...
* mln/morpho/opening_algebraic.hh: ...this new file.
Make it a closing.
* mln/canvas/morpho/algebraic_filter.hh (todo): New.
* tests/morpho/closing_volume.cc: Test that the new version
with morpho::attribute::volume gives the same result as the
former version.
2009-02-11 Guillaume Lazzara <z@lrde.epita.fr>
 
Fix debug::histo.
......@@ -32,6 +32,8 @@
/// \file mln/canvas/morpho/algebraic_filter.hh
///
/// Canvas for morphological algebraic filters.
///
/// \todo Add a version without 'activity' thanx to set_value.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
......
// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of the Olena 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 MLN_MORPHO_ATTRIBUTE_VOLUME_HH
# define MLN_MORPHO_ATTRIBUTE_VOLUME_HH
/// \file mln/morpho/attribute/volume.hh
///
/// Define an accumulator that computes the volume of a
/// component.
# include <mln/accu/internal/base.hh>
# include <mln/math/diff_abs.hh>
namespace mln
{
// Forward declaration.
namespace morpho {
namespace attribute {
template <typename I> class volume;
}
}
// Traits.
namespace trait
{
template <typename I>
struct accumulator_< morpho::attribute::volume<I> >
{
typedef accumulator::has_untake::no has_untake;
typedef accumulator::has_set_value::no has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_v when_pix;
};
} // end of namespace mln::trait
namespace morpho
{
namespace attribute
{
/// Volume accumulator class.
///
/// The parameter \p I is the image type on which the accumulator
/// of pixels is built.
template <typename I>
struct volume
: public mln::accu::internal::base< unsigned , volume<I> >
{
typedef mln_value(I) argument;
volume();
/// Manipulators.
/// \{
void init();
void take(const mln_value(I)& v);
void take(const util::pix<I>& px);
void take(const volume<I>& other);
void take_as_init(const mln_value(I)& v);
void take_as_init(const util::pix<I>& px);
/// \}
/// Get the value of the accumulator.
unsigned to_result() const;
/// Check whether this accu is able to return a result.
/// Always true here.
bool is_valid() const;
protected:
/// The current level.
mln_value(I) level_;
/// The area of the component.
unsigned area_;
/// The volume of the component.
unsigned volume_;
};
# ifndef MLN_INCLUDE_ONLY
template <typename I>
inline
volume<I>::volume()
{
init();
}
template <typename I>
inline
void
volume<I>::init()
{
volume_ = 0;
}
template <typename I>
inline
void
volume<I>::take(const mln_value(I)& v)
{
mln_invariant(volume_ != mln_max(unsigned));
if (! is_valid())
{
take_as_init(v);
return;
}
++area_;
volume_ += 1 + math::diff_abs(v, level_);
level_ = v;
}
template <typename I>
inline
void
volume<I>::take(const util::pix<I>& px)
{
mln_invariant(volume_ != mln_max(unsigned));
take(px.v());
}
template <typename I>
inline
void
volume<I>::take(const volume<I>& other)
{
mln_invariant(volume_ != mln_max(unsigned));
area_ += other.area_;
volume_ +=
other.volume_ +
other.area_ * math::diff_abs(other.level_, level_);
// level_ do not change.
}
template <typename I>
inline
void
volume<I>::take_as_init(const mln_value(I)& v)
{
level_ = v;
area_ = 1;
volume_ = 1;
}
template <typename I>
inline
void
volume<I>::take_as_init(const util::pix<I>& px)
{
take_as_init(px.v());
}
template <typename I>
inline
unsigned
volume<I>::to_result() const
{
return volume_;
}
template <typename I>
inline
bool
volume<I>::is_valid() const
{
return volume_ != 0;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::morpho::attribute
} // end of namespace mln::morpho
} // end of namespace mln
#endif // ! MLN_MORPHO_ATTRIBUTE_VOLUME_HH
// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of the Olena 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 MLN_MORPHO_OPENING_ALGEBRAIC_HH
# define MLN_MORPHO_OPENING_ALGEBRAIC_HH
/// \file mln/morpho/opening_algebraic.hh
///
/// Morphological algebraic opening.
# include <mln/morpho/includes.hh>
# include <mln/canvas/morpho/algebraic_filter.hh>
namespace mln
{
namespace morpho
{
/// Morphological algebraic opening.
template <typename I, typename N, typename A>
mln_concrete(I)
opening_algebraic(const Image<I>& input, const Neighborhood<N>& nbh,
const Accumulator<A>& accu, const mln_result(A)& lambda);
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename N, typename A>
inline
mln_concrete(I)
opening_algebraic(const Image<I>& input, const Neighborhood<N>& nbh,
const Accumulator<A>& accu, const mln_result(A)& lambda)
{
trace::entering("morpho::opening_algebraic");
mln_precondition(exact(input).is_valid());
mln_concrete(I) output;
output = canvas::morpho::algebraic_filter(input, nbh, accu, lambda,
/* increasing = */ false);
mln_postcondition(output <= input);
trace::exiting("morpho::opening_algebraic");
return output;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::morpho
} // end of namespace mln
#endif // ! MLN_MORPHO_OPENING_ALGEBRAIC_HH
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
// (LRDE)
// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -38,15 +38,23 @@
#include <mln/io/pgm/save.hh>
#include <mln/morpho/closing_volume.hh>
#include <mln/morpho/attribute/volume.hh>
#include "tests/data.hh"
int main()
{
using namespace mln;
using value::int_u8;
image2d<int_u8> lena;
typedef image2d<int_u8> I;
I lena;
io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
io::pgm::save(morpho::closing_volume(lena, c4(), 10000), "out.pgm");
io::pgm::save(morpho::closing_volume(lena, c4(), 10000),
"ref.pgm");
typedef morpho::attribute::volume<I> A;
io::pgm::save(morpho::closing_attribute<A>(lena, c4(), 10000),
"out.pgm");
}
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