Add noise (Gaussian, etc.) to an image
imn = imnoise(im, type [,parameters])
im
.imnoise(im, type [, parameters])
adds a type of noise
to the intensity image im
.
Optionally, you can control the noise parameters starting at the 3rd. Argument to imnoise.
Here are examples of noise types and their parameters:
imn = imnoise(im, 'salt & pepper', d)
adds drop-out noise,
where d
is the noise density (probability of swapping a pixel). (default: d=0.05).
imn = imnoise(im, 'gaussian', m, v)
adds Gaussian additive noise of mean m and variance v. (default: m=0 and v=0.01)
im = imnoise(im, 'localvar', V)
additive zero-mean Gaussian
noise where the variance at im(i,j) is V(i,j).
imn = imnoise(im,'localvar', intensity, V)
additive zero-mean Gaussian noise,
and the local variance of the noise, var,
is a function of the image intensity values in im
.
The variance is matrix( interp1(intensity(:),V(:),im(:)), size(im) )
imn = imnoise(im,'speckle',v)
adds multiplicative noise,
using imn = im + noise*im
,
where noise is uniformly distributed with mean 0 and variance v. (default: v=0.04)
The mean and variance parameters are specified as if image intensities went from 0 to 1. By default, we consider that "1" corresponds to the maximum intensity value of the image. If you want to change this for 'gaussian' and 'speckle', pass an extra parameter at the end of the argument list. For instance, your image may have maximum intensity 180 even though the grayscale range is 0-1:
J = imnoise(I,'gaussian', m, v, val)
J = imnoise(I,'speckle', v, val)
xset('auto clear', 'on'); A = gray_imread(SIPDIR + 'images/gra.jpg'); imshow(A); N = imnoise(A,'salt & pepper'); imshow(N,[]); N = imnoise(A,'salt & pepper',0.3); imshow(N,[]); // Replace pixel by independent random value: N = imnoise(A,'salt & pepper',0.3,0); imshow(N,[]); // Replace pixel by *dependent* random value: N = imnoise(A,'speckle'); imshow(N,[]); xset('auto clear', 'off'); |
'poisson' noise is not yet implemented.
"Noise Generation", The Hypermedia Image Processing Reference (HIPR), R. Fisher, S. Perkins, A. Walker and E. Wolfart, University of Edinburgh:
http://sip.sf.net