https://svn.lrde.epita.fr/svn/oln/trunk/milena
It's cool, because I'm doing two tasks in one time:
1. adding things to support my research work (at the moment, some watershed/morphological experiments); and
2. reviewing the contents of mln/morpho/, which was one of my assignments about two or three months ago. :-P
Index: ChangeLog from Roland Levillain roland@lrde.epita.fr
Add an area closing filter.
* mln/morpho/closing_attribute.hh: New. Dual of mln/morpho/opening_attribute.hh * mln/morpho/closing_area.hh: New. Dual of mln/morpho/opening_area.hh * tests/morpho/closing_area.cc: New test. * tests/morpho/Makefile.am (check_PROGRAMS): Add closing_area. (closing_area_SOURCES): New.
mln/morpho/closing_area.hh | 77 +++++++++++++++++++++ mln/morpho/closing_attribute.hh | 146 ++++++++++++++++++++++++++++++++++++++++ tests/morpho/Makefile.am | 2 tests/morpho/closing_area.cc | 57 +++++++++++++++ 4 files changed, 282 insertions(+)
Index: mln/morpho/closing_attribute.hh --- mln/morpho/closing_attribute.hh (revision 0) +++ mln/morpho/closing_attribute.hh (revision 0) @@ -0,0 +1,146 @@ +// Copyright (C) 2007, 2008 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_CLOSING_ATTRIBUTE_HH +# define MLN_MORPHO_CLOSING_ATTRIBUTE_HH + +/*! \file mln/morpho/closing_attribute.hh + * + * \brief Morphological attribute closing. + */ + +# include <mln/morpho/includes.hh> +# include <mln/canvas/morpho/algebraic_union_find.hh> +# include <mln/level/sort_points.hh> +# include <mln/util/pix.hh> + + +namespace mln +{ + + namespace morpho + { + + /* FIXME: The neighborhood shall not be passed as argument, but + bound to the input image. We can also optionnaly provide a + version of this function for regular-grid-based images where + the neighborhood is replaced by a (user-provided) window. */ + + /// Morphological attribute closing. + template <typename A, + typename I, typename N, typename O> + void closing_attribute(const Image<I>& input, const Neighborhood<N>& nbh, + mln_result(A) lambda, Image<O>& output); + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + template <typename A_, + typename I_, typename N_, typename O_> + struct closing_attribute_t + { + typedef mln_point(I_) P; + + // requirements from mln::canvas::morpho::algebraic_union_find + + typedef A_ A; + typedef I_ I; + typedef N_ N; + typedef O_ O; + typedef p_array<P> S; + typedef util::pix<I> pix_t; + + const I& input; + const N& nbh; + mln_result(A) lambda; + O& output; + + const S s; + + inline + void init() + { + // FIXME: border::fill(input, mln_max(mln_value(I))); + } + + inline + bool is_active(const A& attr) const + { + return attr.to_result() < lambda; + } + + inline + void inactivate(A& attr) + { + attr.set_value(lambda); + } + + // end of requirements + + inline + closing_attribute_t(const I_& input, const N_& nbh, + mln_result(A) lambda, O_& output) + : input(input), nbh(nbh), lambda(lambda), output(output), + s(level::sort_points_increasing(input)) + { + } + + }; + + } // end of namespace mln::morpho::impl + + + template <typename A, + typename I, typename N, typename O> + inline + void closing_attribute(const Image<I>& input_, + const Neighborhood<N>& nbh_, mln_result(A) lambda, + Image<O>& output_) + { + const I& input = exact(input_); + const N& nbh = exact(nbh_); + O& output = exact(output_); + mln_precondition(output.domain() == input.domain()); + + typedef impl::closing_attribute_t<A,I,N,O> F; + F f(input, nbh, lambda, output); + canvas::morpho::algebraic_union_find<F> run(f); + + mln_postcondition(output >= input); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::morpho + +} // end of namespace mln + + +#endif // ! MLN_MORPHO_CLOSING_ATTRIBUTE_HH Index: mln/morpho/closing_area.hh --- mln/morpho/closing_area.hh (revision 0) +++ mln/morpho/closing_area.hh (revision 0) @@ -0,0 +1,77 @@ +// Copyright (C) 2007, 2008 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_CLOSING_AREA_HH +# define MLN_MORPHO_CLOSING_AREA_HH + +/*! \file mln/morpho/closing_area.hh + * + * \brief Morphological area closing. + */ + +# include <mln/morpho/closing_attribute.hh> +# include <mln/accu/count.hh> + + +namespace mln +{ + + namespace morpho + { + + /* FIXME: The neighborhood shall not be passed as argument, but + bound to the input image. We can also optionnaly provide a + version of this function for regular-grid-based images where + the neighborhood is replaced by a (user-provided) window. */ + + /// Morphological area closing. + template <typename I, typename N, typename O> + void closing_area(const Image<I>& input, const Neighborhood<N>& nbh, + std::size_t lambda, Image<O>& output); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename N, typename O> + inline + void closing_area(const Image<I>& input, const Neighborhood<N>& nbh, + std::size_t lambda, Image<O>& output) + { + mln_precondition(exact(output).domain() == exact(input).domain()); + typedef util::pix<I> pix_t; + // FIXME: Change sig of closing_attribute! + closing_attribute< accu::count_<pix_t> >(input, nbh, lambda, output); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::morpho + +} // end of namespace mln + + +#endif // ! MLN_MORPHO_CLOSING_AREA_HH Index: tests/morpho/closing_area.cc --- tests/morpho/closing_area.cc (revision 0) +++ tests/morpho/closing_area.cc (revision 0) @@ -0,0 +1,57 @@ +// Copyright (C) 2007, 2008 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. + +/*! \file tests/morpho/closing_area.cc + * + * \brief Test on mln::morpho::closing_area. + */ + +#include <mln/core/image2d.hh> +#include <mln/value/int_u8.hh> +#include <mln/core/neighb2d.hh> + +#include <mln/io/pgm/load.hh> +#include <mln/io/pgm/save.hh> + +#include <mln/morpho/closing_area.hh> + +#include "tests/data.hh" + + + +int main() +{ + using namespace mln; + using value::int_u8; + + image2d<int_u8> lena; + io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm"); + image2d<int_u8> out(lena.domain()); + + morpho::closing_area(lena, c4(), 510, out); + io::pgm::save(out, "out.pgm"); +} Index: tests/morpho/Makefile.am --- tests/morpho/Makefile.am (revision 1695) +++ tests/morpho/Makefile.am (working copy) @@ -3,6 +3,7 @@ include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \ + closing_area \ contrast \ dilation \ dilation_max_h \ @@ -16,6 +17,7 @@ opening_area \ thinning
+closing_area_SOURCES = closing_area.cc contrast_SOURCES = contrast.cc dilation_SOURCES = dilation.cc dilation_max_h_SOURCES = dilation_max_h.cc