
%The first parameter is the degraded image. The second parameter
%is the the blurring function and the third is an indication of
%the amount of noise added to the image

function[D]=wiener_filt(i,h,noise)

YSIZE=size(i,1);
XSIZE=size(i,2);
SIZEMAX=max([XSIZE YSIZE]);
     
H=fft2(h,2*SIZEMAX,2*SIZEMAX);
I=fft2(i,2*SIZEMAX,2*SIZEMAX);
G=conj(H)./((abs(H).^2) + noise);
Ifilt=G.*I;
ifilt=ifft2(Ifilt);

D=abs(ifilt(1:YSIZE,1:XSIZE));

