Main Content

ordfilt2

二维顺序统计量滤波

说明

示例

B = ordfilt2(A,order,domain)A 中的每个元素替换为由 domain 中的非零元素指定的相邻元素的有序集中的第 order 个元素。

B = ordfilt2(A,order,domain,S)A 进行滤波,其中 ordfilt2 使用与 domain 的非零值对应的 S 的值作为加性偏移量。您可以使用此语法实现灰度形态学运算,包括灰度膨胀和腐蚀。

B = ordfilt2(___,padopt)A 进行滤波,其中 padopt 指定 ordfilt2 如何填充矩阵边界。

示例

全部折叠

将图像读入工作区并显示它。

A = imread('snowflakes.png');
figure
imshow(A)

对图像进行滤波并显示结果。

B = ordfilt2(A,25,true(5));
figure
imshow(B)

输入参数

全部折叠

要滤波的数据,指定为二维逻辑矩阵或二维数值矩阵。

数据类型: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

用来替换目标像素的元素,指定为实整数标量。

数据类型: double

邻域,指定为包含 10 的数值或逻辑矩阵。domain 等效于用于二值图像运算的结构元素。1 值元素定义滤波运算的邻域。下表列出一些常见滤波器的示例。

滤波运算类型MATLAB 代码邻域示例图像数据,指示选定元素
中位数滤波器B = ordfilt2(A,5,ones(3,3))3-by-3 matrix of ones3-by-3 matrix of numbers. The element with the fifth highest value in the neighborhood is circled.
最小值滤波器B = ordfilt2(A,1,ones(3,3))3-by-3 matrix of ones3-by-3 matrix of numbers. The element with the lowest value in the neighborhood is circled.
最大值滤波器B = ordfilt2(A,9,ones(3,3))3-by-3 matrix of ones3-by-3 matrix of numbers. The element with the highest value in the neighborhood is circled.
北、东、南、西邻点的最小值B = ordfilt2(A,1,[0 1 0; 1 0 1; 0 1 0])3-by-3 neightborhood in which the north, south, east, and west pixels are true (1) and the center and corner pixels are false (0)3-by-3 matrix of numbers. The element with the lowest value in the specified neighborhood is circled. Elements excluded from the neighborhood are grayed out.

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

加性偏移量,指定为与 domain 大小相同的数值矩阵。

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

填充选项,指定为下列值之一。

选项描述
'zeros'0 填充数组边界。
'symmetric'

用自身的镜像翻转填充数组。

数据类型: char | string

输出参量

全部折叠

滤波后的数据,以与输入数据 A 具有相同类的二维数值矩阵或二维逻辑矩阵形式返回。

提示

  • 当处理不包含任何零值元素的大型域矩阵时,如果 A 采用整数数据格式(uint8int8uint16int16),则 ordfilt2 可以获得更高的性能。uint8int8 的速度增益高于 16 位数据类型。对于 8 位数据格式,域矩阵必须包含 7 行或更多行。对于 16 位数据格式,域矩阵必须包含三行或更多行以及 520 个或更多元素。

参考

[1] Haralick, Robert M., and Linda G. Shapiro, Computer and Robot Vision, Volume I, Addison-Wesley, 1992.

[2] Huang, T.S., G.J.Yang, and G.Y.Tang. "A fast two-dimensional median filtering algorithm.", IEEE transactions on Acoustics, Speech and Signal Processing, Vol ASSP 27, No. 1, February 1979

扩展功能

版本历史记录

在 R2006a 之前推出

全部展开

另请参阅