# Canny边缘检测

Canny边缘检测是一种多阶段图像处理算法，通过高斯滤波平滑、计算梯度幅值、非极大值抑制细化、以及滞后阈值连接来检测数字图像中的边缘。其输出是一幅细薄的二值边缘像素图。<sup>[1](https://doi.org/10.1109/tpami.1986.4767851)</sup><sup> • </sup><sup>[2](https://www.mdpi.com/2227-7390/13/15/2464)</sup>

| 关键事实 | 详情 |
|---|---|
| 提出者 | John Canny，《边缘检测的计算方法》，IEEE TPAMI，1986<sup>[1](https://doi.org/10.1109/tpami.1986.4767851)</sup> |
| 输出 | 单像素宽边缘点的二值边缘图<sup>[2](https://www.mdpi.com/2227-7390/13/15/2464)</sup> |
| 流程 | 高斯平滑、梯度幅值与方向、非极大值抑制、滞后双阈值<sup>[3](http://vision.stanford.edu/teaching/cs131_fall1516/lectures/lecture5_edges_cs131.pdf)</sup> |
| 阈值经验法则 | 高低阈值比约为二比一或三比一<sup>[4](https://www.cse.ust.hk/~quan/comp5421/notes/canny1986.pdf)</sup> |
| 关键参数 | 高斯sigma：大sigma抑制噪声但降低边缘定位精度<sup>[5](https://www.ijsr.net/archive/v3i11/T0NUMTQxMTQw.pdf)</sup> |
| 主要变体 | Deriche于1987年提出的递归IIR实现，每像素计算成本恒定，与滤波器尺度无关<sup>[6](https://doi.org/10.1007/bf00123164)</sup> |
| 硬件速度 | 在100 MHz的FPGA上处理512 × 512图像耗时0.721 ms<sup>[5](https://www.ijsr.net/archive/v3i11/T0NUMTQxMTQw.pdf)</sup> |

## 工作原理

该检测器围绕Canny为边缘算子明确提出的三条准则设计：良好检测，即能够定位并标记所有真实边缘；良好定位，即检测到的边缘与真实边缘之间距离最小；清晰响应，即每条边缘只产生一个响应。<sup>[7](https://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MARBLE/low/edges/canny.htm)</sup> Canny将这些准则表述为算子冲激响应上的泛函，并加入第三条准则以确保单条边缘只产生单一响应。<sup>[4](https://www.cse.ust.hk/~quan/comp5421/notes/canny1986.pdf)</sup>

由此得到的最优算子可由高斯函数的一阶导数很好地近似。<sup>[4](https://www.cse.ust.hk/~quan/comp5421/notes/canny1986.pdf)</sup>

单响应准则在实践中通过两个后处理操作来满足：非极大值抑制和滞后阈值处理。<sup>[8](https://cv.inf.elte.hu/wp-content/uploads/2025/03/lec03_edge.pdf)</sup> 滞后处理减少了断裂现象，即轮廓碎裂为不连续片段的问题：如果轮廓的任一部分超过高阈值，则这些点连同低阈值以上的整个连通段一起输出，因此轮廓必须在高阈值以上和低阈值以下之间波动才会断裂。<sup>[4](https://www.cse.ust.hk/~quan/comp5421/notes/canny1986.pdf)</sup>

## 实现方法

标准流程按以下顺序执行：<sup>[3](http://vision.stanford.edu/teaching/cs131_fall1516/lectures/lecture5_edges_cs131.pdf)</sup>

1. **平滑**：用高斯核 \( G_{\sigma}(x, y) = \frac{1}{2 \pi \sigma^{2}} e^{-\frac{x^{2} + y^{2}}{2 \sigma^{2}}} \) 对图像进行平滑，得到 \( I_{\sigma} = I * G_{\sigma} \)。<sup>[2](https://www.mdpi.com/2227-7390/13/15/2464)</sup>
2. **微分**：在x和y方向上求导，计算梯度幅值（各导数平方和的平方根）及梯度角度。<sup>[9](https://www.intel.com/content/www/us/en/docs/ipp/developer-guide-reference/2022-1/canny-edge-detector.html)</sup><sup> • </sup><sup>[10](https://www.cecs.uci.edu/~doemer/publications/CECS_TR_12_13.pdf)</sup>
3. **非极大值抑制**：在幅值数组上滑动3 × 3邻域，若中心像素沿梯度方向不大于其两个邻居，则将其设为零，梯度方向取整到最接近的45度整数倍。这将多像素宽的脊线细化至单像素宽度。<sup>[9](https://www.intel.com/content/www/us/en/docs/ipp/developer-guide-reference/2022-1/canny-edge-detector.html)</sup><sup> • </sup><sup>[11](http://vision.stanford.edu/teaching/cs131_fall1718/files/06_notes.pdf)</sup>
4. **应用滞后阈值**：高于高阈值 \( T_{\mathrm{high}} \) 的像素被接受为强边缘；低于低阈值 \( T_{\mathrm{low}} \) 的像素被拒绝；中间像素仅当通过一条高于 \( T_{\mathrm{low}} \) 的像素路径连接到已接受像素时才被接受。高阈值启动边缘曲线，低阈值延续边缘曲线。<sup>[4](https://www.cse.ust.hk/~quan/comp5421/notes/canny1986.pdf)</sup><sup> • </sup><sup>[9](https://www.intel.com/content/www/us/en/docs/ipp/developer-guide-reference/2022-1/canny-edge-detector.html)</sup><sup> • </sup><sup>[12](https://www.cs.umd.edu/class/fall2019/cmsc426-0201/files/11_CannyEdgeDetection.pdf)</sup>

Canny基于预测信噪比推荐高低阈值比在二比一到三比一之间。<sup>[4](https://www.cse.ust.hk/~quan/comp5421/notes/canny1986.pdf)</sup><sup> • </sup><sup>[7](https://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MARBLE/low/edges/canny.htm)</sup> sigma的选择决定了分析尺度：大sigma检测大尺度边缘，小sigma检测精细特征。<sup>[3](http://vision.stanford.edu/teaching/cs131_fall1516/lectures/lecture5_edges_cs131.pdf)</sup> 大sigma提高了抗噪性，但削弱了检测器定位真实边缘的能力，选择合适的sigma是经典算法公认的难点。<sup>[5](https://www.ijsr.net/archive/v3i11/T0NUMTQxMTQw.pdf)</sup><sup> • </sup><sup>[13](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0319852)</sup>

参考实现将整个流程封装为一次调用。OpenCV的`cv.Canny()`接受输入图像、`minVal`和`maxVal`阈值、Sobel `aperture_size`（默认3）以及选择梯度幅值公式的`L2gradient`标志。<sup>[14](https://docs.opencv.org/4.13.0/da/d22/tutorial_py_canny.html)</sup>

## 起源

该方法由[John Canny](https://www.edgepedia.org/zh/john-canny)在《边缘检测的计算方法》中提出，发表于1986年的IEEE TPAMI。<sup>[1](https://doi.org/10.1109/tpami.1986.4767851)</sup> Canny对受高斯噪声污染的理想阶跃边缘进行了建模。<sup>[7](https://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MARBLE/low/edges/canny.htm)</sup>

一年后，Rachid Deriche在《利用Canny准则推导递归实现的最优边缘检测器》中重新表述了该检测器，发表于1987年的[International Journal of Computer Vision](https://www.edgepedia.org/zh/international-journal-of-computer-vision)。<sup>[6](https://doi.org/10.1007/bf00123164)</sup>

推导本身受到了质疑。2011年International Journal of Computer Vision上的一篇论文《重新审视Canny边缘检测器》指出，Canny对定位准则的推导是错误的，并且除非考虑相邻边缘效应，Canny准则会产生一个无限宽的最优边缘检测器。<sup>[15](https://dl.acm.org/doi/10.1007/s11263-010-0392-0)</sup>

## 变体

Deriche的递归变体用两个方向相反的递归滤波器实现最优滤波器，每像素仅需五次乘法和五次加法，与邻域大小无关。<sup>[16](https://web.archive.org/web/20180607233447/https:/link.springer.com/article/10.1007/BF00123164)</sup> 滤波器的尺度可通过改变单个参数来调整而不影响执行时间，这使得恒定计算成本下的多尺度边缘检测成为可能；定位与输出信噪比之间的权衡也通过改变该单一参数来实现。<sup>[16](https://web.archive.org/web/20180607233447/https:/link.springer.com/article/10.1007/BF00123164)</sup>

并非所有实现都遵循一阶导数流程。ITK的`CannyEdgeDetectionRecursiveGaussianImageFilter`遵循Canny 1986年论文的四步流程：高斯平滑、计算二阶方向导数、对二阶导数的过零点进行非极大值抑制（利用三阶导数的符号寻找正确的极值点）、以及对梯度幅值进行滞后阈值处理。<sup>[17](https://docs.itk.org/projects/doxygen/en/v5.0.0/classitk_1_1CannyEdgeDetectionRecursiveGaussianImageFilter.html)</sup>

## 应用

该算法易于并行化且适合硬件移植。结合两种并行策略，对于2048 × 2048图像，相比串行执行可获得33倍加速，相比仅使用16核可获得最高3倍加速。<sup>[18](https://hvg.ece.concordia.ca/Publications/Conferences/NEWCAS12-3.pdf)</sup> 在Xilinx Virtex-5上基于块的Split Canny FPGA实现在100 MHz下以0.721 ms检测512 × 512图像的边缘，占用64%的切片和87%的BRAM。<sup>[5](https://www.ijsr.net/archive/v3i11/T0NUMTQxMTQw.pdf)</sup>

学习型边缘检测器以Canny作为经典对比基准：2024年利用二阶导数信息进行清晰边缘检测的工作将Canny描述为一种鲁棒算法，并将其作为经典基线。<sup>[19](https://arxiv.org/pdf/2406.05779v5.pdf)</sup>

## 局限与替代方案

该检测器的主要弱点在于其手工调参和交叉点处的行为。与学习方法相比，它对人工调校的 \( \sigma \)、\( T_{\mathrm{low}} \) 和 \( T_{\mathrm{high}} \) 的依赖限制了其对变化图像条件的适应性，尽管它相比Sobel算子具有更好的噪声鲁棒性和边缘连续性。<sup>[2](https://www.mdpi.com/2227-7390/13/15/2464)</sup> 手动设置的双阈值可能在检测结果中留下虚假边缘，非极大值抑制步骤会抑制位于X形、Y形和星形边缘交叉点处的真实边缘像素，因此实际检测结果中交叉边缘会丢失。<sup>[13](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0319852)</sup>

在其他经典算子的对比中，一张比较表将基于一阶导数局部极值的Canny评为检测最佳、定位和单响应良好；Sobel定位差且边缘粗，而基于二阶导数过零点的Marr–Hildreth高斯拉普拉斯算子在三条准则上均表现良好但会平滑角点。<sup>[20](https://www.cs.ubc.ca/~aerion1/425_2025W2/Lecture9.pdf)</sup>

2023年底以来的研究集中在修复经典方法的弱点上。2025年的一种检测器用多尺度自动各向异性形态学高斯核替代Canny的各向同性高斯核，在椒盐噪声、高斯噪声和散斑噪声下均优于Canny，且优势随噪声水平降低而增大。<sup>[13](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0319852)</sup> 自动阈值选择仍是一个活跃课题，2025年的一篇论文提出了Canny边缘检测器的自适应阈值方法，其技术脉络从基于滤波和统计的方法一直延伸到基于CNN的边缘检测。<sup>[21](https://www.mdpi.com/2076-3417/15/22/12158)</sup>

## References

1. [John Canny (1986). A Computational Approach to Edge Detection. IEEE Transactions on Pattern Analysis and Machine Intelligence.](https://doi.org/10.1109/tpami.1986.4767851)
2. [A Mathematical Survey of Image Deep Edge Detection Algorithms: From Convolution to Attention (MDPI Mathematics, 2025)](https://www.mdpi.com/2227-7390/13/15/2464)
3. [Stanford CS131 Lecture 5: Edge Detection](http://vision.stanford.edu/teaching/cs131_fall1516/lectures/lecture5_edges_cs131.pdf)
4. [A Computational Approach to Edge Detection (Canny, 1986)](https://www.cse.ust.hk/~quan/comp5421/notes/canny1986.pdf)
5. [A Split Canny Edge Detection: Algorithm and its FPGA Implementation](https://www.ijsr.net/archive/v3i11/T0NUMTQxMTQw.pdf)
6. [Rachid Deriche (1987). Using Canny's criteria to derive a recursively implemented optimal edge detector. International Journal of Computer Vision.](https://doi.org/10.1007/bf00123164)
7. [CVonline: The Canny Edge Detector](https://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MARBLE/low/edges/canny.htm)
8. [Basic Algorithms for Digital Image Analysis (lecture notes, ELTE)](https://cv.inf.elte.hu/wp-content/uploads/2025/03/lec03_edge.pdf)
9. [Canny Edge Detector, Intel IPP Developer Guide](https://www.intel.com/content/www/us/en/docs/ipp/developer-guide-reference/2022-1/canny-edge-detector.html)
10. [System-Level Modeling and Refinement of a Canny Edge Detector (UCI)](https://www.cecs.uci.edu/~doemer/publications/CECS_TR_12_13.pdf)
11. [Lecture #06: Edge Detection, Stanford CS131 notes](http://vision.stanford.edu/teaching/cs131_fall1718/files/06_notes.pdf)
12. [Canny Edge Detection, CMSC426 lecture notes (University of Maryland)](https://www.cs.umd.edu/class/fall2019/cmsc426-0201/files/11_CannyEdgeDetection.pdf)
13. [Noise-Robust image edge detection based on multi-scale automatic anisotropic morphological Gaussian Kernels (PLOS One, 2025)](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0319852)
14. [Canny Edge Detection, OpenCV Python tutorial](https://docs.opencv.org/4.13.0/da/d22/tutorial_py_canny.html)
15. [The Canny Edge Detector Revisited (International Journal of Computer Vision)](https://dl.acm.org/doi/10.1007/s11263-010-0392-0)
16. [Using Canny's criteria to derive a recursively implemented optimal edge detector (Deriche, 1987, Springer record)](https://web.archive.org/web/20180607233447/https:/link.springer.com/article/10.1007/BF00123164)
17. [ITK CannyEdgeDetectionRecursiveGaussianImageFilter documentation](https://docs.itk.org/projects/doxygen/en/v5.0.0/classitk_1_1CannyEdgeDetectionRecursiveGaussianImageFilter.html)
18. [Parallelization Strategies of the Canny Edge Detector](https://hvg.ece.concordia.ca/Publications/Conferences/NEWCAS12-3.pdf)
19. [Learning to utilize image second-order derivative information for crisp edge detection (arXiv, 2024)](https://arxiv.org/pdf/2406.05779v5.pdf)
20. [CPSC 425: Computer Vision, Lecture 9 (UBC)](https://www.cs.ubc.ca/~aerion1/425_2025W2/Lecture9.pdf)
21. [An Adaptive Threshold for the Canny Edge with Weak Label (Applied Sciences, MDPI, 2025)](https://www.mdpi.com/2076-3417/15/22/12158)

---
*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/canny-edge-detection

English original: https://www.edgepedia.org/canny-edge-detection
