This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

imnoise

Add noise to image

Syntax

J = imnoise(I,'gaussian')
J = imnoise(I,'gaussian',m)
J = imnoise(I,'gaussian',m,var_gauss)
J = imnoise(I,'localvar',var_local)
J = imnoise(I,'localvar',intensity_map,var_local)
J = imnoise(I,'poisson')
J = imnoise(I,'salt & pepper')
J = imnoise(I,'salt & pepper',d)
J = imnoise(I,'speckle')
J = imnoise(I,'speckle',var_speckle)

Description

J = imnoise(I,'gaussian') adds zero-mean, Gaussian white noise with variance of 0.01 to grayscale image I.

You optionally can add noise using a GPU (requires Parallel Computing Toolbox™). For more information, see Image Processing on a GPU.

J = imnoise(I,'gaussian',m) adds Gaussian white noise with mean m and variance of 0.01.

J = imnoise(I,'gaussian',m,var_gauss) adds Gaussian white noise with mean m and variance var_gauss.

J = imnoise(I,'localvar',var_local) adds zero-mean, Gaussian white noise of local variance var_local.

J = imnoise(I,'localvar',intensity_map,var_local) adds zero-mean, Gaussian white noise. The local variance of the noise, var_local, is a function of the image intensity values in I. The mapping of image intensity value to noise variance is specified by the vector intensity_map.

J = imnoise(I,'poisson') generates Poisson noise from the data instead of adding artificial noise to the data. See Algorithms for more information.

J = imnoise(I,'salt & pepper') adds salt and pepper noise, with default noise density 0.05. This affects approximately 5% of pixels.

example

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

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

J = imnoise(I,'speckle',var_speckle) adds multiplicative noise with variance var_speckle.

Examples

Add Noise to an Image

Read a grayscale image and display it.

I = imread('eight.tif');
imshow(I)

Add salt and pepper noise, with a noise density of 0.02, to the image. Display the result.

J = imnoise(I,'salt & pepper',0.02);
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);

Input Arguments

collapse all

Grayscale image, specified as a numeric matrix. If I has more than two dimensions, it is treated as a multidimensional intensity image and not as an RGB image.

Note

For Poisson noise, images of data type int16 are not allowed.

To add noise using a GPU, specify I as a gpuArray that contains a numeric matrix.

Data Types: single | double | int16 | uint8 | uint16

Mean of Gaussian noise, specified as a numeric scalar.

Variance of Gaussian noise, specified as a numeric scalar.

Local variance of Gaussian noise, specified as one of the following:

  • A numeric matrix of the same size as I.

  • A numeric vector the same length of intensity_map.

Intensity values that are mapped to Gaussian noise variance, specified as a numeric vector. The values are normalized to the range [0, 1].

You can plot the functional relationship between noise variance var_local and image intensity using the command plot(intensity_map,var_local).

Noise density for salt and pepper noise, specified as a numeric scalar. The noise is applied to approximately d*numel(I) pixels.

Variance of multiplicative noise, specified as a numeric scalar.

Output Arguments

collapse all

Noisy image, returned as a numeric matrix of the same data type as input image I.

If noise is added using a GPU, then J is returned as a gpuArray containing a numeric matrix.

Algorithms

  • 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 a different class, 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.

  • The Poisson distribution depends on the data type of input image I:

    • 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.

Extended Capabilities

See Also

|

Introduced before R2006a