利用Halcon提取出器件的中心部分

利用Halcon取出器件的中心部分,结果如下图:

主要是利用distance_transform函数,在NI VISION里也有相对应的功能函数。

主要代码:

read_image (Image, 'C:/Users/gongyong/Desktop/捕获.PNG')
rgb1_to_gray (Image, GrayImage)
threshold (GrayImage, Regions, 16, 255)
connection (Regions, Connection)
*凸运算,填充区域
shape_trans (Connection, RegionTrans, 'convex')
get_image_size (GrayImage, Width, Height)
*计算一个区域的距离转换,越往内部的值越高,到图中为越亮
distance_transform (RegionTrans, DistanceImage, 'city-block', 'true', Width, Height)

reduce_domain (DistanceImage, Regions, ImageReduced)
threshold (ImageReduced, Regions1, 16, 127)

*根据Connection进行连通域分割
intersection (Connection, Regions1, RegionIntersection)

posted @ 2017-06-27 14:53  ilovelab  阅读(1793)  评论(0编辑  收藏  举报