Saturday, January 14, 2012

Denoise it!!


This algorithm may not be very competent but it still gave appreciable results as I made them on my own without any background on image processing. What I have done is, First found out the irregular value in 3X3 matrix, which could possibly be noise. By irregular value I mean, the value which is 20 (this factor can be varied to study its effect) units farther from its neighborhood. Then we substitute the mean of regular values in the matrix to the irregular value.

Below is the MATLAB code for the same and in the end the result. A 3 to 4dB gain in PSNR is observed. Cheers!!



a=imread('plane.jpg');
sze=1200;
a=a(1:sze,1:sze,:);
b=imnoise(a,'gaussian');
c=b;
d=a;


for rgb=1:3
  rgb                       % for R, G and B matrices
  for i=2:sze-1
    i;
    for j=2:sze-1
      z=0;
      arr=zeros(3,3,3);
      for l=1:3
        for n=1:3     % if statement for neighborhood
          pqr=0;      % limit
 if((c(i-2+l,j-2+n,rgb))-c(i,j,rgb)<20 && (c(i-2+l,j-2+n,rgb))-c(i,j,rgb)>-20)
        z=z+1;
        pqr=1;
        arr(l,n,rgb)=c(i-2+l,j-2+n,rgb);   
        end
      end
    end
    c(i,j,rgb)=round((9/z)*(mean(mean(arr(1:3,1:3,rgb)))));
    end
 end 
end
imwrite(b,'3noised.png');
imwrite(a,'3original.png');
imwrite(c,'3noise+myalgo.png');

error_diff = c - b;          
decibels=20*log10(255/(sqrt(mean(mean(error_diff.^2)))));
disp(sprintf('PSNR after reduction= +%5.2f dB',decibels)
error_diff = b - a;
decibels=20*log10(255/(sqrt(mean(mean(error_diff.^2)))));
disp(sprintf('PSNR of noised image = +%5.2f dB',decibels))
original Image
Noised Image
Noised image, denoised!


Quater image denoised


removed noise!!

No comments:

Post a Comment