Functions > Image Processing > Image Manipulation > Example: Addition and Measurement of Noise
  
Example: Addition and Measurement of Noise
addnoise
Use this function to add or subtract noise of magnitude n (where n is any real number) to each element of M with probability p/2.
For information on using this example, refer to About Image Processing Examples.
1. Define the value for all the elements of a 5 × 5 matrix to be 127.
Click to copy this expression
Click to copy this expression
Click to copy this expression
2. Add noise to matrix M so that +/-50 is added to half of the elements of M.
Click to copy this expression
Click to copy this expression
3. Read in an image and apply addnoise to it.
Click to copy this expression
Click to copy this expression
Click to copy this expression
(camera.bmp)
(noisy_camera.bmp)
The function addnoise clips the resulting pixel values to the 0–255 range.
4. Compare the difference between the histograms of the two images to view the effect of the noise mathematically.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
The large spikes of difference at 0 and 255 illustrate the clipping performed by the addnoise function.
Adding Noise Using Other Methods
You can generate other types of noise by constructing a mathematical expression.
1. To generate Gaussian noise, use the following expression:
Click to copy this expression
gnoise is not a built-in function. A is the mean value of the noise and σ is the standard deviation.
Unlike the addnoise function, the Gaussian method does not clip the resulting pixel values to the 0–255 range.
2. Use gnoise to generate a noise matrix.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
3. Plot a histogram of the noise.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
The histogram shows that most of the signal values fall in the first 30 histogram bins.
4. Insert the new image M2 which is the original image plus the noise.
Click to copy this expression
Click to copy this expression
(noisy_camera2.bmp)