matlab fspecial创建滤波算子

Fspecial函数用于创建预定义的滤波算子,其语法格式为:
h = fspecial(type)
h = fspecial(type,parameters,sigma)

参数type制定算子类型,parameters指定相应的参数,具体格式为:
type='average',为均值滤波,参数为n,代表模版尺寸,用向量表示,默认值为[3,3]
type= 'gaussian',为高斯低通滤波器,参数有两个,n表示模版尺寸,默认值为[3,3]sigma表示滤波器的标准差,单位为像素,默认值为 

0.5
type= 'laplacian',为拉普拉斯算子,参数为alpha,用于控制拉普拉斯算子的形状,取值范围为[0,1],默认值为0.2
type= 'log',为拉普拉斯高斯算子,参数有两个,n表示模版尺寸,默认值为[3,3]sigma为滤波器的标准差,单位为像素,默认值为0.5
type= 'prewitt'
,为prewitt算子,用于边缘增强,无参数。
type= 'sobel',为著名的sobel算子,用于边缘提取,无参数。
type= 'unsharp',为对比度增强滤波器,参数alpha用于控制滤波器的形状,范围为[0,1],默认值为0.2

例子:

>> G=fspecial('gaussian',5)%参数为5,表示产生5*5gaussian矩阵,如果没有,默认为3*3的矩阵。

G =

    0.0000    0.0000    0.0002    0.0000    0.0000
    0.0000    0.0113    0.0837    0.0113    0.0000
    0.0002    0.0837    0.6187    0.0837    0.0002
    0.0000    0.0113    0.0837    0.0113    0.0000
    0.0000    0.0000    0.0002    0.0000    0.0000

>> G=fspecial('gaussian',5,1.5)%1.5为滤波器的标准差。

G =

    0.0144    0.0281    0.0351    0.0281    0.0144
    0.0281    0.0547    0.0683    0.0547    0.0281
    0.0351    0.0683    0.0853    0.0683    0.0351
    0.0281    0.0547    0.0683    0.0547    0.0281
    0.0144    0.0281    0.0351    0.0281    0.0144

>> 

>> G=fspecial('average')%默认为3*3的矩阵。均值滤波

G =

    0.1111    0.1111    0.1111
    0.1111    0.1111    0.1111
    0.1111    0.1111    0.1111

>> G=fspecial('average',5)%会产生5*5的矩阵。

 

I=imread('obj1.jpg');

I0=rgb2gray(I);

I01=im2double(I0);

% I=im2double(I);

h1=fspecial('sobel');

h2=fspecial('gaussian',8);

h3=fspecial('laplacian',0.2);

h4=fspecial('laplacian');

h5=fspecial('sobel');

 

I1=filter2(h1,I0);

I2=filter2(h2,I01);

I3=filter2(h3,I0);

I4=filter2(h4,I0);

I5=imfilter(I,h5,'corr','same');

I6=imfilter(I,h5,'conv','same');

 

 

subplot(3,2,1);imshow(I1);

subplot(3,2,2);imshow(I2);

subplot(3,2,3);imshow(I3);

subplot(3,2,4);imshow(I4);

subplot(3,2,5);imshow(I5);

subplot(3,2,6);imshow(I6);

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值