图像处理之matlab中fspecial函数用法详解

一、fspecial()函数基本调用格式

通过在matlab的命令行窗口输入:help fspecial,可以查看到以下说明:

fspecial - 创建预定义的二维滤波器
此 MATLAB 函数 创建具有指定 type 的二维滤波器 h。一些滤波器类型具有可选的附加参
数,如以下语法所示。fspecial 以相关性核形式返回 h,该形式适用于 imfilter。
    h = fspecial(type)
    h = fspecial('average',hsize)
    h = fspecial('disk',radius)
    h = fspecial('gaussian',hsize,sigma)
    h = fspecial('laplacian',alpha)
    h = fspecial('log',hsize,sigma)
    h = fspecial('motion',len,theta)
    h = fspecial('prewitt')
    h = fspecial('sobel')

总结一下fspecial函数有三种语法格式:
(1)h=fspecial(type)
(2)h=fspecial(type,para)
(3)h=fspecial(type,para,sigma)
其中type用于指定滤波器种类,para用于对具体滤波器种类添加额外的参数信息,sigma用于表示滤波器的标准差,单位为像素且默认值为0.5

二、滤波器种类type说明

1、‘average’

'average’表示均值滤波,h = fspecial(‘average’,hsize)生成均值滤波器,参数hsize代表模板尺寸默认为3*3。

2、‘disk’

'disk’表示圆形区域均值滤波,h = fspecial(‘disk’,radius)生成圆形区域均值滤波器,参数radius代表区域半径默认为5。

3、‘gaussian’

'gaussian’表示高斯低通滤波, h = fspecial(‘gaussian’,hsize,sigma生成高斯低通滤波器,参数hsize代表模板尺寸默认为3*3,sigma用于表示滤波器的标准差,单位为像素且默认值为0.5。

4、‘laplacian’

扫描二维码关注公众号,回复: 15222420 查看本文章

'laplacian’表示拉普拉斯算子,h = fspecial(‘laplacian’,alpha)生成拉普拉斯滤波器,参数alpha用于控制算子形状,取值范围为[0 1],默认值为0.2。

5、‘log’

'log’表示拉普拉斯高斯算子,h = fspecial(‘log’,hsize,sigma)生成拉普拉斯高斯滤波器,参数hsize代表模板尺寸默认为3*3,sigma用于表示滤波器的标准差,单位为像素且默认值为0.5。

6、‘motion’

'motion’表示运动模糊算子,h = fspecial(‘motion’,len,theta)生成运动模糊滤波器,参数len和theta表示摄像物体逆时针方向以theta角度运动了len个像素,len的默认值为9,theta的默认值为0。

7、‘prewitt’

'prewitt’为prewitt算子,用于边缘增强,无参数。

8、 ‘sobel’

'sobel’为sobel算子,用于边缘提取,无参数。

三、fspecial()函数应用实例

img = imread('football.jpg');
I1=imfilter(img,fspecial('average'),'replicate','same');
I2=imfilter(img,fspecial('disk',5),'replicate','same');
I3=imfilter(img,fspecial('gaussian',5,0.5),'replicate','same');
I4=imfilter(img,fspecial('laplacian',0.2),'replicate','same');
I5=imfilter(img,fspecial('log',5,0.5),'replicate','same');
I6=imfilter(img,fspecial('motion',20,30),'replicate','same');
I7=imfilter(img,fspecial('prewitt'),'replicate','same');
I8=imfilter(img,fspecial('sobel'),'replicate','same');

figure(1);
imshow(img);

figure(2);
subplot(241),imshow(I1);
title('均值滤波');
subplot(242),imshow(I2);
title('圆形区域均值滤波');
subplot(243),imshow(I3);
title('高斯低通滤波');
subplot(244),imshow(I4);
title('拉普拉斯算子');
subplot(245),imshow(I5);
title('拉普拉斯高斯算子');
subplot(246),imshow(I6);
title('运动模糊算子');
subplot(247),imshow(I7);
title('prewitt算子');
subplot(248),imshow(I8);
title('sobel算子');

实现效果:
(1)原始图像:
在这里插入图片描述
(2)通过各种滤波器处理过后的图像
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_44111805/article/details/126511396
今日推荐