How do I add white Gaussian noise with SNR=5dB to an image using imnoise
?
I know that the syntax is:
J = imnoise(I,type,parameters)
and:
SNR = 10log10[var(image)/var(error image)]
How do I use this SNR value to add noise to the image?
How do I add white Gaussian noise with SNR=5dB to an image using imnoise
?
I know that the syntax is:
J = imnoise(I,type,parameters)
and:
SNR = 10log10[var(image)/var(error image)]
How do I use this SNR value to add noise to the image?
Let's start by seeing how the SNR relates to the noise. Your error image is the difference between the original image and the noisy image, meaning that the error image is the noise itself. Therefore, the SNR is actually:
For a given image and SNR=5db, the variance of the noise would be:
Now let's translate all of this into MATLAB code. To add white Gaussian noise to an image (denote it
I
) using theimnoise
command, the syntax is:where
m
is the mean noise andv
is its variance. It is also important to note thatimnoise
assumes that the intensities in imageI
range from 0 to 1.In our case, we'll add zero-mean noise and its variance is
v = var(I(:))/sqrt(10)
. The complete code is:Clarification: we use
var(I(:))
to treat compute the variance of all samples in imageI
(instead ofvar(I)
, which computes variance along columns).Hope this helps!
Example
Here's the result: