Using imnoise to add gaussian noise to an image

对着背影说爱祢 提交于 2019-11-27 12:33:46

问题


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?


回答1:


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:

SNR = 10log10[var(image)/var(noise)]

For a given image and SNR=5db, the variance of the noise would be:

var(noise) = var(image)/10SNR/10 = var(image)/sqrt(10)

Now let's translate all of this into MATLAB code. To add white Gaussian noise to an image (denote it I) using the imnoise command, the syntax is:

I_noisy = imnoise(I, 'gaussian', m, v)

where m is the mean noise and v is its variance. It is also important to note that imnoise assumes that the intensities in image I 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:

%// Adjust intensities in image I to range from 0 to 1
I = I - min(I(:));
I = I / max(I(:));

%// Add noise to image
v = var(I(:)) / sqrt(10);
I_noisy = imnoise(I, 'gaussian', 0, v);

Clarification: we use var(I(:)) to treat compute the variance of all samples in image I (instead of var(I), which computes variance along columns).

Hope this helps!

Example

I = imread('eight.tif');
I = double(I);

%// Adjust intensities in image I to range from 0 to 1
I = I - min(I(:));
I = I / max(I(:));

%// Add noise to image
v = var(I(:)) / sqrt(10);
I_noisy = imnoise(I, 'gaussian', 0, v);

%// Show images
figure
subplot(1, 2, 1), imshow(I), title('Original image')
subplot(1, 2, 2), imshow(I_noisy), title('Noisy image, SNR=5db')

Here's the result:



来源:https://stackoverflow.com/questions/16008228/using-imnoise-to-add-gaussian-noise-to-an-image

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