在Halcon软件中使用Sobel算子进行边缘检测时,查看相关算子,结合自己的理解。对于其中三种检测方式做出说明,不对的地方请大家指正。
* 检测原图
read_image (Image, 'printer_chip/printer_chip_01')
一、默认Sobel检测算子sobel_amp
* 在各个方向上都均匀的检测边缘信息
sobel_amp (Image, EdgeAmplitude, 'sum_abs', 3)
二、使用卷积函数中默认的sobel算子
* 从图中看出检出的边缘在左侧和上侧明显(只检出了图像由暗到亮的边缘)
convol_image (Image, ImageResult, 'sobel', 'mirrored')
三、使用自己构造的sobel算子进行卷积检测
1)、构造X方向增大的Sobel检测算子
sobelXright := [3,3,1, \
-1,0,1, \
-2,0,2, \
-1,0,1 ]
* 看kernel结构,我们可以推断出,将检测出图像中X方向由暗到亮的边缘
convol_image (Image, ImageResultxright, sobelXright, 'mirrored')
2)、构造Y方向增大的Sobel检测算子
sobelYdown := [3, 3, 1, \
-1,-2,-1, \
0, 0, 0, \
1, 2, 1 ]
* 看kernel结构,我们可以推断出,将检测出图像中Y方向由暗到亮的边缘
convol_image (Image, ImageResultydown, sobelYdown, 'mirrored')
我们将上面两小步中得到的两幅图像相加,则可得到和标题二中接近的效果
add_image (ImageResultxright, ImageResultydown, ImageResultxy1, 0.5, 0)
3)、构造X减小增大的Sobel检测算子
sobelXleft := [3,3, 1, \
1,0,-1, \
2,0,-2, \
1,0,-1 ]
* 看kernel结构,我们可以推断出,将检测出图像中X方向由亮到暗的边缘
convol_image (Image, ImageResultxleft, sobelXleft, 'mirrored')
4)、构造Y方向减小的Sobel检测算子
sobelYup := [3, 3, 1, \
1, 2, 1, \
0, 0, 0, \
-1,-2,-1 ]
* 看kernel结构,我们可以推断出,将检测出图像中Y方向由亮到暗的边缘
convol_image (Image, ImageResultyup, sobelYup, 'mirrored')
我们将上面两小步中得到的两幅图像相加,则可得到和标题二中相反的效果
add_image (ImageResultxleft, ImageResultyup, ImageResultxy2, 0.5, 0)
最后,我们将上面4个小步骤结合起来,可得到和标题一接近的检测效果
add_image (ImageResultxy1, ImageResultxy2, ImageResult1, 1, 0)