36#ifndef VIGRA_GAUSSIANS_HXX
37#define VIGRA_GAUSSIANS_HXX
41#include "mathutil.hxx"
42#include "array_vector.hxx"
62template <
class T =
double>
96 vigra_precondition(sigma_ > 0.0,
97 "Gaussian::Gaussian(): sigma > 0 required.");
102 norm_ = T(-1.0 / (VIGRA_CSTD::sqrt(2.0 * M_PI) * sq(
sigma) *
sigma));
105 norm_ = T(1.0 / (VIGRA_CSTD::sqrt(2.0 * M_PI) * sq(
sigma) * sq(
sigma) *
sigma));
108 norm_ = T(1.0 / VIGRA_CSTD::sqrt(2.0 * M_PI) /
sigma);
110 calculateHermitePolynomial();
137 void calculateHermitePolynomial();
140 T sigma_, sigma2_, norm_;
150 T g = norm_ * VIGRA_CSTD::exp(
x2 * sigma2_);
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];
179void 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);
210 for(
unsigned int i = 2;
i <= order_; ++
i)
213 for(
unsigned int j = 1;
j <=
i; ++
j)
221 for(
unsigned int i = 0;
i < hermitePolynomial_.size(); ++
i)
222 hermitePolynomial_[
i] = order_ % 2 == 0 ?
Definition gaussians.hxx:64
Gaussian(T sigma=1.0, unsigned int derivativeOrder=0)
Definition gaussians.hxx:89
T value_type
Definition gaussians.hxx:69
double radius(double sigmaMultiple=3.0) const
Definition gaussians.hxx:133
value_type sigma() const
Definition gaussians.hxx:119
T result_type
Definition gaussians.hxx:75
result_type operator()(argument_type x) const
Definition gaussians.hxx:147
T argument_type
Definition gaussians.hxx:72
unsigned int derivativeOrder() const
Definition gaussians.hxx:124
Class for a single RGB value.
Definition rgbvalue.hxx:128
RGBValue()
Definition rgbvalue.hxx:209