Commit afe34437 authored by Ugo Jardonnet's avatar Ugo Jardonnet
Browse files

Algo MorphoMath : and, or, opening, closing, elementary algo.

	* oln/accumulator/and.hh: New.
	* oln/accumulator/or.hh: New.
	* oln/core/internal/max_value.hh,
	* oln/core/internal/op_image_plus_nbh.hh,
	* oln/morpho/elementary_erosion.hh,
	* oln/morpho/dilation.hh: Update.
	* oln/morpho/elementary_closing.hh,
	* oln/morpho/elementary_opening.hh: New.
	* oln/morpho/elementary_dilation.hh: Update.
	* oln/morpho/erosion.hh: New.
	* oln/morpho/opening.hh: New.
	* oln/level/local.hh: .


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@893 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 3b0c3b4c
2007-03-21 Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr>
Algo MorphoMath : and, or, opening, closing, elementary algo.
* oln/accumulator/and.hh: New.
* oln/accumulator/or.hh: New.
* oln/core/internal/max_value.hh,
* oln/core/internal/op_image_plus_nbh.hh,
* oln/morpho/elementary_erosion.hh,
* oln/morpho/dilation.hh: Update.
* oln/morpho/elementary_closing.hh,
* oln/morpho/elementary_opening.hh: New.
* oln/morpho/elementary_dilation.hh: Update.
* oln/morpho/erosion.hh: New.
* oln/morpho/opening.hh: New.
* oln/level/local.hh: .
2007-03-21 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add image selection about different kinds of values and update.
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// 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 OLN_ACCUMULATOR_AND_HH
# define OLN_ACCUMULATOR_AND_HH
# include <oln/core/concept/accumulator.hh>
# include <oln/core/internal/max_value.hh>
namespace oln
{
namespace accumulator
{
template <typename T>
struct and_ : public Accumulator< and_<T> >
{
typedef T argument;
typedef T result;
and_();
void init() const;
const T& value() const;
void operator()(const T& val) const;
private:
mutable T val_;
};
# ifndef OLN_INCLUDE_ONLY
template <typename T>
and_<T>::and_()
{
this->init();
}
template <typename T>
void
and_<T>::init() const
{
this->val_ = oln_min(T);
}
template <typename T>
const T&
and_<T>::value() const
{
return this->val_;
}
template <typename T>
void
and_<T>::operator()(const T& val) const
{
if (val < this->val_)
this->val_ = val;
}
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::accumulator
} // end of namespace oln
#endif // ! OLN_ACCUMULATOR_AND_HH
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// 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 OLN_ACCUMULATOR_OR_HH
# define OLN_ACCUMULATOR_OR_HH
# include <oln/core/concept/accumulator.hh>
# include <oln/core/internal/max_value.hh>
namespace oln
{
namespace accumulator
{
template <typename T>
struct or_ : public Accumulator< or_<T> >
{
typedef T argument;
typedef T result;
or_();
void init() const;
const T& value() const;
void operator()(const T& val) const;
mutable T ultimate;
private:
mutable T val_;
};
# ifndef OLN_INCLUDE_ONLY
template <typename T>
or_<T>::or_()
{
this->init();
}
template <typename T>
void
or_<T>::init() const
{
this->val_ = oln_min(T);
this->ultimate = oln_max(T);
}
template <typename T>
const T&
or_<T>::value() const
{
return this->val_;
}
template <typename T>
void
or_<T>::operator()(const T& val) const
{
if (val < this->val_)
this->val_ = val;
}
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::accumulator
} // end of namespace oln
#endif // ! OLN_ACCUMULATOR_OR_HH
......@@ -30,6 +30,8 @@
# include <limits>
# define oln_max(T) std::numeric_limits< T >::max()
#define oln_max(T) std::numeric_limits< T >::max() // FIXME std lib
#define oln_min(T) std::numeric_limits< T >::min() // FIXME std lib
#endif // ! OLN_CORE_INTERNAL_MAX_VALUE_HH
......@@ -28,7 +28,6 @@
#ifndef OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
# define OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
# include <mlc/unconst.hh>
# include <oln/core/concept/neighborhood.hh>
# include <oln/core/gen/op.hh>
# include <oln/core/gen/dpoints_piter.hh>
......
......@@ -31,7 +31,8 @@
# include <oln/core/concept/image.hh>
# include <oln/core/concept/window.hh>
# include <oln/core/concept/accumulator.hh>
# include <oln/accumulator/or.hh>
# include <oln/accumulator/and.hh>
namespace oln
{
......@@ -67,7 +68,8 @@ namespace oln
const oln_point(I)& p)
{
f.init_with(input(p));
oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be 'input'!
oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
// 'input'!
for_all(n)
f(input(n));
return f.value();
......@@ -76,7 +78,6 @@ namespace oln
// FIXME: Generic version with nbh given as argument?
// Generic version with window.
template <typename A, typename I, typename W>
......@@ -93,6 +94,80 @@ namespace oln
return f.value();
}
// Optimised version for OR operator with neighborhood.
template <typename A, typename I>
typename A::result
local_(const ::oln::accumulator::or_< oln_value(I) > f,
const Binary_Image<I>& input,
const oln_point(I)& p)
{
f.init_with(input(p));
oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
// 'input'!
for_all(n)
if (f(input(n)) == f.ultimate)
return (f.ultimate);
return f.value();
}
// Optimised version for OR operator with window.
template <typename A, typename I, typename W>
typename A::result
local_(const ::oln::accumulator::or_< oln_value(I) > f,
const Binary_Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
{
f.init();
oln_qiter(W) q(p, win);
for_all(q)
if (f(input(q)) == f.ultimate)
return (f.ultimate);
return f.value();
}
// FIXME : same function for OR.
// Optimised version for AND operator with neighborhood.
template <typename A, typename I>
typename A::result
local_(const ::oln::accumulator::and_< oln_value(I) > f,
const Binary_Image<I>& input,
const oln_point(I)& p)
{
f.init_with(input(p));
oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
// 'input'!
for_all(n)
if (f(input(n)) == f.ultimate)
return (f.ultimate);
return f.value();
}
// Optimised version for AND operator with window.
template <typename A, typename I, typename W>
typename A::result
local_(const ::oln::accumulator::and_< oln_value(I) > f,
const Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
{
f.init();
oln_qiter(W) q(p, win);
for_all(q)
if (f(input(q)) == f.ultimate)
return (f.ultimate);
return f.value();
}
} // end of namespace oln::level::impl
......
......@@ -32,6 +32,8 @@
#include <oln/border/fill.hh>
#include <oln/accumulator/max.hh>
namespace oln
{
namespace morpho
{
......@@ -40,7 +42,7 @@
template <typename I, typename W>
oln_plain(I)
dilation(const Image<I>& input, const Window<W>& win);
dilation(const Image<I>& input, const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
......@@ -52,8 +54,8 @@
template <typename I, typename W>
oln_plain(I)
elementary_dilation_(const Image<I>& input,
const Window<W>& win)
elementary_dilation_(const Image<I>& input,
const Window<W>& win)
{
border::fill(input, oln_min(oln_value(I)));
accumulator::max_<oln_value(I)> max;
......@@ -69,7 +71,7 @@
template <typename I, typename W>
oln_plain(I)
dilation(const Image<I>& input, const Window<W>& win)
dilation(const Image<I>& input, const Window<W>& win)
{
return impl::dilation_(exact(input), exact(win));
}
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// 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 OLN_MORPHO_ELEMENTARY_CLOSING_HH
# define OLN_MORPHO_ELEMENTARY_CLOSING_HH
#include <oln/level/apply_local.hh>
#include <oln/border/fill.hh>
#include <oln/morpho/elementary_erosion.hh>
#include <oln/morpho/elementary_dilation.hh>
namespace oln
{
namespace morpho
{
// Fwd decl.
template <typename I, typename W>
oln_plain(I)
elementary_closing(const Image<I>& input, const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
namespace impl
{
// Generic version.
template <typename I, typename W>
oln_plain(I)
elementary_closing_(const Image<I>& input,
const Window<W>& win)
{
return elementary_erosion(elementary_dilation(input, win), win); // FIXME : memory
}
// FIXME: Add a fast version.
} // end of namespace oln::morpho::impl
// Facade.
template <typename I, typename W>
oln_plain(I)
elementary_closing(const Image<I>& input, const Window<W>& win)
{
return impl::elementary_closing_(exact(input), exact(win));
}
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::morpho
} // end of namespace oln
#endif // ! OLN_MORPHO_ELEMENTARY_CLOSING_HH
......@@ -31,7 +31,7 @@
#include <oln/level/apply_local.hh>
#include <oln/border/fill.hh>
#include <oln/accumulator/max.hh>
#include <oln/accumulator/or.hh>
namespace oln
{
......@@ -66,11 +66,11 @@ namespace oln
template <typename I>
oln_plain(I)
elementary_dilation_on_set_(const Image<I>&,
const I&)
const I& input)
{
oln_plain(I) tmp;
std::cerr << "morpho::impl::elementary_dilation_on_set_ is not yet impled!" << std::endl;
return tmp;
border::fill(input, oln_min(oln_value(I)));
accumulator::or_<oln_value(I)> accu_or;
return level::apply_local(accu_or, input);
}
// FIXME: Add a fast version.
......
......@@ -32,7 +32,6 @@
#include <oln/border/fill.hh>
#include <oln/accumulator/min.hh>
namespace oln
{
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// 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 OLN_MORPHO_ELEMENTARY_OPENING_HH
# define OLN_MORPHO_ELEMENTARY_OPENING_HH
#include <oln/level/apply_local.hh>
#include <oln/border/fill.hh>
#include <oln/morpho/elementary_erosion.hh>
#include <oln/morpho/elementary_dilation.hh>
namespace oln
{
namespace morpho
{
// Fwd decl.
template <typename I, typename W>
oln_plain(I)
elementary_opening(const Image<I>& input, const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
namespace impl
{
// Generic version.
template <typename I, typename W>
oln_plain(I)
elementary_opening_(const Image<I>& input,
const Window<W>& win)
{
return elementary_dilation(elementary_erosion(input, win), win); // FIXME : memory
}
// FIXME: Add a fast version.
} // end of namespace oln::morpho::impl
// Facade.
template <typename I, typename W>
oln_plain(I)
elementary_opening(const Image<I>& input, const Window<W>& win)
{
return impl::elementary_opening_(exact(input), exact(win));
}
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::morpho
} // end of namespace oln
#endif // ! OLN_MORPHO_ELEMENTARY_OPENING_HH
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// 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 OLN_MORPHO_EROSION_HH
# define OLN_MORPHO_EROSION_HH
#include <oln/level/apply_local.hh>
#include <oln/border/fill.hh>
#include <oln/accumulator/min.hh>
namespace oln
{
namespace morpho
{
// Fwd decl.