Commit 38469bb4 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Update accus and add LoG filter.

	* mln/core/concept/accumulator.hh (merge): New.
	* mln/core/concept/doc/accumulator.hh
	(take): New; overload.
	* mln/accu/bbox.hh,
	* mln/accu/count.hh,
	* mln/accu/histo.hh,
	* mln/accu/max.hh,
	* mln/accu/mean.hh,
	* mln/accu/min.hh,
	* mln/accu/sum.hh (operator+=): Rename as...
	(take): ...this.
	(conversion): Remove operator; too risky.
	Update.
	* mln/estim/mean.hh: Update.
	* mln/level/fast_median.hh: Update.
	* mln/level/median.hh: Update.
	* mln/level/naive/median.hh: Update.
	* mln/morpho/erosion.hh: Update.

	* mln/border/duplicate.hh,
	* mln/border/fill.hh,
	* mln/border/mirror.hh,
	* mln/border/resize.hh: Add fixme.
	
	* mln/io/load_pgm,
	* mln/io/save_pgm: Fix for g++-2.95.
	* mln/linear/convolve.hh: Use border.
	* tests/convolve.cc: Update.
	
	* mln/accu/min_max.hh: New.
	* mln/estim/min_max.hh: New.
	* mln/fun/v2v/linear.hh: New.
	* mln/level/stretch.hh: New.
	* mln/linear/log.hh: New.
	* mln/value/props.hh (epsilon): New.
	* tests/linear_log.cc: New.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1051 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 591901fb
