{
#define NoiseEpsilon (attenuate*1.0e-5)
#define SigmaUniform ScaleCharToQuantum((unsigned char) (attenuate*4.0+0.5))
-#define SigmaGaussian ScaleCharToQuantum((unsigned char) (attenuate*4.0+0.5))
+#define SigmaGaussian 4.0
#define SigmaImpulse (attenuate*0.10)
#define SigmaLaplacian ScaleCharToQuantum((unsigned char) (attenuate*10.0+0.5))
#define SigmaMultiplicativeGaussian \
ScaleCharToQuantum((unsigned char) (attenuate*1.0+0.5))
#define SigmaPoisson (attenuate*0.05)
-#define TauGaussian ScaleCharToQuantum((unsigned char) (attenuate*20.0+0.5))
+#define TauGaussian 20.0
- MagickRealType
+ double
alpha,
beta,
noise,
sigma;
alpha=GetPseudoRandomValue(random_info);
- if (alpha == 0.0)
- alpha=1.0;
switch (noise_type)
{
case UniformNoise:
default:
{
- noise=(MagickRealType) pixel+SigmaUniform*(alpha-0.5);
+ noise=(double) pixel+SigmaUniform*(alpha-0.5);
break;
}
case GaussianNoise:
{
- MagickRealType
+ double
tau;
+ if (alpha == 0.0)
+ alpha=1.0;
beta=GetPseudoRandomValue(random_info);
- sigma=sqrt(-2.0*log((double) alpha))*cos((double) (2.0*MagickPI*beta));
- tau=sqrt(-2.0*log((double) alpha))*sin((double) (2.0*MagickPI*beta));
- noise=(MagickRealType) pixel+sqrt((double) pixel)*SigmaGaussian*sigma+
+ sigma=sqrt(-2.0*log(alpha))*cos(2.0*MagickPI*beta);
+ tau=sqrt(-2.0*log(alpha))*sin(2.0*MagickPI*beta);
+ noise=(double) pixel+attenuate*sqrt((double) pixel)*SigmaGaussian*sigma+
TauGaussian*tau;
break;
}
case MultiplicativeGaussianNoise:
{
if (alpha <= NoiseEpsilon)
- sigma=(MagickRealType) QuantumRange;
+ sigma=(double) QuantumRange;
else
- sigma=sqrt(-2.0*log((double) alpha));
+ sigma=sqrt(-2.0*log(alpha));
beta=GetPseudoRandomValue(random_info);
- noise=(MagickRealType) pixel+pixel*SigmaMultiplicativeGaussian*sigma/2.0*
- cos((double) (2.0*MagickPI*beta));
+ noise=(double) pixel+pixel*SigmaMultiplicativeGaussian*sigma/2.0*
+ cos((2.0*MagickPI*beta));
break;
}
case ImpulseNoise:
noise=0.0;
else
if (alpha >= (1.0-(SigmaImpulse/2.0)))
- noise=(MagickRealType) QuantumRange;
+ noise=(double) QuantumRange;
else
- noise=(MagickRealType) pixel;
+ noise=(double) pixel;
break;
}
case LaplacianNoise:
if (alpha <= 0.5)
{
if (alpha <= NoiseEpsilon)
- noise=(MagickRealType) pixel-(MagickRealType) QuantumRange;
+ noise=(double) pixel-(double) QuantumRange;
else
- noise=(MagickRealType) pixel+ScaleCharToQuantum((unsigned char)
- (SigmaLaplacian*log((double) (2.0*alpha))+0.5));
+ noise=(double) pixel+ScaleCharToQuantum((unsigned char)
+ (SigmaLaplacian*log((2.0*alpha))+0.5));
break;
}
beta=1.0-alpha;
if (beta <= (0.5*NoiseEpsilon))
- noise=(MagickRealType) (pixel+QuantumRange);
+ noise=(double) (pixel+QuantumRange);
else
- noise=(MagickRealType) pixel-ScaleCharToQuantum((unsigned char)
- (SigmaLaplacian*log((double) (2.0*beta))+0.5));
+ noise=(double) pixel-ScaleCharToQuantum((unsigned char)
+ (SigmaLaplacian*log((2.0*beta))+0.5));
break;
}
case PoissonNoise:
{
- MagickRealType
+ double
poisson;
register long
i;
- poisson=exp(-SigmaPoisson*(double) ScaleQuantumToChar(pixel));
+ poisson=exp(-SigmaPoisson*ScaleQuantumToChar(pixel));
for (i=0; alpha > poisson; i++)
{
beta=GetPseudoRandomValue(random_info);
alpha*=beta;
}
- noise=(MagickRealType) ScaleCharToQuantum((unsigned char)
- (i/SigmaPoisson));
+ noise=(double) ScaleCharToQuantum((unsigned char) (i/SigmaPoisson));
break;
}
case RandomNoise:
{
- noise=(MagickRealType) QuantumRange*GetPseudoRandomValue(random_info);
+ noise=(double) QuantumRange*GetPseudoRandomValue(random_info);
break;
}
}