素材图片:
dev_clear_window() *读取图片 read_image (Image, 'C:/Users/Administrator/Desktop/new/QQ图片20161212193015.jpg') get_image_size (Image, Width, Height) *自动阈值分割 bin_threshold (Image, Region) *分割后选择的是所需的背景,所以求反一次 complement (Region, RegionComplement) dev_display(Image) * dev_display(RegionComplement) *做一次闭运算 closing_circle(RegionComplement, RegionClosing, 3.5) *空洞填充 fill_up_shape (RegionClosing, RegionFillUp, 'area', 1, 100) *欧式距离函数的距离变换 distance_transform (RegionFillUp, DistanceImage, 'octagonal', 'true', Width, Height) *int4转byte convert_image_type (DistanceImage, ImageConverted, 'byte') *图像取反 invert_image (ImageConverted, ImageInvert) *增加对比度 scale_image_max (ImageInvert, ImageScaleMax) *高斯平滑处理 gauss_image (ImageScaleMax, ImageGauss, 11) *分水岭算法 watersheds_threshold (ImageGauss, Basins, 10) *计数统计为29个 count_obj (Basins, Number) *发现有小区域面积干扰,重新选择区域 select_shape (Basins, SelectedRegions, 'area', 'and', 5267.61, 119050) *获取到正确的数目25 count_obj (SelectedRegions, Number1)
其它一些关于粘连处理的贴子:
HALCON图像处理的粘连零件颗粒计数 http://47.98.154.65/?id=78
粘合度高的物体识别 http://47.98.154.65/?id=1449
halcon Blob分析--粘连颗粒检测 http://47.98.154.65/?id=1495
本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:


