# 腐蚀（形态学）

**腐蚀**是[数学形态学](https://www.edgepedia.org/zh/mathematical-morphology)的两个基本算子之一，数学形态学是一种基于集合论和格代数的图像分析理论。用一个称为结构元（也称为核，在某些库中称为足迹）的小型探针作用于图像，腐蚀会缩小明亮或前景区域，并扩大黑暗或背景区域。腐蚀与其对偶算子膨胀一起，构成了开运算、闭运算以及大多数其他形态学滤波器的基础。<sup>[1](https://scikit-image.org/docs/stable/api/skimage.morphology.html?highlight=morphology)</sup><sup> • </sup><sup>[2](https://docs.opencv.org/5.0/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义（灰度） | 每个输出像素是结构元所定义邻域内的最小值；明亮区域缩小，黑暗区域扩大<sup>[1](https://scikit-image.org/docs/stable/api/skimage.morphology.html?highlight=morphology)</sup> |
| 定义（二值） | 前景像素仅当平移至该处的结构元完全位于前景内部时才保留；可计算为逻辑与<sup>[3](https://www.inf.u-szeged.hu/ssip/1996/morpho/morphology.html)</sup> |
| 集合论形式 | 集合B对集合A的腐蚀是所有满足“B平移x后包含于A”的点x的集合<sup>[3](https://www.inf.u-szeged.hu/ssip/1996/morpho/morphology.html)</sup> |
| 平坦元等价性 | 使用平坦结构元时，灰度腐蚀恰好是滑动最小值（最小秩）滤波器<sup>[4](https://www.oreilly.com/library/view/microscope-image-processing/9780080558547/chapter-104.html)</sup> |
| 导出运算 | 先腐蚀后膨胀得到开运算；先膨胀后腐蚀得到闭运算<sup>[5](https://www.sciencedirect.com/topics/computer-science/mathematical-morphology)</sup> |
| 起源 | 数学形态学由乔治·马瑟龙和让·塞拉于20世纪60年代中期在枫丹白露的巴黎矿业学院创立<sup>[6](https://livrepository.liverpool.ac.uk/3175097/1/399060.pdf)</sup> |
| 典型用途 | 去除噪声、分离或连接图像元素、寻找亮度凸起或孔洞，以及OCR之前的预处理<sup>[2](https://docs.opencv.org/5.0/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html)</sup> |

## 定义

形态学运算基于形状处理图像：一个结构元（通常远小于图像，常为3×3矩阵）在图像上滑动，每个位置的输出取决于该元素与局部模式的拟合方式。<sup>[2](https://docs.opencv.org/5.0/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html)</sup><sup> • </sup><sup>[3](https://www.inf.u-szeged.hu/ssip/1996/morpho/morphology.html)</sup> 该元素有一个锚点，通常是其中心，可以采用任意形状，不过方形和圆形较为常见。<sup>[2](https://docs.opencv.org/5.0/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html)</sup>

在二值情况下，图像仅区分前景和背景，集合B对集合A的腐蚀是所有满足“B平移x后仍包含于A”的点x的集合。实际操作中，逐个检查每个前景像素：如果该像素及其被结构元覆盖的所有邻域像素均为前景，则该像素保持前景；如果至少有一个被覆盖的邻域像素为背景，则该像素被设为背景。在8连通条件下使用3×3结构元，这不过是对邻域做逻辑与运算。<sup>[3](https://www.inf.u-szeged.hu/ssip/1996/morpho/morphology.html)</sup> 其效果是侵蚀前景区域的边界，使前景面积缩小，而其中的孔洞增大。<sup>[3](https://www.inf.u-szeged.hu/ssip/1996/morpho/morphology.html)</sup>

在灰度情况下，腐蚀将每个像素赋值为结构元所定义邻域内的最小值。OpenCV将该操作表示为

\[ \texttt{dst}(x,y) = \min_{(x',y'):\ \texttt{element}(x',y') \ne 0} \texttt{src}(x+x', y+y') \]

scikit-image的描述完全相同：位于(i, j)的像素被设为以(i, j)为中心的邻域内所有像素的最小值。<sup>[2](https://docs.opencv.org/5.0/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html)</sup><sup> • </sup><sup>[1](https://scikit-image.org/docs/stable/api/skimage.morphology.html?highlight=morphology)</sup> 明亮区域变细，黑暗区域变大。<sup>[2](https://docs.opencv.org/5.0/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html)</sup>

## 与最小值滤波器的关系及对偶性

对于平坦结构元——即在其定义域上取值均为零的结构元——灰度腐蚀退化为最小秩滤波器：它从邻域中选择排名最低的灰度级作为输出值。<sup>[4](https://www.oreilly.com/library/view/microscope-image-processing/9780080558547/chapter-104.html)</sup><sup> • </sup><sup>[7](https://www.cs.auckland.ac.nz/courses/compsci373s1c/PatricesLectures/2013/CS373-IP-02.pdf)</sup> 反之，使用平坦元的灰度膨胀是最大值滤波器，二者是对偶运算。<sup>[7](https://www.cs.auckland.ac.nz/courses/compsci373s1c/PatricesLectures/2013/CS373-IP-02.pdf)</sup> 用神经网络的术语来说，最小池化可以写为 \( \min_{b \in B} f(x+b) = -\max_{b \in B}\{-f(x+b)\} \)，因此腐蚀就是对负图像应用负最大池化。<sup>[8](https://wanghemath.github.io/Book-MathCV/chapters/chapter-09-morphology-and-shape.html)</sup>

腐蚀和膨胀是构建高阶运算的基本原语。开运算是先腐蚀后膨胀；它去除小的明亮特征而不扩大黑暗特征，可以消除噪声斑点并对物体进行尺寸滤波。闭运算是先膨胀后腐蚀；它增亮小的黑暗区域并能填充孔洞，同时保持初始区域尺寸。<sup>[5](https://www.sciencedirect.com/topics/computer-science/mathematical-morphology)</sup><sup> • </sup><sup>[3](https://www.inf.u-szeged.hu/ssip/1996/morpho/morphology.html)</sup><sup> • </sup><sup>[7](https://www.cs.auckland.ac.nz/courses/compsci373s1c/PatricesLectures/2013/CS373-IP-02.pdf)</sup> 顶帽变换定义为图像减去其开运算结果，它分离出被开运算去除的小尺度明亮细节，充当灰度级表面的峰值和脊线检测器。<sup>[7](https://www.cs.auckland.ac.nz/courses/compsci373s1c/PatricesLectures/2013/CS373-IP-02.pdf)</sup>

## 实现说明

各库的实现为腐蚀提供了若干实用控制参数。OpenCV的`cv::erode`接受一个结构元（未指定时默认为3×3矩形）、锚点位置、迭代次数和边界处理方式；它支持原地操作，并对多通道图像的每个通道独立处理。<sup>[9](https://docs.opencv.org/4.11.0/d4/d86/group__imgproc__filter.html)</sup> scikit-image的`erosion`接受一个足迹数组，默认为连通性为1的十字形足迹，以及边界模式如'reflect'、'constant'或'max'，用于确定图像域外像素的处理方式。<sup>[1](https://scikit-image.org/docs/stable/api/skimage.morphology.html?highlight=morphology)</sup>

实践中两个效率和正确性细节很重要。第一，足迹可以分解：先应用9×1足迹再应用1×9足迹与使用9×9足迹效果相同，但计算成本更低，内置足迹如`disk()`可以自动生成这样的序列。<sup>[1](https://scikit-image.org/docs/stable/api/skimage.morphology.html?highlight=morphology)</sup> 更一般地，对于矩形窗口，二维最小值滤波器可分离为两个一维滤波器，而一维最小值滤波器可以写成增量形式，使每像素计算复杂度为常数，与窗口尺寸无关。<sup>[10](https://cmp.felk.cvut.cz/cmp/courses/dzo/resources/course_ip_tudelft/course/fip-Morpholo.html)</sup> 第二，偶数尺寸的足迹没有唯一中心：在scikit-image中，对于此类足迹，`binary_erosion`和灰度`erosion`产生的输出相对彼此偏移一个像素，`pad_footprint()`的存在正是为了处理这一问题。<sup>[1](https://scikit-image.org/docs/stable/api/skimage.morphology.html?highlight=morphology)</sup>

## 应用

由于形态学算子与形状直接相关，在工业视觉中的物体或缺陷识别方面，它们往往比基于卷积的滤波器更有用，正如华盛顿大学的罗伯特·M·哈拉利克、斯坦利·R·斯滕伯格和庄新华在1987年发表于《IEEE模式分析与机器智能汇刊》的一篇被广泛引用的综述中所论述的，该综述涵盖二值和灰度腐蚀、膨胀、开运算和闭运算。<sup>[11](https://pubmed.ncbi.nlm.nih.gov/21869411/)</sup> 腐蚀和膨胀的常见用途包括去除噪声、分离图像中的单个元素或连接不同元素，以及寻找亮度凸起或孔洞；它们也用作光学字符识别之前的预处理步骤。<sup>[2](https://docs.opencv.org/5.0/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html)</sup>

腐蚀也出现在现代流程中。在医学图像分析中，二值形态学运算被应用于分割后的图像，结构元在二值图像上滑动以清理结果。<sup>[12](https://www.ncbi.nlm.nih.gov/books/NBK546156/)</sup> 1989年的一篇论文描述了一种实时光学架构，实现了用于工业检测的腐蚀、开运算、闭运算和骨架化，并展示了腐蚀和开运算的首批实时光学实验室结果，用于定位烟草中的细绳。<sup>[13](https://pubmed.ncbi.nlm.nih.gov/20556052/)</sup> 最近，有人提出了形态学网络，使用可训练的结构元通过一系列腐蚀和膨胀算子来模拟经典形态学滤波，应用于图像去雨等任务。<sup>[14](https://arxiv.org/abs/1901.02411)</sup>

## 历史

数学形态学——腐蚀是其基本算子之一——由乔治·马瑟龙和让·塞拉于20世纪60年代中期在[枫丹白露](https://www.edgepedia.org/zh/fontainebleau)的巴黎矿业学院创立，源于与采矿相关的图像分析研究。<sup>[6](https://livrepository.liverpool.ac.uk/3175097/1/399060.pdf)</sup><sup> • </sup><sup>[15](https://link.springer.com/chapter/10.1007/978-3-319-78999-6_35)</sup> 基本算子最初基于集合论为二值图像开发，受到闵可夫斯基和哈德维格尔工作的启发，后来使用局部最小和最大算子扩展到灰度图像。<sup>[16](https://www.sciencedirect.com/science/article/abs/pii/B9780124077027000024)</sup> 德克萨斯A&M大学的爱德华·R·多尔蒂指出，腐蚀、膨胀、开运算和闭运算这些基本操作是每个图像处理工具箱的一部分，而最初在欧几里得集合上表述的代数理论，此后通过用序关系替代子集关系，已扩展到实值函数和格值函数。<sup>[17](https://doi.org/10.1002/0471443395.IMG069)</sup>

## References

1. [skimage.morphology API documentation, scikit-image 0.26.0](https://scikit-image.org/docs/stable/api/skimage.morphology.html?highlight=morphology)
2. [Eroding and Dilating, OpenCV Tutorials](https://docs.opencv.org/5.0/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html)
3. [Morphological Operations: An overview, SSIP 1996, University of Szeged](https://www.inf.u-szeged.hu/ssip/1996/morpho/morphology.html)
4. [Grayscale Erosion and Dilation, Microscope Image Processing (Elsevier)](https://www.oreilly.com/library/view/microscope-image-processing/9780080558547/chapter-104.html)
5. [Mathematical Morphology, ScienceDirect Topics overview](https://www.sciencedirect.com/topics/computer-science/mathematical-morphology)
6. [Origin and historical notes of mathematical morphology, University of Liverpool thesis](https://livrepository.liverpool.ac.uk/3175097/1/399060.pdf)
7. [Basics of Mathematical Morphology, lecture slides, University of Auckland CS373](https://www.cs.auckland.ac.nz/courses/compsci373s1c/PatricesLectures/2013/CS373-IP-02.pdf)
8. [Morphology and Shape, The Mathematics of Modern Computer Vision](https://wanghemath.github.io/Book-MathCV/chapters/chapter-09-morphology-and-shape.html)
9. [cv::erode, OpenCV Image Filtering API documentation](https://docs.opencv.org/4.11.0/d4/d86/group__imgproc__filter.html)
10. [Morphology-based Operations, Image Processing Fundamentals, CTU Prague](https://cmp.felk.cvut.cz/cmp/courses/dzo/resources/course_ip_tudelft/course/fip-Morpholo.html)
11. [Haralick, R. M., Sternberg, S. R., Zhuang, X. (1987). Image analysis using mathematical morphology. IEEE TPAMI 9(4), 532–550.](https://pubmed.ncbi.nlm.nih.gov/21869411/)
12. [Image Processing, Medical Imaging Systems, NCBI Bookshelf](https://www.ncbi.nlm.nih.gov/books/NBK546156/)
13. [Botha, E., Richards, J., Casasent, D. P. (1989). Optical laboratory morphological inspection processor. Applied Optics 28(24), 5342–5350.](https://pubmed.ncbi.nlm.nih.gov/20556052/)
14. [Morphological Networks for Image De-raining, arXiv:1901.02411](https://arxiv.org/abs/1901.02411)
15. [Mathematical Morphology in Geosciences and GISci: An Illustrative Review, Springer](https://link.springer.com/chapter/10.1007/978-3-319-78999-6_35)
16. [Representations for Morphological Image Operators and Analogies with Linear Operators, ScienceDirect](https://www.sciencedirect.com/science/article/abs/pii/B9780124077027000024)
17. [Dougherty, E. R. Foundations of Morphological Image Processing, Wiley Encyclopedia of Imaging](https://doi.org/10.1002/0471443395.IMG069)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: 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/erosion-morphology

English original: https://www.edgepedia.org/erosion-morphology
