52 #ifndef __PCL_GaussianFilter_h
53 #define __PCL_GaussianFilter_h
114 Initialize( sigma, epsilon, 1, 0 );
126 Initialize( sigma, epsilon, rho, theta );
137 Initialize( n, epsilon, 1, 0 );
149 Initialize( n, epsilon, rho, theta );
183 FVector v = coefficients.RowVector( Size()>>1 );
206 (void)KernelFilter::operator =( x );
208 m_epsilon = x.m_epsilon;
219 (void)KernelFilter::operator =( std::move( x ) );
221 m_epsilon = x.m_epsilon;
242 return m_rho*m_sigma;
289 return 2.3548200450309493 * m_sigma;
299 return m_rho * FWHMx();
319 void Set(
float sigma,
float epsilon,
float rho,
float theta )
321 Initialize( sigma, epsilon, rho, theta );
329 void Set(
float sigma,
float epsilon,
float rho )
331 Initialize( sigma, epsilon, rho, m_theta );
339 void Set(
float sigma,
float epsilon )
341 Initialize( sigma, epsilon, m_rho, m_theta );
351 Initialize( sigma, m_epsilon, m_rho, m_theta );
368 Set( m_sigma, epsilon );
377 Set( m_sigma, m_epsilon, rho );
386 Set( m_sigma, m_epsilon, m_rho, theta );
397 Initialize( n, m_epsilon, m_rho, m_theta );
417 float m_epsilon = 0.01F;
419 void Initialize(
float s,
float e,
float r,
float a )
421 PCL_PRECONDITION( s > 0 )
422 PCL_PRECONDITION( e > 0 )
423 PCL_PRECONDITION( r >= 0 && r <= 1 )
424 PCL_PRECONDITION( a >= 0 && a <=
Const<
float>::pi() )
426 m_epsilon =
Abs( e );
427 m_rho =
Range( r, 0.0F, 1.0F );
428 m_theta =
Range( a, 0.0F,
Const<
float>::pi() );
433 void Initialize(
int n,
float e,
float r,
float a )
435 PCL_PRECONDITION( n == 0 || n >= 3 && (n & 1) != 0 )
436 PCL_PRECONDITION( e > 0 )
437 PCL_PRECONDITION( r >= 0 && r <= 1 )
438 PCL_PRECONDITION( a >= 0 && a <=
Const<
float>::pi() )
440 m_epsilon =
Abs( e );
441 m_sigma = (Size() >> 1)/
Sqrt( -2*
Ln( m_epsilon ) );
442 m_rho =
Range( r, 0.0F, 1.0F );
443 m_theta =
Range( a, 0.0F,
Const<
float>::pi() );
453 float* __restrict__ h = *coefficients;
455 double sy = m_rho * sx;
457 if ( m_theta == 0 || m_rho == 1 )
459 double twosx2 = 2*sx*sx;
460 double twosy2 = 2*sy*sy;
461 for (
int n2 = size >> 1, dy = -n2; dy <= n2; ++dy )
463 for (
int dx = 0; dx < size; ++dx, ++h )
464 *h = *(h - ((dy+dy)*size));
466 for (
int dx = -n2; dx <= n2; ++dx, ++h )
467 *h = (dx > 0) ? *(h - (dx+dx)) : float(
Exp( -(dx*dx/twosx2 + dy*dy/twosy2) ) );
471 double st, ct;
SinCos(
double( m_theta ), st, ct );
475 double twosx2 = 2*sx*sx;
476 double twosy2 = 2*sy*sy;
477 double p1 = ct2/twosx2 + st2/twosy2;
478 double p2 = sct/twosy2 - sct/twosx2;
479 double p3 = st2/twosx2 + ct2/twosy2;
480 for (
int n2 = size >> 1, dy = -n2; dy <= n2; ++dy )
482 double twop2dy = 2*p2*dy;
483 double p3dy2 = p3*dy*dy;
484 for (
int dx = -n2; dx <= n2; ++dx, ++h )
485 *h =
float(
Exp( -(p1*dx*dx + twop2dy*dx + p3dy2) ) );
Fundamental numeric constants.
A kernel filter implementing a discrete Gaussian distribution in two dimensions.
void Set(float sigma, float epsilon, float rho, float theta)
GaussianFilter(int n, float epsilon, float rho, float theta=0, const String &name=String())
friend void Swap(GaussianFilter &x1, GaussianFilter &x2)
void SetSigma(float sigma)
void Resize(int n) override
GaussianFilter(float sigma, float epsilon, float rho, float theta=0, const String &name=String())
float RotationAngle() const
void Set(float sigma, float epsilon, float rho)
SeparableFilter AsSeparableFilter(float tolerance=__PCL_DEFAULT_FILTER_SEPARABILITY_TOLERANCE) const override
GaussianFilter(float sigma, float epsilon=0.01, const String &name=String())
void SetAspectRatio(float rho)
GaussianFilter(const GaussianFilter &)=default
float AspectRatio() const
bool IsSeparable() const override
void SetRotationAngle(float theta)
KernelFilter * Clone() const override
void Set(float sigma, float epsilon)
void SetTruncation(float epsilon)
GaussianFilter(GaussianFilter &&)=default
GaussianFilter(int n, float epsilon=0.01, const String &name=String())
Generic vector of arbitrary length.
Kernel filter in two dimensions.
Separable filter in two dimensions.
Complex< T > Sqrt(const Complex< T > &c) noexcept
Complex< T > Exp(const Complex< T > &c) noexcept
Complex< T > Ln(const Complex< T > &c) noexcept
T Abs(const Complex< T > &c) noexcept
void SinCos(T x, T &sx, T &cx) noexcept
int RoundInt(T x) noexcept
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2) noexcept
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
constexpr const T & Max(const T &a, const T &b) noexcept