How to add 5% percent Gaussian noise to image

2019-02-18 13:36发布

问题:

let define that:

The "percent noise" number represents the percent ratio of the standard deviation of the white Gaussian noise versus the signal for whole image.

Assume I have a brain image, I want to add 5% Gaussian noise to whole image (tissues) by Matlab code:

I=imread('brain91.png'); I=rgb2gray(I);I=double(I);
I = I - min(I(:));
I = I / max(I(:));

%// Add noise to image
v = 0.05*var(I(:));
I_noisy = imnoise(I, 'gaussian', 0, v);
I_noisy=255.*I_noisy;
subplot(121);imshow(I,[]);subplot(122);imshow(I_noisy,[])

The figure show original image (left side) and noise image in right side. Do you think that my implementation is correct for above definition? - (about 5% Gaussian noise by set v = 0.05*var(I(:)))

回答1:

Both Ander Biguri and dasdingonesin have correct assertions. Your code is certainly adding Gaussian noise to the image properly, but make sure you account for the actual variance by squaring the 0.05 in your var calculation.

Alternatively, you can use std instead of var and square the entire calculation to get the same thing:

I=imread('brain91.png'); I=rgb2gray(I);I=double(I);
I = I - min(I(:));
I = I / max(I(:));

%// Add noise to image
%v = (0.05^2)*var(I(:)); %// Option #1
v = (0.05*std(I(:)))^2; %// Option #2
I_noisy = imnoise(I, 'gaussian', 0, v);
I_noisy=255.*I_noisy;
subplot(121);imshow(I,[]);subplot(122);imshow(I_noisy,[])


回答2:

Your code looks correct. I have used slicer packages for adding or removing noise. You can try to compare your results with it :