1.sobel算子
sobel算子可以计算图像梯度,计算图像梯度的作用是提取边界。
(1)X方向的梯度
以3x3的卷积核计算sobel算子为例:
图中左边就是计算水平梯度时的卷积核,简单来说就是右边减左边,权重由卷积核规定。
含义:当目标(P5点)右左两列差别特别大的时候,目标点的值会很大,说明该点为边界。
(2)Y方向的梯度
上图是计算垂直方向梯度的卷积核,如果在垂直方向上存在有较大的差值就说明存在有水平边界。
(3)注意&总结
a.水平梯度运算提取垂直方向的边界,垂直方向的梯度运算得到水平方向的边界。
b.Opencv默认的是截断的操作,即小于0按0算,大于255按255算。这样计算得到的图像可能会被削半,不合适,最好对于小于0的取绝对值,大于255的可按255算(最大的极差了)。
(4)总梯度
总梯度:
简化梯度:
(5)函数介绍
cv.Sobel(
src,
ddepth,
dx,
dy[, dst[, ksize[, scale[, delta[, borderType]]]]]
)
-> dst
Parameters
src input image. dst output image of the same size and the same number of channels as src . ddepth output image depth, see combinations; in the case of 8-bit input images it will result in truncated derivatives. dx order of the derivative x. dy order of the derivative y. ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7. scale optional scale factor for the computed derivative values; by default, no scaling is applied (see