如何使用matlab函数添加特定数量的高斯噪音或椒盐噪音?

May*_*ari 1 matlab image-processing noise

对于其他人来说这个问题可能非常愚蠢,但对我来说这是非常困难的.

您好,我是MATLAB的初学者,我最近正在阅读一篇论文,其中我们必须以下列方式在图像中添加噪声.

高斯噪声=> sigma = 10

盐和胡椒噪音=> p = 20%sp

我知道用于添加噪声的MATLAB函数,我们使用imnoise()函数.

noise_image = imnoise(input_image, 'salt & pepper', gaus_val)
Run Code Online (Sandbox Code Playgroud)

会添加盐和胡椒的噪音和

noise_image = imnoise(input_image, 'gaussian', 0 , salt_pepper_val);
Run Code Online (Sandbox Code Playgroud)

将添加ZERO-MEAN高斯方差噪声salt_pepper_val.

现在我的问题是使用imnoise()函数如何添加以下噪声量.换句话说,对于gaus_val和salt_pepper_val的值,我将得到量sigma = 10%,20%,.....的高斯噪声和20%的盐和胡椒噪声,30%....... ........

高斯噪声=> sigma = 10

盐和胡椒噪音=> p = 20%sp

all*_*ije 9

使用不同的参数是因为两种类型的噪声的特征不同:

  1. gaussian noise corrupts the whole image, and if it's white (i.e. no spatial covariance) with zero mean (on average it doesn't brighten or darken the image) then it is completely defined by the noise amplitude sigma. if you read the documentation www.mathworks.com/help/images/ref/imnoise.html then you see that you can specify both the mean and the variance (sigma*sigma -- if sigma = 10 then variance = 100). you can then add noise with sigma 10 using:

    >> noise_image = imnoise(input_image, 'gaussian', 0 , 100);
    
    Run Code Online (Sandbox Code Playgroud)
  2. salt and pepper noise are white(salt) and black(pepper) spots in an image, i.e. they don't affect every pixel. sp is the percentage of an image that is corrupted (default 5% or 0.05), so sp = 20% = 0.2 means that 1 in 5 pixels are corrupted:

    >> noise_image = imnoise(input_image, 'salt & pepper', 0.2);
    
    Run Code Online (Sandbox Code Playgroud)

exactly as described on the help page.

EDIT: please beware that imnoise() is used for images with intensities between 0 and 1, and that values outside the range [0,1] are clipped -- the variance may not be the one you specify.

you can also easily do the same without using imnoise:

(1) load an image as [0,1] greyscale:

  >> input_image = mean(imread('peppers.png'),3)/256;
Run Code Online (Sandbox Code Playgroud)

(2) add gaussian noise of 0.1*the image's sigma:

  >> image2 = randn(size(input_image)); 
  >> image2 = input_image+image2*0.1*std(input_image(:))/std(image2(:)); 
Run Code Online (Sandbox Code Playgroud)

(3) add s&p noise in 20% of pixels:

  >> image3 = input_image; 
  >> li=randperm(length(image3(:))); 
  >> image3(li(1:(end/5)))=1; 
  >> image3(li(1:(end/10)))=0; 
Run Code Online (Sandbox Code Playgroud)

(4) show side by side:

  >> imagesc([input_image image2 image3])
Run Code Online (Sandbox Code Playgroud)