%Question No: 7
%Write a MATLAB program which restores a degraded image using direct
%inverse filtering.

function directinv(x)
f=imread(x);
f=im2double(f);
[r c]=size(f);
sig=10;
F=fft2(f);
H=gaussfilt(r,c,10);
G=F.*H;
g=real(ifft2(G));
figure,imshow(f),title('Original Image');
figure,imshow(g),title('Degraded Image');
R=G./H;
r=real(ifft2(R));
figure,imshow(r),title('Reconstructed Image');
end
function H=gaussfilt(r,c,sig)
u=0:(r-1);
v=0:(c-1);
id=find(u>r/2);
u(id)=u(id)-r;
id=find(v>c/2);
v(id)=v(id)-c;
[V,U]=meshgrid(v,u);
D=sqrt(U.^2+V.^2);
H=exp(-(D.^2)./(2*(sig^2)));
end
