I have a noise-free image I
. I want to simulate the additive Gaussian noise (zero mean, and variation v
) n
added to the image. The output of the model is:
Z = I + n
To simulate it, we have two ways:
- create a gaussian noise and add it to image,
- use
imnoise
function in MATLAB.
I used both ways, but they gave different results. Could you determine which one is correct? Why aren't they equivalent? In my knowledge, I think imnoise
is correct one.
In my simulation, I use a definition of noise percent as
The "percent noise" number represents the percent ratio of the standard deviation of the Gaussian noise versus the signal for whole image.
I = imread('eight.tif');
[rows cols]=size(I);
I = double(I);
I = I - min(I(:));
I = I / max(I(:));
%% Percentage ratio
noise_per=0.4; %40 percent noise
%% Add noise to image
v = (noise_per*std(I(:)))^2 %// Option #2
%% Add noise by manual way
n=normrnd(0,v,[rows cols]);
I_noise1=I+n;
%% Add noise by imnoise func.
I_noise2 = imnoise(I, 'gaussian', 0, v);
subplot(131);imshow(n,[]);title('Gaussian noise');
subplot(132);imshow(I_noise1,[]);title('Add Gaussian noise #1');
subplot(133);imshow(I_noise2,[]);title('Add Gaussian noise #2');