13 #ifndef mitkGaussianNoiseFunctor_h
14 #define mitkGaussianNoiseFunctor_h
21 template <
class TInputPixel,
class TOutputPixel>
35 this->m_Sigma = sigma;
40 return !(*
this == other);
45 return (this->m_Mu == other.m_Mu) && (this->m_Sigma == other.m_Sigma) ;
48 inline TOutputPixel
operator()(
const TInputPixel& value)
const
50 double n = noise(this->m_Mu, this->m_Sigma);
52 TOutputPixel result = value + n;
65 inline double noise(
double mu,
double sigma)
const
67 double u1, u2, W, mult;
74 return (mu + sigma * (
double)x2);
79 u1 = -1 + (
static_cast <double>(rand()) /
static_cast <double>(RAND_MAX)) * 2;
80 u2 = -1 + (
static_cast <double>(rand()) /
static_cast <double>(RAND_MAX)) * 2;
81 W = u1 * u1 + u2 * u2;
83 while (W >= 1 || W == 0);
85 mult = sqrt((-2 * log(W)) / W);
91 return (mu + sigma * (
double)x1);