I=imread('lena.bmp');
I=im2double(I);
figure(1);
subplot(2,2,1);
imshow(I);
title('original image');
I=im2double(I);
%原始的len和theta
len=15;
theta=30;
%增加运动模糊
PSF=fspecial('motion',len,theta);
img1=imfilter(I,PSF,'circular');
%增加高斯模糊
PSF2= fspecial('gaussian',6,5);
I1 = imfilter(img1,PSF2,'replicate');
subplot(2,2,2);
imshow(I1);
title('motion&gauss blurred image');
I2=fft2(I1);
I3=abs(I2);
I4=abs((log10(1+I3))).^2;
I5=ifft2(I4);
%figure
%plot(I4);
I5=fftshift(I5);
minmum=min(I5(:));
I6=abs(I5);
R=[];
C=[];
[R,C]=find(I5==minmum);
[rows,cols]=size(I5);
row1s=rows;
col1s=cols;
m=0.5;
if(length(R)==1&&length(C)==1)
R(2)=0;
C(2)=0;
row1s=0;
col1s=0;
m=0;
end
%估计出来的len和theta
Retrive_len=(1-m)*sqrt((R(1)-rows/2)^2+(C(1)-cols/2)^2 )+m*sqrt((R(2)-row1s/2)^2+(C(2)-col1s/2)^2 );
Retrive_theta=(1-m)*acot(abs(C(1)-cols/2-1)/abs(R(1)-rows/2-1))*180/pi+m*acot(abs(C(1)-cols/2-1)/abs(R(1)-rows/2-1))*180/pi;
ipsf=fspecial('motion',Retrive_len,Retrive_theta);
I7=deconvlucy(I1,ipsf,10);
subplot(2,2,3);
imshow(I7);
title('Demotionblurred image');
%去高斯模糊
INITPSF=ones(size(PSF2));
[I8 P] = deconvblind(I7,INITPSF,12);
subplot(2,2,4);
imshow(I8);
title('final(or degaussblurred) image');
评论0