Search code examples
matlabimage-processinggammagamma-distribution

Creating a Noisy Image and Removing Noise Using randg Gamma Law in Matlab?


I want to add Multiplicative Gamma Noise to a image using "randg" function in Matlab and remove that noise. We have to keep in mind that the noise should have mean 1 and level 4. It should follow Gamma law ( with Gamma Probability Distribution Function). The image after addition of noise becomes

f=u*v; where f=noisy image, u=original image, v=noisy image.

The gamma law is: gv(v)=L^L/(Γ(L)) v^(L-1) exp(-Lv) 1_(v≥0)

where L is the noise level and v is the noise.

Here is the code that I've tried:

  img = imread('lena.png');
  img1 = img./ 255;
  imgdob = double(img1);
  noisyimg = imgdob + randg(1,size(imgdob)) .* 0.4;
  noisyimg(noisyimg< 0) = 0;
  noisyimg(noisyimg> 1) = 1;
  figure,imshow(img);
  figure,imshow(noisyimg);
  imwrite(img, 'lenaOriginal.jpg', 'Quality', 100);
  imwrite(noisyimg, 'lenaNoisy.jpg', 'Quality', 100);

But I could not get the expected result. Please suggest me a way.


Solution

  • 0.4 is VERY destructive. So destructive that it'll force it to threshold values to 0 or 1. You should try 0.2 instead. Also if you're looking for a normal distribution noise, you should use randn instead of randg. The following code is here.

    Note that I don't have sexylena.png on my computer so I must use bag.png instead.

    imgdob = im2double(imread('bag.png'));
    noisyimg = imgdob + randg(1,size(imgdob)) .* 0.15;
    noisyimg(noisyimg< 0) = 0;
    noisyimg(noisyimg> 1) = 1;
    figure,imshow(imgdob);
    figure,imshow(noisyimg);
    imwrite(imgdob, 'lenaOriginal.jpg', 'Quality', 100);
    imwrite(noisyimg, 'lenaNoisy.jpg', 'Quality', 100);
    

    These are the results. Normal image.

    normal img

    Noisy image using randg.

    noisy img randg

    If you wish to use randn instead, you can use this line of code instead.

    noisyimg = imgdob + randn(size(imgdob)) .* 0.2;
    

    Noisy image using randn.

    noisy img randn

    As for noise reduction, please refer to Matlab's tutorial for noise removal.