code for white gaussian noise for image

Hi, I have a Lena image with size 512X512 and I want to add white Gaussian noise with mean=0 and variance=10 to this image. do you have any code that do this for me? thanks in advance.

Respuestas (2)

Namwon Kim
Namwon Kim el 13 de En. de 2020
%% Code for White Gaussian Noise for Image
% noisy = (sqrt((Standard Deviation)^2)*randn(size(Lena_image))+mean + Lena_image
% Where (Standard Deviation)^2 is a variance, and
% [512, 512] = size(Lena_image)
Therefore,
load Lena % Input: Lena image
noisy = (sqrt(10)*randn(512,512))+0 + Lena;
Walter Roberson
Walter Roberson el 26 de Mzo. de 2018

0 votos

https://www.mathworks.com/help/images/ref/imnoise.html

10 comentarios

nadia
nadia el 26 de Mzo. de 2018
I need additive white Gaussian noise(AWGN), Do this function produce this type of noise for me?
Walter Roberson
Walter Roberson el 26 de Mzo. de 2018
https://www.mathworks.com/matlabcentral/answers/24282-image-processing-noise
nadia
nadia el 27 de Mzo. de 2018
can you please guide completely me . I want to add additive white Gaussian noise to Lena with variance 10. I am a beginner. do you have any code? thanks

You just follow the directions. The only "trick/catch" is that the variance assumes the image is in the range 0-1 so you can either use im2double() or you can divide your variance by 255^2.

grayImage = imread('lena.jpg');
subplot(1, 2, 1);
imshow(grayImage);
title('Original Image', 'FontSize', 30);
noisyImage = imnoise(grayImage, 'gaussian', 0, 10/255^2);
subplot(1, 2, 2);
imshow(noisyImage);
title('Noisy Image', 'FontSize', 30);
diffImage = double(grayImage) - double(noisyImage);
variance = var(diffImage(:))  % Check that it's around 10
nadia
nadia el 3 de Abr. de 2018
thank you very much for your answer. if my image has values between [0 1], so, the above code is correct for me or not?
Image Analyst
Image Analyst el 3 de Abr. de 2018
No. You'd use 10 instead of 10/255^2 because your max value is 1, not 255. You will have an extremely noisy image. So much so that you probably won't be able to see your underlying original image.
nadia
nadia el 3 de Abr. de 2018
Editada: nadia el 3 de Abr. de 2018
ok, if I want to change this variance (var=10) so that it suitable for double images, how can I change it? I have a watermark program and I want to attack it with AWGN but my images are double. So, if I want to have a noise with this variance but suitable for double images, how can I change the variance?
Walter Roberson
Walter Roberson el 3 de Abr. de 2018
10/255^2 for that case.
nadia
nadia el 3 de Abr. de 2018
are you sure? when I consider your solution with my double images(values are between [0 1]) the variance of difference of original image and noisy image is not about 10?
Walter Roberson
Walter Roberson el 3 de Abr. de 2018
A variance of 10 is not "suitable or double images" (that are in the range 0 to 1). Especially not if you think of the range 0 to 1 as being upper and lower bounds on representation and do not permit (say) -7 to +7 to be stored there to give room for a clear variance of 10. If you clamp at 0 to 1 then you can never get a variance of 10.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 26 de Mzo. de 2018

Respondida:

el 13 de En. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by