使用杂讯为影像增加高斯杂讯 [英] Using imnoise to add gaussian noise to an image

查看:100
本文介绍了使用杂讯为影像增加高斯杂讯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用imnoise向图像中添加SNR = 5dB的高斯白噪声?

How do I add white Gaussian noise with SNR=5dB to an image using imnoise?

我知道语法是:

J = imnoise(I,type,parameters)

和:

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

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

如何使用此SNR值向图像添加噪点?

How do I use this SNR value to add noise to the image?

推荐答案

让我们首先了解SNR与噪声的关系.您的错误图像是原始图像和噪声图像之间的差异,这意味着错误图像是噪声本身.因此,SNR实际上是:

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

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

对于给定图像和SNR = 5db,噪声的方差为:

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

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

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

现在让我们将所有这些翻译成MATLAB代码.要使用imnoise命令向图像添加高斯白噪声(将其表示为I),语法为:

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)

其中,m是平均噪声,v是其方差.同样重要的是要注意,imnoise假定图像I中的强度范围是0到1.

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.

在我们的例子中,我们将添加零均值噪声,其方差为v = var(I(:))/sqrt(10).完整的代码是:

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);

说明:我们使用var(I(:))来处理计算图像I中所有样本的方差(而不是var(I),它会计算沿列的方差).

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).

希望这会有所帮助!

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')

结果如下:

这篇关于使用杂讯为影像增加高斯杂讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