cd D:\Courses\Image\Website
f=imread('chessboard.jpg');
f=double(f);
figure(9)
imshow(f);
PSF = fspecial('motion', 9, 45);
gb= imfilter(f, PSF, 'circular');
SDD=0.4;
noise=imnoise(zeros(size(f)), 'gaussian', 0, SDD^2);
g=gb+noise;
figure(10)
imshow(g, []);

fr1=deconvwnr(g,PSF);
figure(1)
imshow(fr1,[]);

Sn=abs(fft2(noise)).^2;                      % noise power spectrum
nA=sum(Sn(:))/prod(size(noise));   % noise average power
Sf=abs(fft2(f)).^2;                                 % image power spectrum
fA=sum(Sf(:))/prod(size(f));              % image average power
R=nA/fA;
fr2=deconvwnr(g, PSF, R);
figure(2)
imshow(fr2,[])

NCORR = fftshift(real(ifft2(Sn)));
ICORR = fftshift(real(ifft2(Sf)));
fr3 = deconvwnr(g, PSF, NCORR, ICORR);
figure(3)
imshow(fr3,[])

%    constrained least square

fr4=deconvreg(g, PSF, 4);
figure(4)
imshow(fr4,[]);
fr5=deconvreg(g, PSF, 0.4, [1.e-7 1.e7]);
figure(5)
imshow(fr5,[])

% Lucy Richardson

%fr6=deconvlucy(g, PSF, NUMIT, DAMPAR, WEIGHT)

% blind deconvolution

%fr7=deconvblind(g, INITPSF, NUMIT, DAMPAR, WEIGHT)
SDD
INITPSF = ones(size(PSF));
ITER = 5;

DAMPAR=10*SDD
LIM=ceil(size(PSF,1)/2);
WEIGHT=zeros(size(g));
WEIGHT(LIM+1:end-LIM,LIM+1:end-LIM) = 1;
[fr7,PSFe]=deconvblind(g, INITPSF, ITER, DAMPAR,WEIGHT);
figure(7)
imshow(fr7,[])