套路:滤波模糊化——动态阈值分割
halcon中案例:surface_scratch.hdev,划痕与背景相似,背景均匀
read_image (Image, 'surface_scratch') get_image_size (Image, Width, Height) mean_image (Image, ImageMean, 7, 7) //用7×7的窗口对图像进行均值滤波,获得参考图像
//动态阈值分割 dyn_threshold (Image, ImageMean, DarkPixels, 5, 'dark') //与参考图像对比,灰度差距5以内可接受,凸显暗色 connection (DarkPixels, ConnectedRegions) //区域拆分 select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10, 1000) union1 (SelectedRegions, RegionUnion) //区域合并,connection的逆过程 dilation_circle (RegionUnion, RegionDilation, 3.5) //圆形膨胀,临近区域联通 skeleton (RegionDilation, Skeleton) //骨架抽取 connection (Skeleton, Errors) select_shape (Errors, Scratches, 'area', 'and', 50, 10000) select_shape (Errors, Dots, 'area', 'and', 1, 50)
套路:剔除亮色物——滤波模糊化——动态阈值分割
halcon中案例:particle.hdev,分析在液体中的颗粒(低亮),目标与背景相似,背景均匀(剔除亮色物后)
read_image (Image, 'particle') threshold (Image, Large, 110, 255) dilation_circle (Large, LargeDilation, 7.5) complement (LargeDilation, NotLarge) //补充,即反色 reduce_domain (Image, NotLarge, ParticlesRed) //缩减预,即二值图转灰度图 mean_image (ParticlesRed, Mean, 31, 31) //均值滤波,模糊化 dyn_threshold (ParticlesRed, Mean, SmallRaw, 3, 'light') //动态阈值分割,取亮色目标 opening_circle (SmallRaw, Small, 2.5)