Variance and mean isn't calculated properly

1 visualización (últimos 30 días)
Sajid Khan
Sajid Khan el 23 de Abr. de 2013
Hello Everyone,
I am trying to calculate variance and mean of gaussian noise by adding it to uniform image using imnoise function as
image = rgb2gray(im2double(imread('flat_400.jpg')));
image(:,:) = 0.5;
noisy_image = imnoise(image,'gaussian',0,0.8);
and then am trying to calculate mean and variance using
mean_image = sum(sum(noisy_image))/(size(noisy_image,1)*size(noisy_image,2))
variance = sum(sum((noisy_image - mean_image).^2))/((size(noisy_image,1)*size(noisy_image,2)) - 1)
but the variance and mean are far from the added noise. Can anyone please tell me what's the reason of it?

Respuestas (2)

Iman Ansari
Iman Ansari el 23 de Abr. de 2013
Editada: Iman Ansari el 23 de Abr. de 2013
Hi. Your noise is very large and the output image must be between 0 and 1, so the values greater than 1 became 1 and values less than 0 became zero.
Gaussian noise can be defined:
Mean=0;
Variance=0.8;
Noise=Mean+sqrt(Variance).*randn([256 256]);
mean(Noise(:))
var(Noise(:))

Sajid Khan
Sajid Khan el 23 de Abr. de 2013
Well even if I add noise with variance of 0.2 or 0.3, the code provided by me doesn't provide the correct variance and mean.
  2 comentarios
Jan
Jan el 23 de Abr. de 2013
Editada: Jan el 23 de Abr. de 2013
Please post comments in the comment section. Otherwise the connection top the realted message will get lost soon.
Even with a variance of 0.2 the saturation at 0.0 and 1.0 will matter. To narrow the problem down, please try this:
mean_image = mean(noisy_image(:));
var_image = var(noisy_image(:));
Iman Ansari
Iman Ansari el 23 de Abr. de 2013
Editada: Iman Ansari el 23 de Abr. de 2013
imnoise default variance is 0.01. For this value, the output noise would be became between
[mean-3*sqrt(0.01) mean-3*sqrt(0.01)]
or
[mean-0.3 mean+0.3].
but for 0.2 ====> [mean-1.3416 mean+1.3416]

Iniciar sesión para comentar.

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by