Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
795 views
in Technique[技术] by (71.8m points)

matlab - How to add 5% percent Gaussian noise to image

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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,[])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...