函数fspecial()和imfilter()的用法
时间: 2023-06-02 09:01:48 浏览: 237
函数fspecial()和imfilter()都是MATLAB中用于图像处理的函数。
1. fspecial()函数
fspecial()函数用于生成各种滤波器的核函数。其语法为:
h = fspecial(type, ...)
其中,type表示生成滤波器的类型,可以是以下几种:
- 'average': 平均滤波器
- 'disk': 圆形滤波器
- 'gaussian': 高斯滤波器
- 'laplacian': 拉普拉斯滤波器
- 'log': LoG滤波器
- 'motion': 运动模糊滤波器
- 'prewitt': Prewitt滤波器
- 'sobel': Sobel滤波器
除了type参数外,还可以添加其他参数,例如:
h = fspecial('gaussian', hsize, sigma)
其中,hsize表示滤波器核的大小,sigma表示高斯分布的标准差。
2. imfilter()函数
imfilter()函数用于对图像进行滤波处理。其语法为:
B = imfilter(A, h, filtermode, boundary, ...)
其中,A表示要滤波的图像,h表示滤波器核,filtermode表示滤波模式,可以是以下几种:
- 'corr': 卷积模式,即滤波器核进行旋转后与图像进行卷积操作
- 'conv': 相关模式,即滤波器核不进行旋转直接与图像进行卷积操作
boundary表示边界处理方式,可以是以下几种:
- 'replicate': 用边界像素值填充
- 'symmetric': 对称填充
- 'circular': 循环填充
除了以上参数外,还可以添加其他参数,例如:
B = imfilter(A, h, filtermode, boundary, 'same')
其中,'same'表示输出大小与输入图像A相同。
总结:
fspecial()函数用于生成各种滤波器的核函数,而imfilter()函数则用于对图像进行滤波处理。两者常常结合使用,先使用fspecial()函数生成滤波器核,再使用imfilter()函数对图像进行滤波处理。
阅读全文
相关推荐


















