先来张素材图

bd6a31451e383512f93f39a9e80f3787.png

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 : )

有关动态阈值可以参考下面的贴子:

0be60cc4ac9567dac076a164c9dca8d3.png

#转载请注明出处 www.skcircle.com 《少有人走的路》勇哥的工业自动化技术网站。如果需要本贴图片源码等资源,请向勇哥索取。

收藏 | 0点赞 | 0打赏作者

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