matlab爲圖像加模糊

運動模糊

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的默認值爲9theta的默認值爲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);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章