3
votes

Lets consider an image of 3x3 pixels with the values shown below now if I apply imnoise function(MATLAB image processing toolbox) with Gaussian noise of 0 mean and 0 standard deviation I am getting all ones

original matrix with double precession data type

16    32     64                      
96    128    192                    
224   100    50  

final matrix after applying Gaussian noise with 0 mean and 0 standard deviation

1 1 1
1 1 1
1 1 1

As far I know 0 mean with 0 standard deviation is same thing as 0% of noise added to the original image I wanted to know how imnoise function in MATLAB works

1
Does this error only occur with mean and standard deviation set to zero? Have you tried using the default values(mean = 0 and standard deviation 0.01)?Mailerdaimon

1 Answers

0
votes

imnoise assumes for a Gaussian that the image is a double with range [0, 1].

Have a look in the code at how the input images are dealt with. If you type edit imnoise.m at your command line you should be able to see this - it happens under the ParseInputs function within imnoise (line 188 onwards in my version).

If the input image is not a double → convert to double using im2double (which automatically scales), store input class (so the output can be converted back at the end).

If the input image is a double → no conversion, just clip to [0 1] using a = max(min(a,1),0). Hence your example, with all values above 1, gets simply clipped to a matrix of ones.

This (with your example data) will do what you expected:

I2 = imnoise(uint8(I),'gaussian',0,0);

More generally speaking - this is not the only function in the Image Processing Toolbox that returns unexpected results if your doubles do not have the [0, 1] range. If you want to work in double format, im2double rescales automatically from other data types, or you can rescale by hand.