Canny 边缘检测算法的主要步骤的数学公式
时间: 2023-11-20 11:28:04 浏览: 30
Canny 边缘检测算法的主要步骤可以用以下数学公式表示:
1. 去噪声:
高斯滤波器公式:
$$
G(x,y) = \frac{1}{2\pi \sigma^2}e^{-\frac{x^2+y^2}{2\sigma^2}}
$$
2. 计算梯度:
Sobel 算子公式:
$$
G_x = \begin{bmatrix}
-1 & 0 & 1 \\
-2 & 0 & 2 \\
-1 & 0 & 1
\end{bmatrix}
, \quad
G_y = \begin{bmatrix}
-1 & -2 & -1 \\
0 & 0 & 0 \\
1 & 2 & 1
\end{bmatrix}
$$
梯度大小和方向公式:
$$
\begin{aligned}
G &= \sqrt{G_x^2 + G_y^2} \\
\theta &= \arctan(\frac{G_y}{G_x})
\end{aligned}
$$
3. 非极大值抑制:
非极大值抑制公式:
$$
M(x,y) = \begin{cases}
G(x,y), \quad \text{if } G(x,y) \geq G(x+1,y), G(x,y) \geq G(x-1,y), G(x,y) \geq G(x,y+1), G(x,y) \geq G(x,y-1) \\
0, \quad \text{otherwise}
\end{cases}
$$
4. 双阈值检测:
双阈值检测公式:
$$
\begin{aligned}
&\text{Strong edge} = \text{if } M(x,y) > T_{high} \\
&\text{Weak edge} = \text{if } T_{low} < M(x,y) < T_{high} \\
&\text{Noise} = \text{if } M(x,y) < T_{low}
\end{aligned}
$$
5. 边缘连接:
边缘连接公式:
- 对于任意一个强边缘像素,沿着其梯度方向追踪相邻的像素,如果该像素是弱边缘,则将其认为是边缘像素。
- 重复上述步骤,直到没有新的像素被标记为边缘像素。