13 #ifndef mitkGaussianNoiseFunctor_h
14 #define mitkGaussianNoiseFunctor_h
31 template <
class TInputPixel,
class TOutputPixel>
47 this->m_Sigma = sigma;
52 return !(*
this == other);
57 return (this->m_Mu == other.m_Mu) && (this->m_Sigma == other.m_Sigma) ;
60 inline TOutputPixel
operator()(
const TInputPixel& value)
const
62 double n = noise(this->m_Mu, this->m_Sigma);
64 TOutputPixel result = value + n;
76 inline double noise(
double mu,
double sigma)
const
78 double u1, u2, W, mult;
85 return (mu + sigma * (
double)x2);
90 u1 = -1 + (
static_cast <double>(rand()) /
static_cast <double>(RAND_MAX)) * 2;
91 u2 = -1 + (
static_cast <double>(rand()) /
static_cast <double>(RAND_MAX)) * 2;
92 W = u1 * u1 + u2 * u2;
94 while (W >= 1 || W == 0);
96 mult = sqrt((-2 * log(W)) / W);
102 return (mu + sigma * (
double)x1);
Pixel functor that adds Gaussian noise to a pixel value.
void SetMean(double mu)
Sets the mean of the Gaussian noise distribution.
TOutputPixel operator()(const TInputPixel &value) const
void SetSigma(double sigma)
Sets the standard deviation of the Gaussian noise distribution.
bool operator!=(const GaussianNoiseFunctor &other) const
bool operator==(const GaussianNoiseFunctor &other) const
Find image slices visible on a given plane.