先来张素材图
read_image (Image, 'C:/Users/Administrator/Desktop/划痕+油污+瑕疵的检测/划痕、油污、瑕疵/胶囊表面污点检测/Image.bmp') rgb1_to_gray(Image,GrayImage) scale_image_max(GrayImage,ImageScaleMax) mean_image(ImageScaleMax,ImageMean,9,9) *找到亮点 dyn_threshold(ImageScaleMax,ImageMean,RegionDynThresh,5,'light' ) connection(RegionDynThresh,ConnectedRegions) dev_clear_window() dev_display(Image) select_shape (ConnectedRegions,SelectedRegions,'area','and',20,25) stop() *找到暗点 mean_image(ImageScaleMax,ImageMean,7,7) dyn_threshold(ImageScaleMax,ImageMean,RegionDynThresh1,5,'dark' ) connection(RegionDynThresh1,ConnectedRegions1) dev_clear_window() dev_display(Image) select_shape (ConnectedRegions1,SelectedRegions1,'area','and',13,15) stop()
dyn_threshold是动态阈值算子,动态阈值和threshold不同的是其最大阈值与最小阈值不需要指定,而是由算子根据情况自动推算出来的。因为可以处理一张图片中有多种阈值分布的情况。
dyn_threshold算子一般要前置滤波算子,如本例中使用中值滤波mean_image。
dyn_threshold的原型如下,其最一个参数LightDark可以决定是选择亮部还是暗部。
dyn_threshold(OrigImage, ThresholdImage : RegionDynThresh : Offset, LightDark : )
有关动态阈值可以参考下面的贴子:
Halcon学习(4-6)Region处理:动态阈值,分水岭
视觉检测之焊点检测(三):从干扰背景中提取焊点
视觉检测之焊点检测(四):动态定位焊点区域ROI
本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:


