# 众数滤波

[众数滤波](https://www.edgepedia.org/zh/mode-filtering-image-processing)是一种非线性图像处理滤波，它把每个像素替换为其周围邻域中出现次数最多的值，即众数。它用于去噪和平滑，尤其适用于分类数据，以及强度聚集为少数几个主导取值的图像。

与返回某个中间顺序统计量的中值滤波、或取平均的均值（盒式）滤波不同，众数滤波是基于频率的：它挑出窗口中露面最多的那个值，保住并扩张占主导的平坦区域，同时抑制孤立的离群点。<sup>[1](https://albumentations.ai/explore/transform/ModeFilter/docs/)</sup> MATLAB 的 `modefilt` 按这一定义实现二维图像与三维体的滤波，边界元素以镜像方式填充。<sup>[2](https://www.mathworks.com/help/images/ref/modefilt.html)</sup> 有一个低通滤波程序计算每个像素周围区域内图像值众数的估计，其动机来自天文图像中偏斜的背景分布。<sup>[3](https://doi.org/10.1117/12.957111)</sup>

| 要点 | 说明 |
|---|---|
| 每像素输出 | 邻域中出现次数最多的值；出现并列时按各软件的具体规则裁定（取中心像素、取最小值或取第一个类别）<sup>[2](https://www.mathworks.com/help/images/ref/modefilt.html)</sup> |
| 滤波器族 | 非线性、基于频率；区别于顺序统计量（中值）滤波与取平均（均值）滤波<sup>[1](https://albumentations.ai/explore/transform/ModeFilter/docs/)</sup> |
| 最适用的噪声 | 散斑（此时众数等于最大似然估计量），以及大多数像素正确、少数被污染的噪声<sup>[4](https://digital-library.theiet.org/content/journals/10.1049/ip-vis_19951800)</sup><sup> • </sup><sup>[5](https://docs.openmv.io/v5.0.0/openmvcam/tutorial/image/filters/linear-neighborhood.html)</sup> |
| 数据要求 | 需为量化值或整数值；有限个连续取值样本的精确值众数通常没有意义，因此对这类数据做有用的众数滤波，须依赖量化或密度估计之类的手段<sup>[1](https://albumentations.ai/explore/transform/ModeFilter/docs/)</sup><sup> • </sup><sup>[6](https://iraf.readthedocs.io/en/latest/tasks/images/imfilter/fmode.html)</sup> |
| 典型窗口 | 方形或矩形，常用 3×3；计算量随窗口面积增长<sup>[7](https://catalyst.earth/catalyst-system-files/professional-help/references/pciFunction_r/python/P_fmo.html)</sup><sup> • </sup><sup>[5](https://docs.openmv.io/v5.0.0/openmvcam/tutorial/image/filters/linear-neighborhood.html)</sup> |
| 主要用途 | 专题图清理、分类结果平滑、彩色图像增强、天文背景估计<sup>[7](https://catalyst.earth/catalyst-system-files/professional-help/references/pciFunction_r/python/P_fmo.html)</sup><sup> • </sup><sup>[3](https://doi.org/10.1117/12.957111)</sup> |
| 边缘行为 | 边缘移位特性与中值滤波相似；在边缘上并无特别优势<sup>[8](https://doi.org/10.1179/136821904225011537)</sup> |

## 工作原理

对每个输出像素，滤波器考察以它为中心的输入像素窗口，写入该窗口的众数。形式上说，众数滤波是 M 平滑器族的一端：对 p 阶 M 平滑器，p = 0 给出众数，即出现最频繁的值；而极限 p → ∞ 给出中程值；迭代中值滤波则逼近平均曲率运动。<sup>[9](https://www.mia.uni-saarland.de/Publications/welk-ssvm19.pdf)</sup> 因此众数类滤波器与中值滤波同属顺序统计量与稳健估计这一族——中值滤波对大小为 n = 2u + 1 的窗口定义为 y_i = med(x_{i−u}, …, x_{i+u})。<sup>[10](https://web.eecs.utk.edu/~hqi/ece472-572/reference/order-statistics.pdf)</sup>

对特定噪声模型而言，众数是自然的估计量。对受散斑污染的图像，最大似然估计量对应的正是统计众数，这正是对超声图像做众数滤波的动机。<sup>[4](https://digital-library.theiet.org/content/journals/10.1049/ip-vis_19951800)</sup> 同一套频率逻辑也说明了众数何时胜过中值：它适用于大多数像素正确、少数像素被不同程度污染的噪声，而当被污染的值堆在排序窗口的一侧时，中值就可能漏判。<sup>[5](https://docs.openmv.io/v5.0.0/openmvcam/tutorial/image/filters/linear-neighborhood.html)</sup> 它也适用于分类数据，而在那种场合中值滤波根本无从谈起。<sup>[2](https://www.mathworks.com/help/images/ref/modefilt.html)</sup>

## 实现方式

直接的实现方式是在图像上滑动一个矩形窗口，在每个位置统计窗口取值的直方图，并取频数最大者所对应的像素值。IRAF 的 `fmode` 任务把它改进为增量算法：先在第一个窗口位置算出直方图、中值以及小于中值的像素计数，然后随窗口移动一位逐次更新并重算众数。<sup>[6](https://iraf.readthedocs.io/en/latest/tasks/images/imfilter/fmode.html)</sup> 像素值先被量化为整数分箱；对非整数数据，算出的众数只是近似值。<sup>[6](https://iraf.readthedocs.io/en/latest/tasks/images/imfilter/fmode.html)</sup>

由于小窗口的直方图很稀疏，许多实现并不直接读出众数，而是估计众数。当滤波掩膜内的样本很少、众数难以确定时，截尾中值滤波可给出众数的近似。<sup>[4](https://digital-library.theiet.org/content/journals/10.1049/ip-vis_19951800)</sup> 在彩色众数滤波中，先求出压缩后局部直方图的最大值，再以该最大值附近的抛物线拟合估计真正的众数。<sup>[11](http://cat.cvc.uab.es/~joost/papers/icip2001.pdf)</sup> 另一条思路是把众数视为使经验密度达到最大值的取值，从多个随机初值出发用牛顿—拉夫森法求解该优化问题，并给出了 CPU 与 GPU（JCuda 与 CuPy）实现。<sup>[12](https://github.com/shermanlo77/modefilter)</sup>

并列情形需要确定性的裁定规则，各软件做法不同。MATLAB 若中心像素的值属于并列的众数之一，就取中心像素的值，否则取数值最小的那个众数；对分类输入，则取 `categories(A)` 中的第一个类别。<sup>[2](https://www.mathworks.com/help/images/ref/modefilt.html)</sup> [Albumentations](https://www.edgepedia.org/zh/albumentations) 总是取并列众数中的最小值；USGS ISIS 在矩形窗口内出现多峰时，写入众数取值中最小的那个。<sup>[1](https://albumentations.ai/explore/transform/ModeFilter/docs/)</sup><sup> • </sup><sup>[13](https://isis.astrogeology.usgs.gov/10.0.0/Application/presentation/Tabbed/mode/mode.html)</sup>

## 起源

有一个低通滤波程序计算每个像素周围区域内图像值众数的估计；其动机是：当前景源使像素分布偏斜时，滑动平均之类的线性低通滤波会产生有偏的背景估计，而估计众数在许多情形下能避开这种偏差。<sup>[3](https://doi.org/10.1117/12.957111)</sup> 早期的实际成功来自“截尾中值滤波”实现，它在直接估计失效之处给出了众数的近似。<sup>[8](https://doi.org/10.1179/136821904225011537)</sup> A.N. 埃文斯（A.N. Evans）在 1995 年《IEE Proceedings - Vision Image and Signal Processing》的一篇论文中，将众数滤波用于超声散斑抑制以支持特征提取。<sup>[14](https://doi.org/10.1049/ip-vis:19951800)</sup>

## 变体

**彩色众数滤波。**众数滤波通过局部直方图框架扩展到多通道彩色图像，文中提出了三种操作；它们已被用于边缘锐化、保细节去噪、小目标移除和缺失数据插补。<sup>[11](http://cat.cvc.uab.es/~joost/papers/icip2001.pdf)</sup>

**多尺度众数滤波。**多尺度众数滤波（MSMF）被提出作为双边滤波与均值漂移滤波二者的推广，它在多个尺度上逐级工作，使滤波器不至于被困在虚假的局部极大值上，而倾向于更显著的极大值。其计算复杂度只取决于步数与核尺寸。<sup>[15](https://www.eurasip.org/Proceedings/Eusipco/Eusipco2008/papers/1569104877.pdf)</sup>

**GIS 多数滤波与众数滤波。**在遥感领域，众数滤波被称为多数滤波。ArcGIS 的 Majority Filter 依据栅格单元相邻单元中的多数来替换该单元，既要求相似邻居的数量足够，也要求它们相对于核中心具有空间邻接性，并须输入整数。<sup>[16](https://desktop.arcgis.com/en/arcmap/latest/tools/spatial-analyst-toolbox/majority-filter.htm)</sup> 在制图栅格综合中，众数滤波是一种基于核内类别频数的邻域算子：对每个非边缘单元，用众数类别替换中心单元的类别，核越大，综合程度越高。<sup>[17](https://cartogis.org/docs/proceedings/archive/auto-carto-13/pdf/data-quality-implications-of-raster-generalization.pdf)</sup> PCI Geomatica 的 FMO 滤波器增加了 THINLINE 选项，只有当中心像素的灰度值在 3×3 窗口中出现少于三次时才对其进行滤波，从而保护溪流、道路这类细窄类别。<sup>[7](https://catalyst.earth/catalyst-system-files/professional-help/references/pciFunction_r/python/P_fmo.html)</sup>

## 应用

众数滤波被描述为清理专题图以供展示的理想手段，因为它把小型的“孤岛”图斑替换为其周围更大的图斑。<sup>[7](https://catalyst.earth/catalyst-system-files/professional-help/references/pciFunction_r/python/P_fmo.html)</sup> 同一操作在“多数滤波”之名下，常用于平滑分类结果、减轻椒盐效应，在诸如 3×3 的可指定邻域上计算众数。<sup>[18](https://enmap-box.readthedocs.io/en/rfc_spectral_properties/usr_section/usr_cookbook/generic_filter.html)</sup> 在天文学中，众数估计是背景低通滤波的基础<sup>[3](https://doi.org/10.1117/12.957111)</sup>，也是 IRAF `fmode` 流水线任务的基础。<sup>[6](https://iraf.readthedocs.io/en/latest/tasks/images/imfilter/fmode.html)</sup> 在彩色图像上，据报告众数滤波无论用于图像增强还是噪声消除，效果都令人印象深刻。<sup>[8](https://doi.org/10.1179/136821904225011537)</sup>

目前的实现包括 MATLAB 的 `modefilt`（二维与三维）<sup>[2](https://www.mathworks.com/help/images/ref/modefilt.html)</sup>、Albumentations 面向量化图像、调色板式图像或卡通图像的逐通道 `ModeFilter`<sup>[1](https://albumentations.ai/explore/transform/ModeFilter/docs/)</sup>、OpenMV 面向嵌入式视觉的 `mode()`<sup>[5](https://docs.openmv.io/v5.0.0/openmvcam/tutorial/image/filters/linear-neighborhood.html)</sup>，以及 AMD 的 Vitis Vision 硬件核，后者在 N×N 窗口上计算众数，适用于任何大于 1 的奇数 FILTER_SIZE。<sup>[19](https://docs.amd.com/r/en-US/Vitis_Libraries/vision/api-reference.html_1_77?contentId=32cwYR0nrwHiiX50wtUHXA)</sup>

## 局限与替代方案

对于局部图像邻域这样的小集合，经典的众数是一种高度依赖噪声的运算，这就促使人们在取众数之前先对局部直方图或密度做平滑。<sup>[11](http://cat.cvc.uab.es/~joost/papers/icip2001.pdf)</sup> 在边缘上，众数滤波并无特别优势：其边缘移位特性与中值滤波相似。<sup>[8](https://doi.org/10.1179/136821904225011537)</sup> 形态学的闭—开、开—闭滤波在脉冲噪声上表现较好，但通常逊于中值滤波，且在加性白噪声下是有偏的位置估计量；最大值滤波与最小值滤波能保住边缘，却分别强化亮区与暗区。<sup>[10](https://web.eecs.utk.edu/~hqi/ece472-572/reference/order-statistics.pdf)</sup>

计算量随窗口面积增长：size=3 的邻域滤波每像素的工作量约为 size=1 的九倍，而基于排序的中值滤波每像素比取平均更慢。<sup>[5](https://docs.openmv.io/v5.0.0/openmvcam/tutorial/image/filters/linear-neighborhood.html)</sup> IRAF 基于直方图的 `fmode` 在 SPARCStation2 上用 5×5 和 7×7 窗口滤波一幅 512×512 的整数图像，约需 6.1 与 7.6 CPU 秒。<sup>[6](https://iraf.readthedocs.io/en/latest/tasks/images/imfilter/fmode.html)</sup>

## References

1. [ModeFilter Documentation - Albumentations](https://albumentations.ai/explore/transform/ModeFilter/docs/)
2. [modefilt - 2-D and 3-D mode filtering - MATLAB](https://www.mathworks.com/help/images/ref/modefilt.html)
3. [The Mode Filter: A Nonlinear Image Processing Operator (Proceedings of SPIE, 1979)](https://doi.org/10.1117/12.957111)
4. [Mode filtering to reduce ultrasound speckle for feature extraction (Evans & Nixon, IEE Proceedings - Vision, Image and Signal Processing, 1995)](https://digital-library.theiet.org/content/journals/10.1049/ip-vis_19951800)
5. [5.13. Linear and neighbourhood filters - OpenMV MicroPython documentation](https://docs.openmv.io/v5.0.0/openmvcam/tutorial/image/filters/linear-neighborhood.html)
6. [fmode: Quantize and box modal filter a list of 1D or 2D images (IRAF)](https://iraf.readthedocs.io/en/latest/tasks/images/imfilter/fmode.html)
7. [FMO (mode filter) - Catalyst/PCI Geomatica documentation](https://catalyst.earth/catalyst-system-files/professional-help/references/pciFunction_r/python/P_fmo.html)
8. [Mode filters and their effectiveness for enhancing colour images](https://doi.org/10.1179/136821904225011537)
9. [PDE Evolutions for M-Smoothers: From Common Myths to Robust Numerics (SSVM 2019)](https://www.mia.uni-saarland.de/Publications/welk-ssvm19.pdf)
10. [Order statistics in digital image processing (Proceedings of the IEEE)](https://web.eecs.utk.edu/~hqi/ece472-572/reference/order-statistics.pdf)
11. [Mode filtering of colour images (ICIP 2001)](http://cat.cvc.uab.es/~joost/papers/icip2001.pdf)
12. [shermanlo77/modefilter, ImageJ plugin, Java and CuPy implementation of the mode filter and empirical null filter](https://github.com/shermanlo77/modefilter)
13. [mode - ISIS Application Documentation (USGS)](https://isis.astrogeology.usgs.gov/10.0.0/Application/presentation/Tabbed/mode/mode.html)
14. [A.N. Evans and M.S. Nixon (1995). Mode filtering to reduce ultrasound speckle for feature extraction. IEE Proceedings - Vision Image and Signal Processing.](https://doi.org/10.1049/ip-vis:19951800)
15. [Edge Preserving Smoothing by Multiscale Mode Filtering (EUSIPCO 2008)](https://www.eurasip.org/Proceedings/Eusipco/Eusipco2008/papers/1569104877.pdf)
16. [Majority Filter (Spatial Analyst), ArcMap Documentation](https://desktop.arcgis.com/en/arcmap/latest/tools/spatial-analyst-toolbox/majority-filter.htm)
17. [Data Quality Implications of Raster Generalization (Veregin and McMaster, Auto-Carto 13)](https://cartogis.org/docs/proceedings/archive/auto-carto-13/pdf/data-quality-implications-of-raster-generalization.pdf)
18. [Generic Filter (Majority) - EnMAP-Box cookbook](https://enmap-box.readthedocs.io/en/rfc_spectral_properties/usr_section/usr_cookbook/generic_filter.html)
19. [Mode filter - Vitis Libraries vision API reference (AMD)](https://docs.amd.com/r/en-US/Vitis_Libraries/vision/api-reference.html_1_77?contentId=32cwYR0nrwHiiX50wtUHXA)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Language and vision AI › Computer vision › Vision methods and geometry › Low-level image analysis

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/mode-filter

English original: https://www.edgepedia.org/mode-filter
