MATLAB中ordfilt2函数用法

目录

语法

说明

示例

使用最大值滤波器对图像进行滤波


        ordfilt2函数的功能是二维顺序统计量滤波。

语法

B = ordfilt2(A,order,domain)
B = ordfilt2(A,order,domain,S)
B = ordfilt2(___,padopt)

说明

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)

        如图所示:

参数说明

A — 要滤波的数据

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

order — 用来替换目标像素的元素

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

domain — 邻域

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

滤波运算类型MATLAB 代码邻域示例图像数据,指示所选元素
中位数滤波器B = ordfilt2(A,5,ones(3,3))

3-by-3 matrix of ones

3-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 ones

3-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 ones

3-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.

S — 加性偏移量

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

padopt — 填充选项

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

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

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

B — 滤波后的数据

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

提示

  • 当处理不包含任何零值元素的大型域矩阵时,如果 A 采用整数数据格式(uint8、int8、uint16 和 int16),则 ordfilt2 可以获得更高的性能。uint8 和 int8 的速度增益高于 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

  • 12
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值