Different parameters are used because the two types of noise are characterised differently:
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);
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);
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;
(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(:));
(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;
(4) show side by side:
>> imagesc([input_image image2 image3])