# 分水岭算法

分水岭算法是数学形态学中的一种图像分割方法，它将像素强度视为地形起伏的高程，通过从种子点开始对地形进行泛洪，把图像划分为被分水岭线隔开的集水盆地。<sup>[1](https://scikit-image.org/docs/stable/auto_examples/segmentation/plot_watershed.html)</sup> 在实践中，它被应用于梯度图像。<sup>[2](https://pure.rug.nl/ws/files/127130790/parwshed.pdf)</sup> 该方法无需阈值或参数化边缘拟合即可生成闭合轮廓，至今仍是生物、医学和材料成像中分离相互接触物体的标准工具。<sup>[3](https://people.cmm.minesparis.psl.eu/users/beucher/publi/watershed.pdf)</sup>

| 关键事实 | 数值或陈述 | 来源 |
|---|---|---|
| 输出 | 对集水盆地的标记划分；不同标记的盆地相遇处的像素构成分水岭线 | <sup>[1](https://scikit-image.org/docs/stable/auto_examples/segmentation/plot_watershed.html)</sup> |
| 核心类比 | 集水盆地是从中一滴水会流向给定极小值的点集；重叠盆地的共享点构成分水岭 | <sup>[3](https://people.cmm.minesparis.psl.eu/users/beucher/publi/watershed.pdf)</sup> |
| 泛洪算法的复杂度 | 使用分层队列时，在图像元素数量上为 \( O(N) \)，但不同实现的运行时间相差数个数量级 | <sup>[4](https://www.mdpi.com/2313-433X/8/5/127)</sup> |
| 过分割 | 从梯度的所有区域极小值泛洪会产生过多盆地；标记是标准补救手段 | <sup>[5](https://perso.telecom-paristech.fr/bloch/ANIM/CorpsCalleux/Meyer1994.pdf)</sup> |
| 图论表述 | 边加权图上的分水岭割与最小生成森林割重合，将该方法与克鲁斯卡尔算法联系起来 | <sup>[6](https://doi.org/10.1109/tpami.2008.173)</sup> |
| 应用领域 | 遥感、医学成像、生物成像和材料科学 | <sup>[7](https://link.springer.com/article/10.1007/s10851-026-01347-0)</sup> |

## 工作原理

图像被解读为地形起伏。<sup>[3](https://people.cmm.minesparis.psl.eu/users/beucher/publi/watershed.pdf)</sup> 水滴定义将每个极小值与所有下降路径抵达该极小值的点集相关联；当多个极小值的盆地重叠时，它们的公共点构成分水岭线。<sup>[3](https://people.cmm.minesparis.psl.eu/users/beucher/publi/watershed.pdf)</sup> 等价的泛洪图景是在每个区域极小值处放置一个水源，让所有洪水以均匀速度上涨，并在两股洪水相遇处筑起水坝；所有水坝的并集即为分水岭线。<sup>[5](https://perso.telecom-paristech.fr/bloch/ANIM/CorpsCalleux/Meyer1994.pdf)</sup>

形式上，泛洪可以用阈值集来书写：从最低水平集 \( X_{h_{\min}} \) 开始，每一步将下一个阈值与前一个集合的影响区域取并，\( X_{h+1} = \min_{h+1} \cup \, \mathrm{IZ}_{T_{h+1}}(X_h) \)；与两个不同盆地相邻的像素被标记为分水岭节点。<sup>[2](https://pure.rug.nl/ws/files/127130790/parwshed.pdf)</sup> 迈耶利用地形距离给出了严格定义，地形距离是最陡下降路径的长度，以下斜率加权；极小值的集水盆地是在此距离下距该极小值比距任何其他极小值都更近的点集，由此产生迪杰斯特拉型最短路径算法。<sup>[5](https://perso.telecom-paristech.fr/bloch/ANIM/CorpsCalleux/Meyer1994.pdf)</sup>

## 实现方法

典型的标记控制流程如下。首先，计算梯度（通常是形态学梯度），使物体边界呈现为脊线。<sup>[2](https://pure.rug.nl/ws/files/127130790/parwshed.pdf)</sup> 其次，选择标记：每个物体内部一个，背景一个。<sup>[5](https://perso.telecom-paristech.fr/bloch/ANIM/CorpsCalleux/Meyer1994.pdf)</sup> 第三，修改地形使其仅有的极小值为标记，方法是将梯度 \( g \) 替换为重构 \( g' \)，其中标记像素置为0；经过这种同伦修改后，任何分水岭算法都可应用。<sup>[5](https://perso.telecom-paristech.fr/bloch/ANIM/CorpsCalleux/Meyer1994.pdf)</sup> 第四，泛洪：浸没算法按灰度值递增对像素排序，并通过先进先出队列泛洪平台，<sup>[8](https://doi.org/10.1109/34.87344)</sup> 而基于距离的版本使用分层队列或优先队列；scikit-image的队列按像素值然后按入队时间排序，平局时偏向最近的标记。<sup>[9](https://github.com/scikit-image/scikit-image/blob/v0.17.2/skimage/segmentation/_watershed.py)</sup> 在OpenCV中，用户用正整数标记确定前景，用另一个标签标记确定背景，用0标记未知区域；执行`cv.watershed`后，边界像素被标记为-1。<sup>[10](https://docs.opencv.org/5.0/py_tutorials/py_imgproc/py_watershed/py_watershed.html)</sup>

基于泛洪的实现通常在使用分层队列时达到计算复杂度 \( O(N) \)，其中 \( N \) 为图像元素数量，尽管优先队列变体以 \( O(N \log N) \) 时间运行，<sup>[19](https://richard.science/sci/2014_depressions.pdf)</sup> 但处理速度强烈依赖于数据结构、语言和优化；已发表的标记控制实现在体图像上的基准测试发现执行时间差异达数个数量级。<sup>[4](https://www.mdpi.com/2313-433X/8/5/127)</sup> 文森特–索伊浸没算法以像素数量的线性时间运行。<sup>[2](https://pure.rug.nl/ws/files/127130790/parwshed.pdf)</sup>

## 起源

[枫丹白露](https://www.edgepedia.org/zh/fontainebleau)地质统计学与数学形态学中心的一篇研讨会论文将轮廓定义为灰度函数梯度模的分水岭，并将该方法表述为非参数的，无需阈值且产生闭合轮廓；其两个示例是射线照相板中的气泡检测和钢断裂中的刻面检测。<sup>[3](https://people.cmm.minesparis.psl.eu/users/beucher/publi/watershed.pdf)</sup> 已发表的记述对变换本身的起点存在分歧：文森特和索伊1991年的论文指出，作为形态学工具的分水岭变换归功于H. 迪加贝尔和Ch. 朗图埃茹尔，其数据是表示沥青表面地形在逐次阈值下的二值图像堆叠，灰度扩展归功于伯谢和朗图埃茹尔，<sup>[8](https://doi.org/10.1109/34.87344)</sup> 而迈耶的历史记述将1979年的论文视为分割分水岭概念的起源。<sup>[5](https://perso.telecom-paristech.fr/bloch/ANIM/CorpsCalleux/Meyer1994.pdf)</sup> 两种归属在此并列报告，不作裁定。L. 文森特和P. 索伊的高效浸没模拟算法于1991年发表在《[IEEE模式分析与机器智能汇刊](https://www.edgepedia.org/zh/ieee-transactions-on-pattern-analysis-and-machine-intelligence)》上，使该变换在普通计算机上变得实用，<sup>[8](https://doi.org/10.1109/34.87344)</sup> 综述将算法浸没定义追溯到该论文。<sup>[11](https://sci2s.ugr.es/sites/default/files/ficherosPublicaciones/2344_10.1007-978-3-319-62359-7_12.pdf)</sup> 费尔南·迈耶1994年发表在《信号处理》上的论文提供了地形距离定义，<sup>[5](https://perso.telecom-paristech.fr/bloch/ANIM/CorpsCalleux/Meyer1994.pdf)</sup> 洛朗·纳伊曼和米歇尔·施密特1994年的《信号处理》论文将定义扩展到连续平面，并证明了伯谢–朗图埃茹尔构造的收敛性。<sup>[12](https://doi.org/10.1016/0165-1684%2894%2990059-0)</sup>

## 变体

**基于标记与无种子。** 从所有区域极小值泛洪会产生严重的过分割，因为虚假极小值众多；标记策略仅从选定源泛洪，成为主流的形态学分割范式。<sup>[5](https://perso.telecom-paristech.fr/bloch/ANIM/CorpsCalleux/Meyer1994.pdf)</sup> 在噪声梯度上的无种子分水岭给出过分割结果。<sup>[10](https://docs.opencv.org/5.0/py_tutorials/py_imgproc/py_watershed/py_watershed.html)</sup>

**算法族。** 最短路径算法为各种距离函数构建影响区域；基于细化的算法迭代降低像素值直到留下分水岭。拓扑分水岭通过W-可破坏点定义：W-细化将此类点降低一，直到没有剩余，两点之间的通过值是连接这两点的所有路径各自最大值中的最小值。<sup>[13](https://perso.esiee.fr/~dpt-it/tw/ismm05ncb.pdf)</sup>

**分水岭割。** 在边加权图上，分水岭割是连接两个不同盆地的边集。<sup>[14](https://minesparis-psl.hal.science/hal-01111752/document)</sup> J. 库斯蒂、G. 贝特朗、L. 纳伊曼和M. 库普里在2009年《IEEE模式分析与机器智能汇刊》论文中证明了两个核心结果：一个割是分水岭割当且仅当每个点都有到极小值的最陡下降路径（水滴原理），一组边是分水岭割当且仅当它是针对极小值的最小生成森林割；边界细化变换可在不排序的情况下以线性时间计算此类割，无论输入图的值域如何。<sup>[6](https://doi.org/10.1109/tpami.2008.173)</sup> 最小生成树等价性将该方法与[克鲁斯卡尔算法](https://www.edgepedia.org/zh/kruskals-algorithm)联系起来，并支持基于标记的和分层计算。<sup>[7](https://link.springer.com/article/10.1007/s10851-026-01347-0)</sup>

**分层分水岭与瀑布。** 瀑布对盆地图应用分水岭变换，主要用于应对无监督分割中的过分割；它是非参数的，但继承了底层变换的缺陷。<sup>[15](https://people.cmm.minesparis.psl.eu/users/beucher/publi/P-Algorithm_SB_BM.pdf)</sup> 在一般分层分水岭中，极小值按消亡值（如面积或体积）排序，可从按高度排序的二叉划分树以线性时间获得。<sup>[7](https://link.springer.com/article/10.1007/s10851-026-01347-0)</sup>

## 应用

经典用途是分离相互接触或重叠的物体以进行实例分割，通常将[距离变换](https://www.edgepedia.org/zh/distance-transform)与分水岭结合。<sup>[10](https://docs.opencv.org/5.0/py_tutorials/py_imgproc/py_watershed/py_watershed.html)</sup> 在细胞和细胞核计数中，深度学习增强的标记控制分水岭被描述为近期流行的自动3D细胞核分割方法，其中CNN创建细胞核掩膜和标记，深度为 \( h \) 的H极小值变换抑制距离变换中的弱局部极小值以减少过分割，分水岭执行[实例分割](https://www.edgepedia.org/zh/instance-segmentation)。<sup>[16](https://pmc.ncbi.nlm.nih.gov/articles/PMC9306214/)</sup> 已记录的应用领域包括遥感、医学成像、生物成像和材料科学，<sup>[7](https://link.springer.com/article/10.1007/s10851-026-01347-0)</sup> 以及从3D X射线CT中提取孔隙网络、染色体核型分析、OCT中视网膜黑色素颗粒分割和活细胞荧光显微镜。<sup>[4](https://www.mdpi.com/2313-433X/8/5/127)</sup>

## 局限与替代方案

**过分割**是主要失效模式：计算原始梯度的分水岭大多导致正确轮廓淹没在大量无关轮廓中，<sup>[8](https://doi.org/10.1109/34.87344)</sup> 因为许多局部极小值产生许多小盆地；标记和分层分水岭是标准补救手段。<sup>[2](https://pure.rug.nl/ws/files/127130790/parwshed.pdf)</sup> **顺序泛洪偏差**是第二个问题：按顺序处理同一层级的排队像素会引入变形，变形可增长到任意大小，并使分水岭线非唯一。<sup>[17](https://www.ipol.im/pub/art/2022/215/article.pdf)</sup> **线放置精度**取决于邻域大小：较大的倒角邻域更精确地放置线，在马瑟隆具有准平行分水岭线的严格测试模型下，大多数一阶邻域算法都失败，倒角算法除外。<sup>[5](https://perso.telecom-paristech.fr/bloch/ANIM/CorpsCalleux/Meyer1994.pdf)</sup> 在学习型替代方案中，深度分水岭变换训练网络预测分水岭能量本身，使每个盆地对应单个实例，所有分界脊位于同一高度，从而允许通过单层割提取实例，运行时间恒定，与实例数量无关。<sup>[18](https://openaccess.thecvf.com/content_cvpr_2017/papers/Bai_Deep_Watershed_Transform_CVPR_2017_paper.pdf)</sup>

## References

1. [Watershed segmentation, skimage documentation](https://scikit-image.org/docs/stable/auto_examples/segmentation/plot_watershed.html)
2. [The Watershed Transform: Definitions, Algorithms and Parallelization Strategies (Roerdink & Meijster, Fundamenta Informaticae)](https://pure.rug.nl/ws/files/127130790/parwshed.pdf)
3. [Use of Watersheds in Contour Detection (Beucher & Lantuéjoul, 1979)](https://people.cmm.minesparis.psl.eu/users/beucher/publi/watershed.pdf)
4. [A Review of Watershed Implementations for Segmentation of Volumetric Images (J. Imaging, MDPI)](https://www.mdpi.com/2313-433X/8/5/127)
5. [Topographic distance and watershed lines (F. Meyer, Signal Processing 38, 1994, 113-125)](https://perso.telecom-paristech.fr/bloch/ANIM/CorpsCalleux/Meyer1994.pdf)
6. [J. Cousty and colleagues (2009). Watershed Cuts: Minimum Spanning Forests and the Drop of Water Principle. IEEE Transactions on Pattern Analysis and Machine Intelligence.](https://doi.org/10.1109/tpami.2008.173)
7. [Playing with Kruskal: A State-of-the-Art Report on Watershed Cuts (J. Mathematical Imaging and Vision)](https://link.springer.com/article/10.1007/s10851-026-01347-0)
8. [L. Vincent, P. Soille (1991). Watersheds in digital spaces: an efficient algorithm based on immersion simulations. IEEE Transactions on Pattern Analysis and Machine Intelligence.](https://doi.org/10.1109/34.87344)
9. [skimage/segmentation/_watershed.py source](https://github.com/scikit-image/scikit-image/blob/v0.17.2/skimage/segmentation/_watershed.py)
10. [Image Segmentation with Watershed Algorithm, OpenCV Tutorials](https://docs.opencv.org/5.0/py_tutorials/py_imgproc/py_watershed/py_watershed.html)
11. [An Updated Review on Watershed Algorithms (Springer book chapter)](https://sci2s.ugr.es/sites/default/files/ficherosPublicaciones/2344_10.1007-978-3-319-62359-7_12.pdf)
12. [Watershed of a continuous function (Signal Processing, 1994)](https://doi.org/10.1016/0165-1684%2894%2990059-0)
13. [Watersheds and Mosaic Images (Couprie & Bertrand, ISMM 2005)](https://perso.esiee.fr/~dpt-it/tw/ismm05ncb.pdf)
14. [Watersheds on weighted graphs (F. Meyer)](https://minesparis-psl.hal.science/hal-01111752/document)
15. [Waterfall algorithm paper (Beucher and Meyer, CMM)](https://people.cmm.minesparis.psl.eu/users/beucher/publi/P-Algorithm_SB_BM.pdf)
16. [Marker-controlled watershed with deep edge emphasis and optimized H-minima transform for automatic segmentation of densely cultivated 3D cell nuclei](https://pmc.ncbi.nlm.nih.gov/articles/PMC9306214/)
17. [A Parallel, O(n) Algorithm for an Unbiased, Thin Watershed (IPOL 2022)](https://www.ipol.im/pub/art/2022/215/article.pdf)
18. [Deep Watershed Transform for Instance Segmentation (CVPR 2017)](https://openaccess.thecvf.com/content_cvpr_2017/papers/Bai_Deep_Watershed_Transform_CVPR_2017_paper.pdf)
19. [2014 depressions (richard.science)](https://richard.science/sci/2014_depressions.pdf)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026; Oct 25, 2026 · Last review: Sep 30, 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/watershed-algorithm

English original: https://www.edgepedia.org/watershed-algorithm
