Documentation Center

  • Trial Software
  • Product Updates

imnoise

Add noise to image

Syntax

J = imnoise(I,type)
J = imnoise(I,type,parameters)
J = imnoise(I,'gaussian',M,V)
J = imnoise(I,'localvar',V)
J = imnoise(I,'localvar',image_intensity,var)
J = imnoise(I,'poisson')
J = imnoise(I,'salt & pepper',d)
J = imnoise(I,'speckle',v)
gpuarrayJ = imnoise(gpuarrayI,___)

Description

J = imnoise(I,type) adds noise of a given type to the intensity image I. type is a string that specifies any of the following types of noise. Note that certain types of noise support additional parameters. See the related syntax.

Value

Description

'gaussian'

Gaussian white noise with constant mean and variance

'localvar'

Zero-mean Gaussian white noise with an intensity-dependent variance

'poisson'

Poisson noise

'salt & pepper'

On and off pixels

'speckle'

Multiplicative noise

J = imnoise(I,type,parameters) Depending on type, you can specify additional parameters to imnoise. All numerical parameters are normalized— they correspond to operations with images with intensities ranging from 0 to 1.

J = imnoise(I,'gaussian',M,V) adds Gaussian white noise of mean m and variance v to the image I. The default is zero mean noise with 0.01 variance.

J = imnoise(I,'localvar',V) adds zero-mean, Gaussian white noise of local variance V to the image I. V is an array of the same size as I.

J = imnoise(I,'localvar',image_intensity,var) adds zero-mean, Gaussian noise to an image I, where the local variance of the noise, var, is a function of the image intensity values in I. The image_intensity and var arguments are vectors of the same size, and plot(image_intensity,var) plots the functional relationship between noise variance and image intensity. The image_intensity vector must contain normalized intensity values ranging from 0 to 1.

J = imnoise(I,'poisson') generates Poisson noise from the data instead of adding artificial noise to the data. If I is double precision, then input pixel values are interpreted as means of Poisson distributions scaled up by 1e12. For example, if an input pixel has the value 5.5e-12, then the corresponding output pixel will be generated from a Poisson distribution with mean of 5.5 and then scaled back down by 1e12. If I is single precision, the scale factor used is 1e6. If I is uint8 or uint16, then input pixel values are used directly without scaling. For example, if a pixel in a uint8 input has the value 10, then the corresponding output pixel will be generated from a Poisson distribution with mean 10.

J = imnoise(I,'salt & pepper',d) adds salt and pepper noise to the image I, where d is the noise density. This affects approximately d*numel(I) pixels. The default for d is 0.05.

J = imnoise(I,'speckle',v) adds multiplicative noise to the image I, using the equation J = I+n*I, where n is uniformly distributed random noise with mean 0 and variance v. The default for v is 0.04.

    Note   The mean and variance parameters for 'gaussian', 'localvar', and 'speckle' noise types are always specified as if the image were of class double in the range [0, 1]. If the input image is of class uint8 or uint16, the imnoise function converts the image to double, adds noise according to the specified type and parameters, and then converts the noisy image back to the same class as the input.

gpuarrayJ = imnoise(gpuarrayI,___) adds noise to the gpuArray intensity image gpuarrayI, performing the operation on a GPU. Returns a gpuArray image J of the same class. This syntax requires the Parallel Computing Toolbox™.

Class Support

For most noise types, the input image I can be of class uint8, uint16, int16, single, or double. For Poisson noise, int16 is not allowed. The output image J is of the same class as I. If I has more than two dimensions it is treated as a multidimensional intensity image and not as an RGB image.

An input gpuArray image I can be of class uint8, uint16, int16, single, or double. For Poisson noise, int16 is not allowed. The output gpuArray image J is of the same class as I. If I has more than two dimensions it is treated as a multidimensional intensity image and not as an RGB gpuArray image.

Examples

Add noise to an image.

Add noise to an image.

I = imread('eight.tif');
J = imnoise(I,'salt & pepper',0.02);
figure, imshow(I)
figure, imshow(J)

Add Noise to an Image Performing Operation on a GPU

I = gpuArray(imread('eight.tif'));
J = imnoise(I,'salt & pepper', 0.02);

figure, imshow(I);
figure, imshow(J);

See Also

| |

Was this topic helpful?