36 #ifndef VIGRA_GAUSSIANS_HXX
37 #define VIGRA_GAUSSIANS_HXX
41 #include "mathutil.hxx"
42 #include "array_vector.hxx"
62 template <
class T =
double>
96 vigra_precondition(sigma_ > 0.0,
97 "Gaussian::Gaussian(): sigma > 0 required.");
110 calculateHermitePolynomial();
133 double radius(
double sigmaMultiple = 3.0)
const
137 void calculateHermitePolynomial();
140 T sigma_, sigma2_, norm_;
146 typename Gaussian<T>::result_type
154 return detail::RequiresExplicitCast<result_type>::cast(g);
156 return detail::RequiresExplicitCast<result_type>::cast(x * g);
158 return detail::RequiresExplicitCast<result_type>::cast((1.0 -
sq(x / sigma_)) * g);
160 return detail::RequiresExplicitCast<result_type>::cast((3.0 -
sq(x / sigma_)) * x * g);
162 return order_ % 2 == 0 ?
163 detail::RequiresExplicitCast<result_type>::cast(g * horner(x2))
164 : detail::RequiresExplicitCast<result_type>::cast(x * g * horner(x2));
172 T res = hermitePolynomial_[i];
173 for(--i; i >= 0; --i)
174 res = x * res + hermitePolynomial_[i];
179 void Gaussian<T>::calculateHermitePolynomial()
183 hermitePolynomial_[0] = 1.0;
187 hermitePolynomial_[0] = T(-1.0 / sigma_ / sigma_);
202 T s2 = T(-1.0 / sigma_ / sigma_);
203 ArrayVector<T> hn(3*order_+3, 0.0);
204 typename ArrayVector<T>::iterator hn0 = hn.begin(),
205 hn1 = hn0 + order_+1,
206 hn2 = hn1 + order_+1,
210 for(
unsigned int i = 2; i <= order_; ++i)
212 hn0[0] = s2 * (i-1) * hn2[0];
213 for(
unsigned int j = 1; j <= i; ++j)
214 hn0[j] = s2 * (hn1[j-1] + (i-1) * hn2[j]);
221 for(
unsigned int i = 0; i < hermitePolynomial_.size(); ++i)
222 hermitePolynomial_[i] = order_ % 2 == 0 ?
double radius(double sigmaMultiple=3.0) const
Definition: gaussians.hxx:133
T argument_type
Definition: gaussians.hxx:72
linalg::TemporaryMatrix< T > exp(MultiArrayView< 2, T, C > const &v)
value_type sigma() const
Definition: gaussians.hxx:119
Definition: gaussians.hxx:63
NumericTraits< T >::Promote sq(T t)
The square function.
Definition: mathutil.hxx:382
Gaussian(T sigma=1.0, unsigned int derivativeOrder=0)
Definition: gaussians.hxx:89
T result_type
Definition: gaussians.hxx:75
int ceil(FixedPoint< IntBits, FracBits > v)
rounding up.
Definition: fixedpoint.hxx:675
T value_type
Definition: gaussians.hxx:69
result_type operator()(argument_type x) const
Definition: gaussians.hxx:147
SquareRootTraits< FixedPoint< IntBits, FracBits > >::SquareRootResult sqrt(FixedPoint< IntBits, FracBits > v)
square root.
Definition: fixedpoint.hxx:616
unsigned int derivativeOrder() const
Definition: gaussians.hxx:124