2007-08-27 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Update accus and add LoG filter.
* mln/core/concept/accumulator.hh (merge): New.
* mln/core/concept/doc/accumulator.hh
(take): New; overload.
* mln/accu/bbox.hh,
* mln/accu/count.hh,
* mln/accu/histo.hh,
* mln/accu/max.hh,
* mln/accu/mean.hh,
* mln/accu/min.hh,
* mln/accu/sum.hh (operator+=): Rename as...
(take): ...this.
(conversion): Remove operator; too risky.
Update.
* mln/estim/mean.hh: Update.
* mln/level/fast_median.hh: Update.
* mln/level/median.hh: Update.
* mln/level/naive/median.hh: Update.
* mln/morpho/erosion.hh: Update.
* mln/border/duplicate.hh,
* mln/border/fill.hh,
* mln/border/mirror.hh,
* mln/border/resize.hh: Add fixme.
* mln/io/load_pgm,
* mln/io/save_pgm: Fix for g++-2.95.
* mln/linear/convolve.hh: Use border.
* tests/convolve.cc: Update.
* mln/accu/min_max.hh: New.
* mln/estim/min_max.hh: New.
* mln/fun/v2v/linear.hh: New.
* mln/level/stretch.hh: New.
* mln/linear/log.hh: New.
* mln/value/props.hh (epsilon): New.
* tests/linear_log.cc: New.
2007-08-27 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add 'decorated image' morpher.
......
......@@ -54,10 +54,11 @@ namespace mln
typedef P value;
bbox();
void take(const P& p);
void take(const bbox<P>& other);
void init();
operator box_<P>() const;
const box_<P>& to_value() const;
bool is_valid() const;
......@@ -79,7 +80,8 @@ namespace mln
}
template <typename P>
void bbox<P>::take(const P& p)
void
bbox<P>::take(const P& p)
{
if (! is_valid_)
{
......@@ -97,16 +99,33 @@ namespace mln
template <typename P>
void
bbox<P>::init()
bbox<P>::take(const bbox<P>& other)
{
is_valid_ = false;
if (! other.is_valid_)
{
// no-op
return;
}
if (! this->is_valid_)
{
// 'other' makes '*this' valid
*this = other;
return;
}
// both are valids so:
const box_<P>& o_b = other.b_;
for (unsigned i = 0; i < P::dim; ++i)
if (o_b.pmin()[i] < b_.pmin()[i])
b_.pmin()[i] = o_b.pmin()[i];
else if (o_b.pmax()[i] > b_.pmax()[i])
b_.pmax()[i] = o_b.pmax()[i];
}
template <typename P>
bbox<P>::operator box_<P>() const
void
bbox<P>::init()
{
mln_precondition(is_valid_);
return b_;
is_valid_ = false;
}
template <typename P>
......
......@@ -51,14 +51,13 @@ namespace mln
typedef V value;
count();
void take(const value&);
void init();
void take(const value&);
void take(const count<V>& other);
operator std::size_t() const;
std::size_t to_value() const;
count<V>& operator+=(const count<V>& rhs);
protected:
std::size_t count_;
......@@ -76,22 +75,23 @@ namespace mln
template <typename V>
void
count<V>::take(const value&)
count<V>::init()
{
++count_;
count_ = 0;
}
template <typename V>
void
count<V>::init()
count<V>::take(const value&)
{
count_ = 0;
++count_;
}
template <typename V>
count<V>::operator std::size_t() const
void
count<V>::take(const count<V>& other)
{
return to_value();
count_ += other.count_;
}
template <typename V>
......@@ -101,14 +101,6 @@ namespace mln
return count_;
}
template <typename V>
count<V>&
count<V>::operator+=(const count<V>& rhs)
{
count_ += rhs.count_;
return *this;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
......
......@@ -59,6 +59,7 @@ namespace mln
typedef mln_value(S) value;
void take(const value& v);
void take(const histo<S>& other);
void untake(const value& v);
void init();
......@@ -111,6 +112,15 @@ namespace mln
++sum_;
}
template <typename S>
void
histo<S>::take(const histo<S>& other)
{
for (unsigned i = 0; i < h_.size(); ++i)
h_[i] += other.h_[i];
sum_ += other.sum_;
}
template <typename S>
void
histo<S>::untake(const value& v)
......
......@@ -54,10 +54,11 @@ namespace mln
typedef V value;
max();
void take(const value& v);
void take(const max<V>& other);
void init();
operator V() const;
V to_value() const;
protected:
......@@ -76,7 +77,8 @@ namespace mln
}
template <typename V>
void max<V>::take(const value& v)
void
max<V>::take(const value& v)
{
if (v > v_)
v_ = v;
......@@ -84,15 +86,17 @@ namespace mln
template <typename V>
void
max<V>::init()
max<V>::take(const max<V>& other)
{
v_ = mln_min(V);
if (other.v_ > v_)
v_ = other.v_;
}
template <typename V>
max<V>::operator V() const
void
max<V>::init()
{
return v_;
v_ = mln_min(V);
}
template <typename V>
......
......@@ -60,14 +60,13 @@ namespace mln
typedef V value;
mean();
void take(const value& v);
void init();
void take(const value& v);
void take(const mean<V,S,M>& other);
operator M() const;
M to_value() const;
mean<V,S,M>& operator+=(const mean<V,S,M>& rhs);
protected:
accu::count<V> count_;
......@@ -84,13 +83,6 @@ namespace mln
init();
}
template <typename V, typename S, typename M>
void mean<V,S,M>::take(const value& v)
{
count_.take(v);
sum_.take(v);
}
template <typename V, typename S, typename M>
void
mean<V,S,M>::init()
......@@ -100,25 +92,25 @@ namespace mln
}
template <typename V, typename S, typename M>
mean<V,S,M>::operator M() const
void mean<V,S,M>::take(const value& v)
{
return to_value();
count_.take(v);
sum_.take(v);
}
template <typename V, typename S, typename M>
M
mean<V,S,M>::to_value() const
void
mean<V,S,M>::take(const mean<V,S,M>& other)
{
return sum_.to_value() / count_.to_value();
count_.take(other.count_);
sum_.take(other.sum_);
}
template <typename V, typename S, typename M>
mean<V,S,M>&
mean<V,S,M>::operator+=(const mean<V,S,M>& rhs)
M
mean<V,S,M>::to_value() const
{
count_ += rhs.count_;
sum_ += rhs.sum_;
return *this;
return sum_.to_value() / count_.to_value();
}
# endif // ! MLN_INCLUDE_ONLY
......
......@@ -55,13 +55,13 @@ namespace mln
median(const Value_Set<S>& s);
median();
void init();
void take(const value& v);
void take(const median<S>& other);
void untake(const value& v);
void init();
unsigned card() const { return h_.sum(); }
operator mln_value(S) () const;
value to_value() const;
const accu::histo<S>& histo() const;
......@@ -117,6 +117,25 @@ namespace mln
valid_ = false;
}
template <typename S>
void
median<S>::take(const median<S>& other)
{
// h_
h_.take(other.h_);
// sum_minus_
for (unsigned i = 0; i < i_; ++i)
sum_minus_ += other.h_[i];
// sum_plus_
for (unsigned i = i_ + 1; i < h_.nvalues(); ++i)
sum_plus_ += other.h_[i];
if (valid_)
valid_ = false;
}
template <typename S>
void
median<S>::untake(const value& v)
......@@ -202,12 +221,6 @@ namespace mln
valid_ = true;
}
template <typename S>
median<S>::operator mln_value(S) () const
{
return to_value();
}
template <typename S>
typename median<S>::value
median<S>::to_value() const
......
......@@ -54,10 +54,11 @@ namespace mln
typedef V value;
min();
void take(const value& v);
void take(const min<V>& other);
void init();
operator V() const;
V to_value() const;
protected:
......@@ -75,13 +76,6 @@ namespace mln
init();
}
template <typename V>
void min<V>::take(const value& v)
{
if (v < v_)
v_ = v;
}
template <typename V>
void
min<V>::init()
......@@ -90,9 +84,18 @@ namespace mln
}
template <typename V>
min<V>::operator V() const
void min<V>::take(const value& v)
{
return v_;
if (v < v_)
v_ = v;
}
template <typename V>
void
min<V>::take(const min<V>& other)
{
if (other.v_ < v_)
v_ = other.v_;
}
template <typename V>
......
// 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_ACCU_MIN_MAX_HH
# define MLN_ACCU_MIN_MAX_HH
/*! \file mln/accu/min_max.hh
*
* \brief Define an accumulator that computes a min and a max.
*/
# include <utility>
# include <mln/accu/min.hh>
# include <mln/accu/max.hh>
namespace mln
{
namespace accu
{
/*! Generic min and max accumulator class.
*
* The parameter \c V is the type of values.
*/
template <typename V>
struct min_max : public Accumulator< min_max<V> >
{
typedef V value;
min_max();
void take(const value& v);
void take(const min_max<V>& other);
void init();
V min() const;
V max() const;
std::pair<V,V> to_value() const;
void values(V& min, V& max) const;
protected:
accu::min<V> min_;
accu::max<V> max_;
};
# ifndef MLN_INCLUDE_ONLY
template <typename V>
min_max<V>::min_max()
{
init();
}
template <typename V>
void
min_max<V>::init()
{
min_.init();
max_.init();
}
template <typename V>
void min_max<V>::take(const value& v)
{
min_.take(v);
max_.take(v);
}
template <typename V>
void
min_max<V>::take(const min_max<V>& other)
{
min_.take(other.min_);
max_.take(other.max_);
}
template <typename V>
V
min_max<V>::min() const
{
return min_.to_value();
}
template <typename V>
V
min_max<V>::max() const
{
return max_.to_value();
}
template <typename V>
std::pair<V,V>
min_max<V>::to_value() const
{
std::pair<V,V> tmp(min_.to_value(),
max_.to_value());
return tmp;
}
template <typename V>
void
min_max<V>::values(V& min, V& max) const
{
min = min_.to_value();
max = max_.to_value();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
} // end of namespace mln
#endif // ! MLN_ACCU_MIN_MAX_HH
......@@ -56,13 +56,12 @@ namespace mln
typedef V value;
sum();
void take(const value& v);
void init();
void take(const value& v);
void take(const sum<V,S>& other);
operator S() const;
S to_value() const;
sum<V,S>& operator+=(const sum<V,S>& rhs);
protected:
......@@ -79,12 +78,6 @@ namespace mln
init();
}
template <typename V, typename S>
void sum<V,S>::take(const value& v)
{
sum_ += v;
}
template <typename V, typename S>
void
sum<V,S>::init()
......@@ -93,24 +86,23 @@ namespace mln
}
template <typename V, typename S>
sum<V,S>::operator S() const
void sum<V,S>::take(const value& v)
{
return to_value;
sum_ += v;
}
template <typename V, typename S>
S
sum<V,S>::to_value() const
void
sum<V,S>::take(const sum<V,S>& other)
{
return sum_;
sum_ += other.sum_;
}
template <typename V, typename S>
sum<V,S>&
sum<V,S>::operator+=(const sum<V,S>& rhs)
S
sum<V,S>::to_value() const
{
sum_ += rhs.sum_;
return *this;
return sum_;
}
# endif // ! MLN_INCLUDE_ONLY
......
......@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
# include <mln/core/internal/fixme.hh>