Commit 7d205129 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add some linear filters and augment related tools.

	* mln/linear/convolve.hh: Add doc.
	* mln/linear/log.hh (LoG_7x7, LoG_13x13, LoG_17x17): New.
	* mln/linear/lap.hh: New.
	* tests/linear_lap.cc: New.
	* mln/convert/to_dpoint.hh: Add postcondition.
	* mln/convert/to_w_window.hh: New.
	* mln/core/w_window2d_float.hh: New.
	* mln/make/w_window.hh: New.
	* mln/make/w_window2d_int.hh: Remove; useless.

	* mln/core/concept/doc/weighted_window.hh: Augment doc.
	(weight, window): Rename as...
	(w, win): ...these.
	(weight, window): New associated types.
	* mln/core/concept/weighted_window.hh: Update.
	
	* mln/core/window.hh (window_): Rename as...
	(window): ...this.
	* mln/core/w_window.hh (w_window_): Rename as...
	(w_window): ...this.
	(insert): Swap args; add precondition.
	Update.
	* mln/convert/to_image.hh,
	* mln/convert/to_window.hh,
	* mln/geom/pmin_pmax.hh,
	* mln/geom/bbox.hh: New overload.
	* mln/core/window2d.hh,
	* mln/core/w_window2d_int.hh,
	* mln/linear/convolve.hh,
	* mln/make/w_window2d.hh,
	* tests/convolve.cc,
	* tests/pixter_dpoint2d.cc,
	* tests/w_window2d_int.cc: Update.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1052 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 38469bb4
