1、imfilter
功能:对任意类型数组或多维图像进行滤波。
用法:B = imfilter(A,H)
B = imfilter(A,H,option1,option2,...)
或写作g = imfilter(f, w, filtering_mode, boundary_options, size_options)
其中,f为输入图像,w为滤波掩模,g为滤波后图像。filtering_mode用于指定在滤波过程中是使用“相关”还是“卷积”。boundary_options用于处理边界充零问题,边界的大小由滤波器的大小确定。具体参数选项见下表:
举例: originalRGB = imread('peppers.png');
imshow(originalRGB)
h = fspecial('motion', 50, 45);% 创建一个滤波器
filteredRGB = imfilter(originalRGB, h);
figure, imshow(filteredRGB)
2、fspecial
功能:创建预定义的二维滤波器,在图像处理中就是一个模板即函数的返回值。
用法:h = fspecial(type) 带默认类型参数
h = fspecial(type, parameters) 带指定的类型参数:parameters
TYPE可能的值如下:
'average' averaging filter,均值滤波器,即H = fspecial('average',HSIZE)参数HSIZE代表模板尺寸,默认值为[3,3]。
'disk' circular averaging filter,圆形区域均值滤波器,即H = fspecial('disk',RADIUS),参数radius代表区域半径,默认值为5。
'gaussian' Gaussian lowpass filter,高斯低通滤波器,即H = fspecial('gaussian',HSIZE,SIGMA),有两个参数,hsize表示模板尺寸,默认值为 [3 3],sigma为滤波器的标准差,单位为像素,默认值为0.5。
'laplacian' filter approximating the 2-D Laplacian operator,接近二维拉普拉斯算子的滤波器,即H = fspecial('laplacian',ALPHA),参 数alpha用于控制算子形状,取值范围为[0,1],默认值为0.2。
'log' Laplacian of Gaussian filter,拉普拉斯高斯滤波器,即H = fspecial('log',HSIZE,SIGMA),有两个参数,hsize表示模板尺寸,默认 值为[3 3],sigma为滤波器的标准差,单位为像素,默认值为0.5。
'motion' motion filter,运动滤波器,即H = fspecial('motion',LEN,THETA),有两个参数,表示摄像物体逆时针方向以theta角度运动了len个像 素,len的默认值为9,theta的默认值为0。
'prewitt' Prewitt horizontal edge-emphasizing filter,Prewitt水平边缘增强滤波器,即H = fspecial('prewitt'),大小为[3 3],无参数。
'sobel' Sobel horizontal edge-emphasizing filter,Sobel水平边缘增强滤波,即H = fspecial('sobel'),大小为[3 3],无参数。
举例:I = imread('cameraman.tif');
subplot(2,2,1);imshow(I);title('Original Image');
H = fspecial('motion',20,45);
MotionBlur = imfilter(I,H,'replicate');
subplot(2,2,2);imshow(MotionBlur);title('Motion Blurred Image');
H = fspecial('disk',10);
blurred = imfilter(I,H,'replicate');
subplot(2,2,3);imshow(blurred);title('Blurred Image');