Arun
Arun

Reputation: 75

Gaussian noise,MATLAB

The objective is to add additive gaussian noise of zero mean and variance of 400 to an image.

For example, if i wanted to add additive gaussian noise of zero mean and variance 0.5, i can use one of the two following methods:

1) The imnoise command in Matlab:

                 Noisyimg=imnoise(I,'gaussian',0,0.5) 

where I is the image to which the noise is being added and Noisyimg is the noisy image.

2) Create a matrix of random numbers taken from the normal distribution with the mean and standard deviation specified, by using the randn command.

       noisemat= a*randn(size(I))+ b;  where a=standard deviation and b=mean
       Noisyimg=noisemat+I;                   

Thus,for zero mean and a variance of 0.5,

      noisemat=sqrt(0.5)*randn(size(I))+0; 

since standard deviation is square root of variance.

But, when i try to apply the above two methods to obtain a noisy image with a additive gaussian noise of zero mean and a variance of 400, am ending up with indiscernible images. For eg, using method two,

      noisemat=sqrt(400)*randn(size(I))+0; 
      Noisyimg=noisemat+I;

The resultant noisy image is nowhere near the actual noisy image that i should be obtaining.This, am aware, because i have the picture of the actual noisy output that i should be obtaining. Am i making any mistake in implementing the commands or am i missing some critical points. I have attached the original image to which i was trying to add the gaussian noise and the image that was obtained after the addition of noise.
original image(I) Noisyimg

Any help would be greatly appreciated!!

Upvotes: 0

Views: 3156

Answers (2)

Arun
Arun

Reputation: 75

So,i finally got the result that i was looking far. Hope it helps:)

The key lies with the fact that the variance of the gaussian noise to be added must also be scaled relative to the range of the image that it is being added to. The original image was of type uint8. Initially, it was converted to type double with the range [0 1].

      I=im2double(imread('chipset1.tif'));
      figure;imshow(I);title('original image');

Now, the problem arose when trying to add a gaussian noise of 400. Initially, i was trying it to add as following:

       Noisyimg=imnoise(I,'gaussian',0,400) 

But, it turns out that the variance has to be scaled before it can be used.

It is scaled as follows:

variance = (standard deviation)^2/(255)^2

Thus, for the variance of 400, standard deviation is 20 and thus, the scaling :

          var=(20)^2/(255)^2;%(since the image was of uint8 type)

          Noisyimg=imnoise(I,'gaussian',0,var)
          figure;imshow(Noisyimg);

Note the change in the variance parameter of the imnoise. This relative scaling ensures that the output noisy image is correct and within range.

The same can be done with method two also:

          noisemat=(sqrt(var))*randn(size(I))+0;
          Noisyimg=noisemat+I;
          figure;imshow(Noisyimg);

As a sidenote, this problem of adding a gaussian noise of variance 400 to a grayscale image is available and can be referenced in the Digital Image Processing Textbook by Rafael C.Gonzalez and Richard E.Woods, 3rd Edition, Chapter five, Example 5.2. Note that the original images in that example was used here too as well as in the question that was posted by me in which i did not get the desired output.

Upvotes: 0

aarbelle
aarbelle

Reputation: 1033

There could be two issues: 1. The dynamic range or the original image. if it is [0 1] then it only makes sense that adding values of a normal distribution with variance 400 will result in mostly noise. 2. if the images are uint8 or uint 16, adding double could have undesired affects. try converting the image to double before adding the noise:

 Noisyimg=noisemat+double(I);

Upvotes: 1

Related Questions