# imnoise gaussian variance vs normal variance?

5 views (last 30 days)
Zhouyang Xu on 14 Mar 2021
Commented: Zhouyang Xu on 17 Mar 2021
Dear MATLAB community,
I'm currently trying to understand the imnoise function, if I create an image of just ones and add gaussian noise of 1e^-4 to it, the variance of teh output image is not any where close to that value, it seems to have a corrolation of 0.34 times the gaussian variance in imnoise.
img = ones(500);
img = imnoise(img,"gaussian",0,1e-4);
var(img(:))
Would anyone be kind enough to explain this to me?
Thank you very much! Really appreciate your support!

Uday Pradhan on 17 Mar 2021
Hi,
So the formula for adding Gaussian noise to the image by "imnoise" is given by:
output = input + sqrt(v)*randn(size(input)) + mu; %v is the provided variance and mu the mean
output = max(0,min(output,1)); %truncating the output to the range [0,1]
Now, in the first line, we are drawing 500*500 random values from a normal distribution with a mean of "mu" and variance "v". The mean and variance of the drawn sample will not exactly be "mu" and "v" because they are calculated from a sampling of the distribution. Also, the variance of the output is affected by the truncation step.
You can check the variance of the added noise multiple times to observe how it varies from the user - input variance to imnoise, by using the above formula instead.
Zhouyang Xu on 17 Mar 2021
Thank you very much, that is very helpful