clear;load ????.mat;lambda=1;C=1;sigma=???;H(25,25)=0;
%For clown.mat:sigma=0.2;(clown.mat pixel bounded by 1)
%For letters.mat,xray.mat and mri.mat:sigma=100; (pixels bounded by 255)
for I=1:25;for J=1:25;if((I-13)*(I-13)+(J-13)*(J-13)<145);H(I,J)=1;end;end;end;\%PSF
Y=conv2(X,H);M=size(Y,1);Y=Y+sigma*randn(M,M);%Blur with PSF and add noise
figure,imagesc(X),colormap(gray),title('ORIGINAL IMAGE'),axis off
figure,imagesc(Y),colormap(gray),title('NOISY BLURRED IMAGE'),axis off
%Next 2 lines: power spectral densities:
VH=ones(M,1)*[1:M/2];VH=[VH fliplr(VH)];VV=[1:M/2]'*ones(1,M);VV=[VV;flipud(VV)];
VVV=(VV.*VV+VH.*VH)*4*pi*pi/M/M;
%For mri.mat, need 1/(f*f*f*f) not 1/(f*f), so add this line: VVV=VVV.*VVV;
FH=fft2(H,M,M);FY=fft2(Y,M,M);
%Next 2 lines:Wiener filters. Deterministic, then stochastic.
FW1=FY.*conj(FH)./(abs(FH).*abs(FH)+lambda*lambda);W1=real(ifft2(FW1));
FW2=FY.*conj(FH)./(abs(FH).*abs(FH)+VVV*C*lambda*lambda);W2=real(ifft2(FW2));
figure,imagesc(W1),colormap(gray),title('DETERMINISTIC WIENER'),axis off
figure,imagesc(W2),colormap(gray),title('STOCHASTIC WIENER'),axis off
