哪一种是模拟加性高斯噪声的正确方法

Which one is the correct way of simulating addtive Gaussian noise

我有一张无噪声图像 I。我想模拟添加到图像中的加性高斯噪声(零均值和变化 vnmodel 的输出是:

Z = I + n

要模拟它,我们有两种方法:

  1. 创建高斯噪声并将其添加到图像中,
  2. 在 MATLAB 中使用 imnoise 函数。

两种方法我都用过,但结果不一样。你能确定哪一个是正确的吗?为什么它们不等价?据我所知,我认为 imnoise 是正确的。

在我的模拟中,我将噪声百分比定义为

The "percent noise" number represents the percent ratio of the standard deviation of the Gaussian noise versus the signal for whole image.

I = imread('eight.tif');
[rows cols]=size(I);
I = double(I);
I = I - min(I(:));
I = I / max(I(:));
%% Percentage ratio
noise_per=0.4; %40 percent noise
%% Add noise to image
v = (noise_per*std(I(:)))^2 %// Option #2
%% Add noise by manual way
n=normrnd(0,v,[rows cols]);
I_noise1=I+n;
%% Add noise by imnoise func.
I_noise2 = imnoise(I, 'gaussian', 0, v);

subplot(131);imshow(n,[]);title('Gaussian noise');
subplot(132);imshow(I_noise1,[]);title('Add Gaussian noise #1');
subplot(133);imshow(I_noise2,[]);title('Add Gaussian noise #2');

我把要点加粗了:

J = imnoise(I,'gaussian',M,V) adds Gaussian white noise of mean m and variance v to the image I. The default is zero mean noise with 0.01 variance. http://se.mathworks.com/help/images/ref/imnoise.html

R = normrnd(mu,sigma) generates random numbers from the normal distribution with mean parameter mu and standard deviation parameter sigma. http://se.mathworks.com/help/stats/normrnd.html

我认为这两种方法对于你的任务和任何其他方差校正后的任务应该是相当平等和同样正确的,也就是说,在

之后
I_noise2 = imnoise( I, `gaussian`, 0, v^2 ); % orr sqrt(v) depends...

除了 normrnd 标准差 作为输入而 imnoise 期望 方差(作为@mainactual 指出),还有数据类型和值范围的问题。

imnoise 文档中有注释:

Note: The mean and variance parameters for 'gaussian' noise type is always specified as if the image were of class double in the range [0, 1]. If the input image is of class uint8, the imnoise function converts the image to double, adds noise according to the specified type and parameters, and then converts the noisy image back to the same class as the input.

在输入图像已经 double 在 [0,1] 范围内的情况下,这意味着在添加噪声后将输出值剪切到 [0,1] 范围。

另外 normrnd 在这种情况下可以用对 randn.

的简单调用来替换

示例:

% input image
I = imread('eight.tif');
I = im2double(I);  % convert to double in [0,1] range

% noise mean/variance
m = 0;
v = (0.4 * std(I(:)))^2;

% normrnd
noise1 = normrnd(m, sqrt(v), size(I));
I1 = I + noise1;
I1 = max(0, min(I1, 1));  % clip to [0,1] range

% randn
noise2 = randn(size(I))*sqrt(v) + m;
I2 = I + noise2;
I2 = max(0, min(I2, 1));  % clip to [0,1] range

% imnoise
I3 = imnoise(I, 'gaussian', m, v);

% compare
subplot(221), imshow(I),  title('original')
subplot(222), imshow(I1), title('normrnd')
subplot(223), imshow(I2), title('randn')
subplot(224), imshow(I3), title('imnoise')