效果
代码
*6产中的凹坑检测
dev_update_off ()read_image (Image, '6产中的凹坑检测.png')
*分割出环形区域
threshold (Image, Region, 100, 255)
*连通
connection (Region, ConnectedRegions)
*选择圆环区域
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 34400, 35400)
*select_shape (ConnectedRegions, SelectedRegions2, ['area','circularity'], 'and', [34400,0.64866], [35887.8,0.68719])
*dev_set_color('green')
*将圆环区域的图像剪切出来
reduce_domain (Image, SelectedRegions, ImageReduced)
*将图像和高斯导数进行卷积运算
derivate_gauss (ImageReduced, DerivGaussImage, 1.5, 'gradient')
*分割出图像的轮廓,选择 9-50灰度值区间的区域
threshold (DerivGaussImage, DerivGaussRegion, 9, 50)
closing_circle (DerivGaussRegion, DerivGaussRegion, 1.5)
*对轮廓区域进行连通处理
connection (DerivGaussRegion, DerivGaussConnectedRegions)
*获取轮廓区域,获取最大面积的圆
select_shape_std (DerivGaussConnectedRegions, SelectedDerivGaussConnectedRegions, 'max_area', 70)
*填充该轮廓区域
fill_up (SelectedDerivGaussConnectedRegions, RegionFillUp)
*求轮廓区域和填充的轮廓区域之间的补集区域
difference (RegionFillUp, SelectedDerivGaussConnectedRegions, RegionDifference)
connection (RegionDifference, ResultConnectedRegions)
*获取缺陷区域
select_shape (ResultConnectedRegions, DefectResult, 'area', 'and', 240, 250)
dev_set_color ('red')
dev_display(Image)
dev_display (DefectResult)