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;
No comments:
Post a Comment