2007-08-27 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add some linear filters and augment related tools.
* mln/linear/convolve.hh: Add doc.
* mln/linear/log.hh (LoG_7x7, LoG_13x13, LoG_17x17): New.
* mln/linear/lap.hh: New.
* tests/linear_lap.cc: New.
* mln/convert/to_dpoint.hh: Add postcondition.
* mln/convert/to_w_window.hh: New.
* mln/core/w_window2d_float.hh: New.
* mln/make/w_window.hh: New.
* mln/make/w_window2d_int.hh: Remove; useless.
* mln/core/concept/doc/weighted_window.hh: Augment doc.
(weight, window): Rename as...
(w, win): ...these.
(weight, window): New associated types.
* mln/core/concept/weighted_window.hh: Update.
* mln/core/window.hh (window_): Rename as...
(window): ...this.
* mln/core/w_window.hh (w_window_): Rename as...
(w_window): ...this.
(insert): Swap args; add precondition.
Update.
* mln/convert/to_image.hh,
* mln/convert/to_window.hh,
* mln/geom/pmin_pmax.hh,
* mln/geom/bbox.hh: New overload.
* mln/core/window2d.hh,
* mln/core/w_window2d_int.hh,
* mln/linear/convolve.hh,
* mln/make/w_window2d.hh,
* tests/convolve.cc,
* tests/pixter_dpoint2d.cc,
* tests/w_window2d_int.cc: Update.
2007-08-27 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Update accus and add LoG filter.
......
......@@ -53,10 +53,12 @@ namespace mln
mln_dpoint(P) to_dpoint(const Generalized_Point<P>& p_)
{
const P& p = internal::force_exact<P>(p_);
mln_dpoint(P) tmp;
mln_dpoint(P) dp;
for (unsigned i = 0; i < P::dim; ++i)
tmp[i] = p[i];
return tmp;
dp[i] = p[i];
typedef mln_point(P) P_;
mln_postcondition(dp == p - P_::zero);
return dp;
}
# endif // ! MLN_INCLUDE_ONLY
......
......@@ -37,6 +37,7 @@
# include <mln/core/concept/point_set.hh>
# include <mln/core/concept/window.hh>
# include <mln/core/concept/weighted_window.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/convert/to_window.hh>
......@@ -62,6 +63,10 @@ namespace mln
template <typename N>
image2d_b<bool> to_image(const Neighborhood<N>& nbh);
/// Convert a weighted window \p w_win into an image.
template <typename W>
image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win);
# ifndef MLN_INCLUDE_ONLY
......@@ -99,6 +104,22 @@ namespace mln
return to_image(convert::to_window(nbh));
}
template <typename W>
image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win_)
{
const W& w_win = exact(w_win_);
mln_precondition(! w_win.is_empty());
typedef mln_point(W) P;
box2d b = geom::bbox(w_win);
image2d_b<mln_weight(W)> ima(b);
mln_qiter(W) q(w_win, P::zero);
for_all(q)
ima(q) = q.w();
return ima;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
......
// 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 MLN_CONVERT_TO_W_WINDOW_HH
# define MLN_CONVERT_TO_W_WINDOW_HH
/*! \file mln/convert/to_w_window.hh
*
* \brief Conversions to mln::w_window.
*/
# include <mln/core/concept/image.hh>
# include <mln/core/window.hh>
namespace mln
{
namespace convert
{
/// Convert an image \p input into a weighted window.
template <typename I>
w_window<mln_dpoint(I), mln_value(I)> to_w_window(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
template <typename I>
w_window<mln_dpoint(I), mln_value(I)> to_w_window(const Image<I>& input_)
{
const I& input = exact(input_);
mln_precondition(input.has_data());
// FIXME: Check that input is scalar?
typedef mln_dpoint(I) D;
typedef mln_point(D) P;
w_window<D, mln_value(I)> w_win;
mln_piter(I) p(input.domain());
for_all(p)
if (input(p) != 0)
w_win.insert(input(p), p - P::zero);
return w_win;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
} // end of namespace mln
#endif // ! MLN_CONVERT_TO_W_WINDOW_HH
......@@ -30,9 +30,10 @@
/*! \file mln/convert/to_window.hh
*
* \brief Convertions to mln::Window.
* \brief Conversions to mln::window.
*/
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/window.hh>
......@@ -45,24 +46,44 @@ namespace mln
/// Convert a neighborhood \p nbh into a window.
template <typename N>
window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
/// Convert a binary image \p input into a window.
template <typename I>
window<mln_dpoint(I)> to_window(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
template <typename N>
window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh_)
window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh_)
{
const N& nbh = exact(nbh_);
typedef mln_dpoint(N) D;
typedef mln_point(D) P;
window_<D> win;
window<D> win;
mln_niter(N) n(nbh, P::zero);
for_all(n)
win.insert(n - P::zero);
return win;
}
template <typename I>
window<mln_dpoint(I)> to_window(const Image<I>& input_)
{
const I& input = exact(input_);
mln_precondition(input.has_data());
// FIXME: Check that input is binary!
typedef mln_dpoint(I) D;
typedef mln_point(D) P;
window<D> win;
mln_piter(I) p(input.domain());
for_all(p)
if (input(p))
win.insert(p - P::zero);
return win;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
......
......@@ -56,6 +56,18 @@ namespace mln
*/
typedef void bkd_qiter;
/// Point associated type.
typedef void point;
/// Dpoint associated type.
typedef void dpoint;
/// Weight associated type.
typedef void weight;
/// Window associated type.
typedef void window;
/*! \brief Test if the weighted window is empty.
*
* A weighted_window of null size is empty.
......@@ -73,6 +85,10 @@ namespace mln
*/
unsigned delta() const;
/*! \brief Give the corresponding window.
*/
const window& win() const;
/*! \brief Give the symmetrical weighted_window.
*/
E sym_() const;
......
......@@ -55,6 +55,8 @@ namespace mln
typedef point;
typedef dpoint;
typedef weight;
typedef window;
E sym_() const;
*/
......@@ -62,13 +64,13 @@ namespace mln
/// Test if the weighted window is empty; final method.
bool is_empty() const
{
return exact(this)->window().is_empty();
return exact(this)->win().is_empty();
}
/// Test if the weighted window is centered; final method.
bool is_centered() const
{
return exact(this)->window().is_centered();
return exact(this)->win().is_centered();
}
// FIXME: Remove because too ambiguous: bool is_symmetric() const
......@@ -76,7 +78,7 @@ namespace mln
/// Give the maximum coordinate gap.
unsigned delta() const
{
return exact(this)->window().delta();
return exact(this)->win().delta();
}
protected:
......@@ -99,12 +101,17 @@ namespace mln
{
typedef mln_point(E) point;
typedef mln_dpoint(E) dpoint;
typedef mln_weight(E) weight;
typedef mln_window(E) window;
typedef mln_fwd_qiter(E) fwd_qiter;
typedef mln_bkd_qiter(E) bkd_qiter;
E (E::*m_)() const = & E::sym_;
m_ = 0;
E (E::*m1)() const = & E::sym_;
m1 = 0;
const window& (E::*m2)() const = & E::win;
m2 = 0;
}
template <typename W>
......
......@@ -161,6 +161,16 @@
# define mln_viter(T) typename T::fwd_viter
// w
/// Shortcut to access the weight type associated to T.
# define mln_weight(T) typename T::weight
/// Shortcut to access the window type associated to T.
# define mln_window(T) typename T::window
......
......@@ -30,13 +30,13 @@
/*! \file mln/core/w_window.hh
*
* \brief Definition of the generic weighted window class mln::w_window_.
* \brief Definition of the generic weighted window class mln::w_window.
*/
# include <map>
# include <mln/core/concept/weighted_window.hh>
# include <mln/core/window.hh>
# include <mln/core/concept/weighted_window.hh>
namespace mln
......@@ -54,7 +54,7 @@ namespace mln
* the type of weights.
*/
template <typename D, typename W>
struct w_window_ : public Weighted_Window< w_window_<D,W> >
struct w_window : public Weighted_Window< w_window<D,W> >
{
/// Point associated type.
typedef mln_point(D) point;
......@@ -62,6 +62,12 @@ namespace mln
/// Dpoint associated type.
typedef D dpoint;
/// Weight associated type.
typedef W weight;
/// Window associated type.
typedef mln::window<D> window;
/// Point_Iterator type to browse (forward) the points of a generic w_window.
typedef with_w_< dpoints_fwd_piter<D>, W > fwd_qiter;
......@@ -71,15 +77,15 @@ namespace mln
/// Constructor without argument.
w_window_();
w_window();
/// Insert a delta-point \p d and its associated weight \p w.
w_window_<D,W>& insert(const D& d, const W& w);
/// Insert a couple of weight \p w and delta-point \p d.
w_window<D,W>& insert(const W& w, const D& d);
/// Give the \p i-th weight.
W weight(unsigned i) const;
W w(unsigned i) const;
/// Give access to the vector of weights.
const std::vector<W>& weights() const;
......@@ -95,22 +101,31 @@ namespace mln
const std::vector<D>& vect() const;
/// Give the corresponding window.
const window_<D>& window() const;
const mln::window<D>& win() const;
/// Give the symmetrical w_window.
w_window_<D,W> sym_() const;
w_window<D,W> sym_() const;
protected:
window_<D> win_;
mln::window<D> win_;
std::vector<W> wei_;
};
/// Print a weighted window \p wwin into an output stream \p ostr.
/* \brief Print a weighted window \p w_win into an output stream \p ostr.
* \relates mln::w_window
*/
template <typename D, typename W>
std::ostream& operator<<(std::ostream& ostr, const w_window_<D,W>& wwin);
std::ostream& operator<<(std::ostream& ostr, const w_window<D,W>& w_win);
/* \brief Equality test between two weighted windows \p lhs and \p rhs.
* \relates mln::w_window
*/
template <typename D, typename Wl, typename Wr>
bool operator==(const w_window<D,Wl>& lhs, const w_window<D,Wr>& rhs);
......@@ -122,7 +137,7 @@ namespace mln
template <typename Ds, typename P>
with_w_(const Ds& ds, const P& p);
W weight() const;
W w() const;
protected:
const std::vector<W> wei_;
......@@ -146,39 +161,30 @@ namespace mln
template <typename It, typename W>
W
with_w_<It,W>::weight() const
with_w_<It,W>::w() const
{
mln_precondition(this->i_ < wei_.size());
return wei_[this->i_];
}
// w_window_<D,W>
template <typename D, typename W>
std::ostream& operator<<(std::ostream& ostr, const w_window_<D,W>& wwin)
{
ostr << '[';
for (unsigned i = 0; i < wwin.window().ndpoints(); ++i)
ostr << wwin.vect()[i] << ':' << wwin.weight(i) << ' ';
return ostr << ']';
}
// w_window<D,W>
template <typename D, typename W>
w_window_<D,W>::w_window_()
w_window<D,W>::w_window()
{
}
template <typename D, typename W>
const window_<D>&
w_window_<D,W>::window() const
const mln::window<D>&
w_window<D,W>::win() const
{
return win_;
}
template <typename D, typename W>
const D&
w_window_<D,W>::dp(unsigned i) const
w_window<D,W>::dp(unsigned i) const
{
mln_precondition(i < win_.ndpoints());
mln_invariant(wei_.size() == win_.ndpoints());
......@@ -187,7 +193,7 @@ namespace mln
template <typename D, typename W>
unsigned
w_window_<D,W>::ndpoints() const
w_window<D,W>::ndpoints() const
{
mln_invariant(wei_.size() == win_.ndpoints());
return win_.ndpoints();
......@@ -195,21 +201,21 @@ namespace mln
template <typename D, typename W>
const std::vector<D>&
w_window_<D,W>::vect() const
w_window<D,W>::vect() const
{
return win_.vect();
}
template <typename D, typename W>
const std::vector<W>&
w_window_<D,W>::weights() const
w_window<D,W>::weights() const
{
return wei_;
}
template <typename D, typename W>
W
w_window_<D,W>::weight(unsigned i) const
w_window<D,W>::w(unsigned i) const
{
mln_precondition(i < wei_.size());
mln_invariant(wei_.size() == win_.ndpoints());
......@@ -217,12 +223,13 @@ namespace mln
}
template <typename D, typename W>
w_window_<D,W>&
w_window_<D,W>::insert(const D& d, const W& w)
w_window<D,W>&
w_window<D,W>::insert(const W& w, const D& d)
{
mln_invariant(wei_.size() == win_.ndpoints());
mln_precondition(! win_.has(d));
if (win_.has(d))
if (w == W(0)) // FIXME: Implicit restriction "W scalar"...
// no-op
return *this;
......@@ -244,19 +251,48 @@ namespace mln
return *this;
}
template <typename D, typename W>
w_window_<D,W>
w_window_<D,W>::sym_() const
w_window<D,W>
w_window<D,W>::sym_() const
{
w_window_<D,W> tmp(*this);
w_window<D,W> tmp(*this);
tmp.win_ = - this->win_;
return *this;
}
// operators
template <typename D, typename W>
std::ostream& operator<<(std::ostream& ostr, const w_window<D,W>& w_win)
{
ostr << '[';
for (unsigned i = 0; i < w_win.win().ndpoints(); ++i)
ostr << w_win.vect()[i] << ':' << w_win.w(i) << ' ';
return ostr << ']';
}
template <typename D, typename Wl, typename Wr>
bool operator==(const w_window<D,Wl>& lhs, const w_window<D,Wr>& rhs)
{
if (lhs.ndpoints() != rhs.ndpoints())
return false;
if (lhs.win() != rhs.win())
return false;
const std::vector<Wl>& wl = lhs.weights();
const std::vector<Wr>& wr = rhs.weights();
mln_assertion(wl.size() == wr.size());
for (unsigned i = 0; i < wl.size(); ++i)
if (wr[i] != wl[i])
return false;
return true;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
# include <mln/make/w_window.hh>
#endif // ! MLN_CORE_W_WINDOW_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 MLN_CORE_W_WINDOW2D_FLOAT_HH
# define MLN_CORE_W_WINDOW2D_FLOAT_HH
/*! \file mln/core/w_window2d_float.hh
*