2D算法 Halcon 划痕缺陷检测
方法:滤波模糊化——动态阈值分割
halcon中案例:surface_scratch.hdev,划痕与背景相似,背景均匀
read_image (Image, ‘surface_scratch’)
get_image_size (Image, Width, Height)
mean_image (Image, ImageMean, 7, 7) //用7×7的窗口对图像进行均值滤波,获得参考图像//动态阈值分割
dyn_threshold (Image, ImageMean, DarkPixels, 5, ‘dark’) //与参考图像对比,灰度差距5以内可接受,凸显暗色
connection (DarkPixels, ConnectedRegions) //区域拆分
select_shape (ConnectedRegions, SelectedRegions, ‘area’, ‘and’, 10, 1000)
union1 (SelectedRegions, RegionUnion) //区域合并,connection的逆过程
dilation_circle (RegionUnion, RegionDilation, 3.5) //圆形膨胀,临近区域联通
skeleton (RegionDilation, Skeleton) //骨架抽取
connection (Skeleton, Errors)
select_shape (Errors, Scratches, ‘area’, ‘and’, 50, 10000)
select_shape (Errors, Dots, ‘area’, ‘and’, 1, 50)