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);


你可能感兴趣的:(matlab)