How to add 5% percent Gaussian noise to image

不问归期 提交于 2019-12-01 06:37: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 :



来源:https://stackoverflow.com/questions/31834803/how-to-add-5-percent-gaussian-noise-to-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!