# 众数滤波（图像处理）

[众数滤波](https://www.edgepedia.org/zh/mode-filter)器是一种非线性图像处理滤波器，它用像素周围邻域中出现最频繁的值——众数——替换每个像素。它用于灰度和彩色图像中的噪声去除，尤其特别的是，还用于类别数据，例如分类遥感图，此时中值滤波不可用。<sup>[1](https://www.mathworks.com/help/images/ref/modefilt.html)</sup> 在遥感和地理信息系统（GIS）中，同一操作通常被称为多数滤波，并且是从专题地图中去除椒盐误分类的标准步骤。<sup>[2](https://enmap-box.readthedocs.io/en/latest/usr_section/usr_cookbook/generic_filter.html)</sup>

| 关键事实 | 细节 |
|---|---|
| 输出 | 每个输出像素是输入邻域的众数（出现最频繁的值）<sup>[1](https://www.mathworks.com/help/images/ref/modefilt.html)</sup> |
| 典型窗口 | 方形奇数尺寸窗口，常见实现中默认为3×3至7×7<sup>[3](https://albumentations.ai/explore/transform/ModeFilter/docs/)</sup> |
| 并列值处理 | 若中心像素处于并列，则取中心像素；否则取决于实现，取最小值、最低的并列众数或第一个类别<sup>[1](https://www.mathworks.com/help/images/ref/modefilt.html)</sup><sup> • </sup><sup>[4](https://isis.astrogeology.usgs.gov/10.0.0/Application/presentation/Tabbed/mode/mode.html)</sup> |
| 连续数据 | 对于连续强度值，众数定义不明确；实现中会量化为分箱，或近似为 \( 3 \cdot \mathrm{median} - 2 \cdot \mathrm{mean} \)<sup>[5](https://iraf.readthedocs.io/en/latest/tasks/images/imfilter/fmode.html)</sup><sup> • </sup><sup>[3](https://albumentations.ai/explore/transform/ModeFilter/docs/)</sup> |
| 最适合的噪声 | 脉冲和椒盐污染，即大多数像素正确、少数像素错误<sup>[6](https://docs.openmv.io/v5.0.0/openmvcam/tutorial/image/filters/linear-neighborhood.html)</sup> |
| 边缘行为 | 边缘偏移与中值滤波类似，在这方面没有特别优势<sup>[7](https://digital-library.theiet.org/content/journals/10.1049/ip-vis_19990642)</sup> |
| 已知开销 | 在SPARCStation2上，对512×512整数图像使用5×5和7×7窗口时，分别耗时6.1和7.6 CPU秒（IRAF fmode）<sup>[5](https://iraf.readthedocs.io/en/latest/tasks/images/imfilter/fmode.html)</sup> |

## 工作原理

对于每个像素，滤波器收集窗口内的值，建立局部分布，并将该分布的最大值——众数——写入输出。这使众数滤波归入一类局部估计器，其特征由对偏差所用的惩罚项决定：在\( l_{2} \)惩罚项下，局部极小值点是均值；在\( l_{1} \)下是中位数；而稳健非凸惩罚项产生的解近似于潜在概率密度的众数。<sup>[8](https://www.mia.uni-saarland.de/Publications/mrazek-spp1114-51.pdf)</sup>

在连续灰度图像上，有限样本的众数并不稳定，因此实际滤波器要么将强度值量化为直方图分箱，要么对众数进行近似。IRAF的fmode任务使用近似式 \( \text{mode} = 3 \cdot \text{median} - 2 \cdot \text{mean} \)，其文档称该式主要适用于整数或未校准数据。<sup>[5](https://iraf.readthedocs.io/en/latest/tasks/images/imfilter/fmode.html)</sup> [Albumentations](https://www.edgepedia.org/zh/albumentations)的ModeFilter在uint8空间中处理float32图像，因为如其文档所述，众数对连续值信号没有意义。<sup>[3](https://albumentations.ai/explore/transform/ModeFilter/docs/)</sup> 一种理论刻画将重复的无穷小众数滤波视为偏微分方程：在正则点处，图像按 \( L_{t} = L_{vv} - 2L_{ww} \) 演化，其中 \( v \) 与等照度线相切，\( w \) 沿梯度方向；而在临界点处 \( L_{t} = 0 \)。<sup>[9](https://www.sciencedirect.com/science/article/abs/pii/S0031320399000558)</sup>

## 实现方法

实践者选择窗口形状和大小（典型的是3×3或更大的奇数方形窗口<sup>[10](https://web.eecs.utk.edu/~hqi/ece472-572/reference/order-statistics.pdf)</sup>），为边界选择填充方案（MATLAB的modefilt镜像边界元素<sup>[1](https://www.mathworks.com/help/images/ref/modefilt.html)</sup>，Albumentations使用反射填充<sup>[3](https://albumentations.ai/explore/transform/ModeFilter/docs/)</sup>），并定义并列值处理。MATLAB若中心像素属于并列众数之一，则使用中心像素；否则使用最小数值，或对于类别输入使用categories(A)中的第一个类别；USGS ISIS的mode任务写入并列众数值中的最低值。<sup>[1](https://www.mathworks.com/help/images/ref/modefilt.html)</sup><sup> • </sup><sup>[4](https://isis.astrogeology.usgs.gov/10.0.0/Application/presentation/Tabbed/mode/mode.html)</sup>

高效实现会避免在每个位置重新扫描窗口。IRAF的fmode将像素量化为整数分箱，计算第一个窗口位置的直方图、中位数以及低于中位数的计数，并在窗口滑动一步时更新这些量。<sup>[5](https://iraf.readthedocs.io/en/latest/tasks/images/imfilter/fmode.html)</sup> 对于五维局部直方图空间上的彩色众数滤波，有人提出降低传感器空间的分辨率以减少内存使用。<sup>[11](http://cat.cvc.uab.es/~joost/papers/icip2001.pdf)</sup> 使用CUDA的GPU实现已被用于加速该滤波器的经验密度形式。<sup>[12](https://shermanlo77.github.io/mode_filter.html)</sup> 现有实现包括MATLAB（modefilt）、IRAF、USGS ISIS、GIS软件包如Catalyst/PCI（FMO）和EnMAP-Box（基于scipy.stats.mode和scipy.ndimage.generic_filter构建<sup>[2](https://enmap-box.readthedocs.io/en/latest/usr_section/usr_cookbook/generic_filter.html)</sup>）、Albumentations以及OpenMV。<sup>[3](https://albumentations.ai/explore/transform/ModeFilter/docs/)</sup><sup> • </sup><sup>[6](https://docs.openmv.io/v5.0.0/openmvcam/tutorial/image/filters/linear-neighborhood.html)</sup>

## 起源

一篇早期发表的众数滤波程序描述出现在《SPIE会议录》（Proceedings of SPIE）的一篇论文中，其动机来自天文测光：由于前景源会使背景像素分布偏斜，诸如滑动均值之类的线性低通滤波器会产生有偏的背景估计，从而产生有偏的测光结果；该论文描述了一种低通滤波程序，它改为计算每个像素周围图像值的众数估计。<sup>[13](https://doi.org/10.1117/12.957111)</sup> 中值滤波由迈克尔·卡斯（Michael Kass）和贾斯汀·所罗门（Justin Solomon）在2010年《ACM图形学汇刊》（ACM Transactions on Graphics）的一篇论文中描述为可能是图像处理领域最早受到关注的直方图相关图像滤波器；它与众数滤波器同属更广泛的非线性滤波器中的顺序统计与稳健估计家族。<sup>[14](https://doi.org/10.1145/1778765.1778837)</sup><sup> • </sup><sup>[10](https://web.eecs.utk.edu/~hqi/ece472-572/reference/order-statistics.pdf)</sup>

## 变体

命名的变体包括以下这些。

**截断中值滤波。** 众数滤波的一种早期实现，其成功推动了对众数滤波性能的进一步研究。<sup>[15](https://doi.org/10.1179/136821904225011537)</sup>

**彩色众数操作。** 有三种操作将局部直方图众数滤波扩展到多通道图像：用于边缘锐化、降噪和小目标移除的全局众数操作；用于在保留细节的同时滤除白噪声的约束众数操作；以及纳入测量确定性的不确定数据众数滤波。<sup>[11](http://cat.cvc.uab.es/~joost/papers/icip2001.pdf)</sup>

**主导众数滤波。** 由迈克尔·卡斯和贾斯汀·所罗门在《平滑局部直方图滤波》（Smoothed local histogram filters，《ACM图形学汇刊》，2010）中描述；它选择对应最大样本总体的样本群体，将基于直方图的局部滤波器扩展到中位数之外。<sup>[14](https://doi.org/10.1145/1778765.1778837)</sup>

**经验密度众数滤波。** 众数按经验密度的argmax计算，通过从多个受相邻像素影响的随机初始值出发进行牛顿-拉夫森迭代求解；结果是具有厚涂效果且边缘得到保持的平滑图像。<sup>[12](https://shermanlo77.github.io/mode_filter.html)</sup>

**细线保持众数滤波（THINLINE）。** 在Catalyst/PCI的FMO中，仅当中心像素值在其3×3窗口中出现的次数少于3次时才应用该滤波器，从而保留河流或道路等细薄类别；通过KEEPVALU最多可将16个类别值排除在滤波之外。<sup>[16](https://catalyst.earth/catalyst-system-files/professional-help/references/pciFunction_r/python/P_fmo.html)</sup>

**约束多数规则。** 仅当众数值的频率超过窗口的50%时才更新原始值。<sup>[2](https://enmap-box.readthedocs.io/en/latest/usr_section/usr_cookbook/generic_filter.html)</sup> GIS实践还允许使用由类别面积导出的不等并列权重、用户提供的权重，或带有偏置因子的晕圈邻域，使核外频率获得优先权。<sup>[17](https://cartogis.org/docs/proceedings/archive/auto-carto-13/pdf/data-quality-implications-of-raster-generalization.pdf)</sup>

## 应用

众数滤波用于灰度和彩色图像中的降噪，它在替换受损像素的同时保持锐利边缘。<sup>[18](https://ijarcce.com/wp-content/uploads/2022/03/IJARCCE.2022.11219.pdf)</sup> 其最清晰的用武之地是分类影像的后处理：该滤波器被描述为清理专题地图的理想选择，因为它将小“岛屿”主题替换为周围更大的主题<sup>[16](https://catalyst.earth/catalyst-system-files/professional-help/references/pciFunction_r/python/P_fmo.html)</sup>，并平滑分类结果以减少椒盐效应。<sup>[2](https://enmap-box.readthedocs.io/en/latest/usr_section/usr_cookbook/generic_filter.html)</sup> 在GIS栅格综合中，将核以每个像元为中心，核内的众数类别替换该像元的类别，较大的核产生更高程度的综合。<sup>[17](https://cartogis.org/docs/proceedings/archive/auto-carto-13/pdf/data-quality-implications-of-raster-generalization.pdf)</sup> 在显微成像中，对连续拍摄图像中同一位置的像素值取众数，在椒盐噪声和GIMP hurl噪声方面优于平均。<sup>[19](https://analyticalsciencejournals.onlinelibrary.wiley.com/doi/10.1002/jemt.21062)</sup>

## 局限与替代方案

**边缘偏移。** 一项关于失真的定量研究发现，众数滤波的边缘偏移特性与中值滤波相似，众数滤波在这方面没有特别优势。<sup>[7](https://digital-library.theiet.org/content/journals/10.1049/ip-vis_19990642)</sup> 对彩色图像也报告了相同结论。<sup>[15](https://doi.org/10.1179/136821904225011537)</sup>

**相对均值的噪声敏感性。** 局部众数近似比\( l_{2} \)均值滤波更好地保持不连续处，后者的模糊程度最大，但众数结果对噪声更敏感。<sup>[8](https://www.mia.uni-saarland.de/Publications/mrazek-spp1114-51.pdf)</sup> 该显微成像研究得出了互补的噪声类型划分：对于少数噪声像素且标准差较高的情况，如脉冲和椒盐噪声，众数更有效；而当许多像素以低标准差变化时，如高斯噪声，平均更有效；两种方法可以串行使用。<sup>[19](https://analyticalsciencejournals.onlinelibrary.wiley.com/doi/10.1002/jemt.21062)</sup>

**细薄特征丢失与专题误差。** 河流和道路等细薄类别会被普通众数滤波抹去，这促使了THINLINE选项的出现。<sup>[16](https://catalyst.earth/catalyst-system-files/professional-help/references/pciFunction_r/python/P_fmo.html)</sup> 在栅格综合中，专题误差集中在空间变异性最大的地方。<sup>[17](https://cartogis.org/docs/proceedings/archive/auto-carto-13/pdf/data-quality-implications-of-raster-generalization.pdf)</sup>

**在滤波器之间选择。** 对于类别或分类数据，[众数](https://www.edgepedia.org/zh/mode-statistics)滤波是自然的选择，因为此时中值滤波不可用<sup>[1](https://www.mathworks.com/help/images/ref/modefilt.html)</sup>；对于大多数像素正确、少数像素被偏移到其他值的污染，也是如此。<sup>[6](https://docs.openmv.io/v5.0.0/openmvcam/tutorial/image/filters/linear-neighborhood.html)</sup>

## References

1. [modefilt - 2-D and 3-D mode filtering - MATLAB](https://www.mathworks.com/help/images/ref/modefilt.html)
2. [Generic Filter (Majority), EnMAP-Box 3.14 documentation](https://enmap-box.readthedocs.io/en/latest/usr_section/usr_cookbook/generic_filter.html)
3. [ModeFilter Documentation - Albumentations](https://albumentations.ai/explore/transform/ModeFilter/docs/)
4. [mode - ISIS Application Documentation - USGS](https://isis.astrogeology.usgs.gov/10.0.0/Application/presentation/Tabbed/mode/mode.html)
5. [fmode: Quantize and box modal filter a list of 1D or 2D images](https://iraf.readthedocs.io/en/latest/tasks/images/imfilter/fmode.html)
6. [Linear and neighbourhood filters - OpenMV documentation](https://docs.openmv.io/v5.0.0/openmvcam/tutorial/image/filters/linear-neighborhood.html)
7. [Image distortions produced by mean, median and mode filters](https://digital-library.theiet.org/content/journals/10.1049/ip-vis_19990642)
8. [Kernels (Mrazek et al., Saarland University)](https://www.mia.uni-saarland.de/Publications/mrazek-spp1114-51.pdf)
9. [Mean, median and mode filtering of images](https://www.sciencedirect.com/science/article/abs/pii/S0031320399000558)
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 color images (ICIP 2001)](http://cat.cvc.uab.es/~joost/papers/icip2001.pdf)
12. [Mode Filter - Sherman Lo](https://shermanlo77.github.io/mode_filter.html)
13. [The Mode Filter: A Nonlinear Image Processing Operator](https://doi.org/10.1117/12.957111)
14. [Michael Kass, Justin Solomon (2010). Smoothed local histogram filters. ACM Transactions on Graphics.](https://doi.org/10.1145/1778765.1778837)
15. [Mode filters and their effectiveness for enhancing colour images](https://doi.org/10.1179/136821904225011537)
16. [FMO (mode filter), Catalyst/PCI Geomatics documentation](https://catalyst.earth/catalyst-system-files/professional-help/references/pciFunction_r/python/P_fmo.html)
17. [Data Quality Implications of Raster Generalization (Veregin and McMaster)](https://cartogis.org/docs/proceedings/archive/auto-carto-13/pdf/data-quality-implications-of-raster-generalization.pdf)
18. [Evaluation of Image Denoising Filters](https://ijarcce.com/wp-content/uploads/2022/03/IJARCCE.2022.11219.pdf)
19. [A new algorithm to reduce noise in microscopy images implemented with a simple program in python](https://analyticalsciencejournals.onlinelibrary.wiley.com/doi/10.1002/jemt.21062)

---
*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-filtering-image-processing

English original: https://www.edgepedia.org/mode-filtering-image-processing
