产品表面三角缺陷检测
Demo.hdev
//读取一张图像
read_image (Image, '1.jpg')
//将RGB图像转化为灰度图
rgb1_to_gray (Image, GrayImage)
//使用自动阈值分割图像前景区域
bin_threshold (GrayImage, Region)
//将前景区域中图像剪切出来
reduce_domain (GrayImage, Region, ClipImage)
//均值滤波
mean_image (ClipImage, ImageMean, 200, 3)
//局部阈值,分割出前景
dyn_threshold (ClipImage, ImageMean, RegionDynThresh, 7, 'light')
//对分割的区域闭运算,填充间隙,平滑边界
closing_circle (RegionDynThresh, RegionClosing, 3.5)
//连通处理
connection (RegionClosing, ConnectedRegions)
//过滤出三角形区域
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 500, 2000)
//填充三角形内部区域
fill_up (SelectedRegions, RegionFillUp)
//将三角形区域转换为凸度
shape_trans (RegionFillUp, RegionTrans, 'convex')
//将区域转换为轮廓
gen_contour_region_xld (RegionTrans, Contours, 'border')
//显示图像
dev_display(GrayImage)
//显示三角形区域
dev_display(Contours)