matlab图像去散焦,matlab为图像加运动模糊和散焦模糊

运动模糊

I = imread('Fig0525(a)(aerial_view_no_turb).tif');

figure,subplot(1,2,1);imshow(I);title('原图像');

%T = rgb2gray(M);figure;imshow(I);

PSF = fspecial('motion',20,15);

J = imfilter(I,PSF,'conv','circular');

subplot(1,2,2);imshow(J);title('模糊运动的图像');

imwrite(J, '55.tif');

'motion'motion filter 为运动模糊算子,有两个参数,表示摄像物体逆时针方向以theta角度运动了len个像素,len的默认值为9,theta的默认值为0; H = FSPECIAL('motion',LEN,THETA) returns a filter to approximate, onceconvolved with an image, the linear motion of a camera by LEN pixels, with an angle of THETA degrees in a counter-clockwise direction. Thefilter becomes a vector for horizontal and vertical motions. Thedefault LEN is 9, the default THETA is 0, which corresponds to ahorizontal motion of 9 pixels.

散焦模糊

'disk' circular averaging filter 为圆形区域均值滤波,参数为radius代表区域半径,默认值为5. H = FSPECIAL('disk',RADIUS) returns a circular averaging filter(pillbox) within the square matrix of side 2*RADIUS+1.The default RADIUS is 5.

clear clc %'计算中......' I=imread('Lena256.bmp'); r=10;%散焦半径r PSF=fspecial('disk',r);   %得到点扩散函数 I1=imfilter(I,PSF,'symmetric','conv');  %实现散焦模糊

%利用拉普拉斯算子对散焦模糊图像进行二阶微分 I1=double(I1); h=[1 1 1;1 -8 1;1 1 1]; I2=filter2(h,I1); %对微分图I2进行自相关计算 R=xcorr2(I2); R=R/max(R(:)); figure,surfc(R);