運動模糊
I = imread(‘5.jpg');
>> PSF = fspecial('motion',20,15);
J = imfilter(I,PSF,'conv','circular');
figure(2),imshow(J);
imwrite(J, ’55.jpg', 'jpg');
'motion'motion filter
為運動模糊算子,有兩個參數,表示攝像物體逆時針方向以theta角度運動了len個像素,len的預設值為9,theta的預設值為0;
H = FSPECIAL('motion',LEN,THETA) returns a filter to approximate, once convolved with an image, the linear motion of a camera by LEN pixels,
with an angle of THETA degrees in a counter-clockwise direction. The filter becomes a vector for horizontal and vertical motions.
The default LEN is 9, the default THETA is 0, which corresponds to a horizontal 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);