How to add 5% percent Gaussian noise to image

2019-02-18 13:18发布

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(:)))

enter image description here

2条回答
太酷不给撩
2楼-- · 2019-02-18 13:40

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

slicer gaussian filter

查看更多
家丑人穷心不美
3楼-- · 2019-02-18 14:02

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,[])
查看更多
登录 后发表回答