| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkGaussianOperator.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:36 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkGaussianOperator_h |
| 18 |
|
#define __itkGaussianOperator_h |
| 19 |
|
|
| 20 |
|
#include "itkNeighborhoodOperator.h" |
| 21 |
|
#include <math.h> |
| 22 |
|
namespace itk { |
| 23 |
|
|
| 24 |
|
/** |
| 25 |
|
* \class GaussianOperator |
| 26 |
|
* \brief A NeighborhoodOperator whose coefficients are a one |
| 27 |
|
* dimensional, discrete Gaussian kernel. |
| 28 |
|
* |
| 29 |
|
* GaussianOperator can be used to perform Gaussian blurring |
| 30 |
|
* by taking its inner product with to a Neighborhood |
| 31 |
|
* (NeighborhooIterator) that is swept across an image region. |
| 32 |
|
* It is a directional operator. N successive applications |
| 33 |
|
* oriented along each dimensional direction will effect separable, |
| 34 |
|
* efficient, N-D Gaussian blurring of an image region. |
| 35 |
|
* |
| 36 |
|
* GaussianOperator takes two parameters: |
| 37 |
|
|
| 38 |
|
* (1) The floating-point variance of the desired Gaussian function. |
| 39 |
|
|
| 40 |
|
* (2) The "maximum error" allowed in the discrete Gaussian |
| 41 |
|
* function. "Maximum errror" is defined as the difference between the area |
| 42 |
|
* under the discrete Gaussian curve and the area under the continuous |
| 43 |
|
* Gaussian. Maximum error affects the Gaussian operator size. Care should |
| 44 |
|
* be taken not to make this value too small relative to the variance |
| 45 |
|
* lest the operator size become unreasonably large. |
| 46 |
|
* |
| 47 |
|
* References: |
| 48 |
|
* The Gaussian kernel contained in this operator was described |
| 49 |
|
* by Tony Lindeberg (Discrete Scale-Space Theory and the Scale-Space |
| 50 |
|
* Primal Sketch. Dissertation. Royal Institute of Technology, Stockholm, |
| 51 |
|
* Sweden. May 1991.). |
| 52 |
|
* |
| 53 |
|
* \sa NeighborhoodOperator |
| 54 |
|
* \sa NeighborhoodIterator |
| 55 |
|
* \sa Neighborhood |
| 56 |
|
* |
| 57 |
|
* \ingroup Operators |
| 58 |
|
*/ |
| 59 |
|
template<class TPixel,unsigned int VDimension=2, |
| 60 |
|
class TAllocator = NeighborhoodAllocator<TPixel> > |
| 61 |
|
class ITK_EXPORT GaussianOperator |
| 62 |
IND |
**: public NeighborhoodOperator<TPixel, VDimension, TAllocator> |
| 63 |
|
{ |
| 64 |
|
public: |
| 65 |
|
/** Standard class typedefs. */ |
| 66 |
|
typedef GaussianOperator Self; |
| 67 |
TDA |
typedef NeighborhoodOperator<TPixel, VDimension, TAllocator> Superclass; |
| 68 |
|
|
| 69 |
|
/** Constructor. */ |
| 70 |
LEN |
GaussianOperator() : m_Variance(1), m_MaximumError(.01), m_MaximumKernelWidth(30) { } |
| 71 |
|
|
| 72 |
|
/** Copy constructor */ |
| 73 |
|
GaussianOperator(const Self &other) |
| 74 |
IND |
****: NeighborhoodOperator<TPixel, VDimension, TAllocator>(other) |
| 75 |
IND |
**{ |
| 76 |
|
m_Variance = other.m_Variance; |
| 77 |
|
m_MaximumError = other.m_MaximumError; |
| 78 |
|
m_MaximumKernelWidth = other.m_MaximumKernelWidth; |
| 79 |
IND |
**} |
| 80 |
|
|
| 81 |
|
/** Assignment operator */ |
| 82 |
|
Self &operator=(const Self &other) |
| 83 |
IND |
**{ |
| 84 |
|
Superclass::operator=(other); |
| 85 |
|
m_Variance = other.m_Variance; |
| 86 |
|
m_MaximumError = other.m_MaximumError; |
| 87 |
|
m_MaximumKernelWidth = other.m_MaximumKernelWidth; |
| 88 |
|
return *this; |
| 89 |
IND |
**} |
| 90 |
|
|
| 91 |
|
/** Sets the desired variance of the Gaussian kernel. */ |
| 92 |
|
void SetVariance(const double &variance) |
| 93 |
IND |
**{ m_Variance = variance; } |
| 94 |
|
|
| 95 |
|
/** Sets the desired maximum error of the gaussian approximation. Maximum |
| 96 |
|
* error is the difference between the area under the discrete Gaussian curve |
| 97 |
|
* and the area under the continuous Gaussian. Maximum error affects the |
| 98 |
|
* Gaussian operator size. */ |
| 99 |
|
void SetMaximumError(const double &max_error) |
| 100 |
IND |
**{ |
| 101 |
|
if (max_error >= 1 || max_error <= 0) |
| 102 |
|
{ |
| 103 |
|
throw ExceptionObject(__FILE__, __LINE__); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
m_MaximumError = max_error; |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
/** Returns the variance of the Gaussian (scale) for the operator. */ |
| 110 |
|
double GetVariance() |
| 111 |
|
{ return m_Variance; } |
| 112 |
|
|
| 113 |
LEN |
/** Returns the maximum error of the gaussian approximation. Maximum error is |
| 114 |
|
* the difference between the area under the discrete Gaussian curve and the |
| 115 |
|
* area under the continuous Gaussian. Maximum error affects the Gaussian |
| 116 |
|
* operator size. */ |
| 117 |
|
double GetMaximumError() |
| 118 |
|
{ return m_MaximumError; } |
| 119 |
|
|
| 120 |
|
/** Sets a limit for growth of the kernel. Small maximum error values with |
| 121 |
|
* large variances will yield very large kernel sizes. This value can be |
| 122 |
|
* used to truncate a kernel in such instances. A warning will be given on |
| 123 |
|
* truncation of the kernel. */ |
| 124 |
|
void SetMaximumKernelWidth( unsigned int n ) |
| 125 |
|
{ m_MaximumKernelWidth = n; } |
| 126 |
|
|
| 127 |
|
/** Returns the maximum allowed kernel width. */ |
| 128 |
|
unsigned int GetMaximumKernelWidth() const |
| 129 |
|
{ return m_MaximumKernelWidth; } |
| 130 |
|
|
| 131 |
|
/** Prints some debugging information. */ |
| 132 |
|
virtual void PrintSelf(std::ostream &os, Indent i) const |
| 133 |
|
{ |
| 134 |
|
os << i << "GaussianOperator { this=" << this |
| 135 |
|
<< ", m_Variance = " << m_Variance |
| 136 |
|
<< ", m_MaximumError = " << m_MaximumError |
| 137 |
|
<< "} " << std::endl; |
| 138 |
|
Superclass::PrintSelf(os, i.GetNextIndent()); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
protected: |
| 142 |
|
typedef typename Superclass::CoefficientVector CoefficientVector; |
| 143 |
|
|
| 144 |
LEN |
/** Returns the value of the modified Bessel function I0(x) at a point x >= 0. */ |
| 145 |
|
double ModifiedBesselI0(double); |
| 146 |
|
|
| 147 |
|
/** Returns the value of the modified Bessel function I1(x) at a point x, |
| 148 |
|
* x real. */ |
| 149 |
|
double ModifiedBesselI1(double); |
| 150 |
|
|
| 151 |
|
/** Returns the value of the modified Bessel function Ik(x) at a point x>=0, |
| 152 |
|
* where k>=2. */ |
| 153 |
|
double ModifiedBesselI(int, double); |
| 154 |
|
|
| 155 |
|
/** Calculates operator coefficients. */ |
| 156 |
|
CoefficientVector GenerateCoefficients(); |
| 157 |
|
|
| 158 |
|
/** Arranges coefficients spatially in the memory buffer. */ |
| 159 |
|
void Fill(const CoefficientVector& coeff) |
| 160 |
IND |
**{ this->FillCenteredDirectional(coeff); } |
| 161 |
|
|
| 162 |
|
private: |
| 163 |
|
/** Desired variance of the discrete Gaussian function. */ |
| 164 |
|
double m_Variance; |
| 165 |
|
|
| 166 |
|
/** Difference between the areas under the curves of the continuous and |
| 167 |
|
* discrete Gaussian functions. */ |
| 168 |
|
double m_MaximumError; |
| 169 |
|
|
| 170 |
|
/** Maximum kernel size allowed. This value is used to truncate a kernel |
| 171 |
|
* that has grown too large. A warning is given when the specified maximum |
| 172 |
|
* error causes the kernel to exceed this size. */ |
| 173 |
|
unsigned int m_MaximumKernelWidth; |
| 174 |
|
|
| 175 |
|
/** For compatibility with itkWarningMacro */ |
| 176 |
|
const char *GetNameOfClass() |
| 177 |
|
{ return "itkGaussianOperator"; } |
| 178 |
|
|
| 179 |
|
}; |
| 180 |
|
|
| 181 |
|
} // namespace itk |
| 182 |
|
|
| 183 |
|
|
| 184 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 185 |
|
#include "itkGaussianOperator.txx" |
| 186 |
|
#endif |
| 187 |
|
|
| 188 |
|
#endif |
| 189 |
|
|