*关闭程序计数器,图形变量,窗口图形更新
dev_update_off()
* Image Acquisition 01: Code generated by Image Acquisition 01
ImageFiles := []
ImageFiles[0] := '1.bmp'
ImageFiles[1] := '2.bmp'
for Index := 0 to |ImageFiles| - 1 by 1
*读取一张图像
read_image (Image, ImageFiles[Index])
*分割出环形区域
threshold (Image, Region, 100, 255)
*对区域进行连通处理
connection (Region, ConnectedRegions)
*过滤出圆环区域
select_shape (ConnectedRegions, SelectedConnectedRegions, ['area','circularity'], 'and', [40000,0.6], [99999,1])
*将圆环区域中的图像剪切出来
reduce_domain (Image, SelectedConnectedRegions, ImageReduced)
*将图像和高斯导数进行卷积运算求轮廓
derivate_gauss (ImageReduced, DerivGaussImage, 1.5, 'gradient')
*分割出图像中的轮廓
threshold (DerivGaussImage, DerivGaussRegion, 9, 50)
*对轮廓区域进行连通处理
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', 50, 999)
*显示图像
dev_display (Image)
*显示缺陷区域
dev_display (DefectResult)
stop()
endfor