static inline void PlasmaPixel(Image *image,RandomInfo *random_info,double x, double y) { ExceptionInfo *exception; QuantumAny range; register PixelPacket *q; exception=(&image->exception); q=GetAuthenticPixels(image,(ssize_t) ceil(x-0.5),(ssize_t) ceil(y-0.5),1,1, exception); if (q == (PixelPacket *) NULL) return; range=GetQuantumRange(16UL); q->red=ScaleAnyToQuantum((size_t) (65535.0* GetPseudoRandomValue(random_info)+0.5),range); q->green=ScaleAnyToQuantum((size_t) (65535.0* GetPseudoRandomValue(random_info)+0.5),range); q->blue=ScaleAnyToQuantum((size_t) (65535.0* GetPseudoRandomValue(random_info)+0.5),range); (void) SyncAuthenticPixels(image,exception); }
static inline void PlasmaPixel(Image *image,double x,double y) { register PixelPacket *q; q=GetImagePixels(image,(long) ceil(x-0.5),(long) ceil(y-0.5),1,1); if (q == (PixelPacket *) NULL) return; q->red=ScaleAnyToQuantum((unsigned long) (65535.0*GetPseudoRandomValue()+0.5),16UL); q->green=ScaleAnyToQuantum((unsigned long) (65535.0*GetPseudoRandomValue()+0.5),16UL); q->blue=ScaleAnyToQuantum((unsigned long) (65535.0*GetPseudoRandomValue()+0.5),16UL); (void) SyncImagePixels(image); }
static inline void PlasmaPixel(Image *image,RandomInfo *random_info,double x, double y,ExceptionInfo *exception) { register Quantum *q; q=GetAuthenticPixels(image,(ssize_t) ceil(x-0.5),(ssize_t) ceil(y-0.5),1,1, exception); if (q == (Quantum *) NULL) return; SetPixelRed(image,ScaleShortToQuantum((unsigned short) (65535.0* GetPseudoRandomValue(random_info)+0.5)),q); SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (65535.0* GetPseudoRandomValue(random_info)+0.5)),q); SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (65535.0* GetPseudoRandomValue(random_info)+0.5)),q); (void) SyncAuthenticPixels(image,exception); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e n e r a t e D i f f e r e n t i a l N o i s e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GenerateDifferentialNoise() generates differentual noise. % % The format of the GenerateDifferentialNoise method is: % % double GenerateDifferentialNoise(RandomInfo *random_info, % const Quantum pixel,const NoiseType noise_type, % const MagickRealType attenuate) % % A description of each parameter follows: % % o random_info: the random info. % % o pixel: noise is relative to this pixel value. % % o noise_type: the type of noise. % % o attenuate: attenuate the noise. % */ MagickExport double GenerateDifferentialNoise(RandomInfo *random_info, const Quantum pixel,const NoiseType noise_type,const MagickRealType attenuate) { #define SigmaUniform (attenuate*0.015625) #define SigmaGaussian (attenuate*0.015625) #define SigmaImpulse (attenuate*0.1) #define SigmaLaplacian (attenuate*0.0390625) #define SigmaMultiplicativeGaussian (attenuate*0.5) #define SigmaPoisson (attenuate*0.05/0.0001953125) #define TauGaussian (attenuate*0.078125) double alpha, beta, noise, sigma; alpha=GetPseudoRandomValue(random_info); switch (noise_type) { case UniformNoise: default: { noise=(double) pixel+QuantumRange*SigmaUniform*(alpha-0.5); break; } case GaussianNoise: { double gamma, tau; if (alpha == 0.0) alpha=1.0; beta=GetPseudoRandomValue(random_info); gamma=sqrt(-2.0*log(alpha)); sigma=gamma*cos((double) (2.0*MagickPI*beta)); tau=gamma*sin((double) (2.0*MagickPI*beta)); noise=(double) pixel+sqrt((double) pixel)*SigmaGaussian*sigma+ QuantumRange*TauGaussian*tau; break; } case ImpulseNoise: { if (alpha < (SigmaImpulse/2.0)) noise=0.0; else if (alpha >= (1.0-(SigmaImpulse/2.0))) noise=(double) QuantumRange; else noise=(double) pixel; break; } case LaplacianNoise: { if (alpha <= 0.5) { if (alpha <= MagickEpsilon) noise=(double) pixel-(double) QuantumRange; else noise=(double) pixel+QuantumRange*SigmaLaplacian* log(2.0*alpha)+0.5; break; } beta=1.0-alpha; if (beta <= (0.5*MagickEpsilon)) noise=(double) (pixel+QuantumRange); else noise=(double) pixel-QuantumRange*SigmaLaplacian*log(2.0*beta)+0.5; break; } case MultiplicativeGaussianNoise: { sigma=1.0; if (alpha > MagickEpsilon) sigma=sqrt(-2.0*log(alpha)); beta=GetPseudoRandomValue(random_info); noise=(double) pixel+pixel*SigmaMultiplicativeGaussian*sigma* cos((double) (2.0*MagickPI*beta))/2.0; break; } case PoissonNoise: { double poisson; register ssize_t i; poisson=exp(-SigmaPoisson*QuantumScale*pixel); for (i=0; alpha > poisson; i++) { beta=GetPseudoRandomValue(random_info); alpha*=beta; } noise=(double) QuantumRange*i/SigmaPoisson; break; } case RandomNoise: { noise=(double) QuantumRange*alpha; break; } } return(noise); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e n e r a t e D i f f e r e n t i a l N o i s e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GenerateDifferentialNoise() generates differentual noise. % % The format of the GenerateDifferentialNoise method is: % % double GenerateDifferentialNoise(RandomInfo *random_info, % const Quantum pixel,const NoiseType noise_type, % const MagickRealType attenuate) % % A description of each parameter follows: % % o random_info: the random info. % % o pixel: noise is relative to this pixel value. % % o noise_type: the type of noise. % % o attenuate: attenuate the noise. % */ MagickExport double GenerateDifferentialNoise(RandomInfo *random_info, const Quantum pixel,const NoiseType noise_type,const MagickRealType attenuate) { #define NoiseEpsilon (attenuate*1.0e-5) #define SigmaUniform (attenuate*4.0) #define SigmaGaussian (attenuate*4.0) #define SigmaImpulse (attenuate*0.10) #define SigmaLaplacian (attenuate*10.0) #define SigmaMultiplicativeGaussian (attenuate*1.0) #define SigmaPoisson (attenuate*0.05) #define TauGaussian (attenuate*20.0) double alpha, beta, noise, sigma; alpha=GetPseudoRandomValue(random_info); switch (noise_type) { case UniformNoise: default: { noise=(double) pixel+ScaleCharToQuantum((unsigned char) (SigmaUniform*(alpha))); break; } case GaussianNoise: { double tau; if (alpha == 0.0) alpha=1.0; beta=GetPseudoRandomValue(random_info); 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+sqrt((double) pixel)*SigmaGaussian*sigma+ TauGaussian*tau; break; } case MultiplicativeGaussianNoise: { if (alpha <= NoiseEpsilon) sigma=(double) QuantumRange; else sigma=sqrt(-2.0*log(alpha)); beta=GetPseudoRandomValue(random_info); noise=(double) pixel+pixel*SigmaMultiplicativeGaussian*sigma/2.0* cos((2.0*MagickPI*beta)); break; } case ImpulseNoise: { if (alpha < (SigmaImpulse/2.0)) noise=0.0; else if (alpha >= (1.0-(SigmaImpulse/2.0))) noise=(double) QuantumRange; else noise=(double) pixel; break; } case LaplacianNoise: { if (alpha <= 0.5) { if (alpha <= NoiseEpsilon) noise=(double) pixel-(double) QuantumRange; else noise=(double) pixel+ScaleCharToQuantum((unsigned char) (SigmaLaplacian*log((2.0*alpha))+0.5)); break; } beta=1.0-alpha; if (beta <= (0.5*NoiseEpsilon)) noise=(double) (pixel+QuantumRange); else noise=(double) pixel-ScaleCharToQuantum((unsigned char) (SigmaLaplacian*log((2.0*beta))+0.5)); break; } case PoissonNoise: { double poisson; register long i; poisson=exp(-SigmaPoisson*ScaleQuantumToChar(pixel)); for (i=0; alpha > poisson; i++) { beta=GetPseudoRandomValue(random_info); alpha*=beta; } noise=(double) ScaleCharToQuantum((unsigned char) (i/SigmaPoisson)); break; } case RandomNoise: { noise=(double) QuantumRange*GetPseudoRandomValue(random_info); break; } } return(noise); }