原图来自Ihalcon论坛
一个非常小的凹坑位于图中间
- 算法思路 -
利用灰度统计特性进行缺陷检测
原图噪声比较大,进行高斯滤波
计算灰度统计特性
代码语言:javascript复制intensity (ImageGauss, ImageGauss, Mean, Deviation)
利用灰度统计特性,检测亮缺陷
亮缺陷检测代码如下
代码语言:javascript复制
*亮缺陷
threshold(ImageGauss, LightRegion, Mean 3.5*Deviation, 255)
connection (LightRegion, ConnectedRegions)
shape_trans (ConnectedRegions, RegionTrans, 'convex')
inner_circle(RegionTrans, _, _, Radius2)
tuple_find(sgn(Radius2 - max(Radius2) 0.001), 1, Indices)
select_obj (ConnectedRegions, ObjectSelected, Indices 1)
检测暗缺陷
检测暗缺陷代码
代码语言:javascript复制*暗缺陷
threshold(ImageGauss, DarkRegion, 0, Mean - 1.5*Deviation)
fill_up (DarkRegion, RegionFillUp)
connection (RegionFillUp, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions, 'inner_radius', 'and', 2.0122, 4.9109)
*亮缺陷与暗缺陷相邻很近,根于此关系,选择暗缺陷
select_shape_proto (SelectedRegions, ObjectSelected, SelectedRegions1, 'distance_dilate', 0, 5)
合并缺陷