C#Halcon从零开发_Day13_几种阈值分割方法
read_image (Image, 'printer_chip/printer_chip_01')
* 一、直接阈值分割(最常用)
*threshold (Image, Region, 100, 255)
*二、值化阈值分割
* 应用场景:自动阈值计算,分割出前景和背景
*'max_separability' 速度快,不抗干扰
* 'dark' 提取暗部 light提取亮部
*UsedThreshold 自动算出的阈值
*binary_threshold (Image, Region, 'max_separability', 'light', UsedThreshold)
*三、动态阈值分割(常用)
*适用场景: 成像不一致,暗一块、亮一块
*3.1 均值滤波
*9, 9:表示均值滤波的邻域大小(窗口大小)为9×9像素。这意味着在计算每个像素点的平均灰度值时,会考虑其周围8×8(共81个)相邻像素的灰度值。
*mean_image (Image, ImageMean, 50, 50)
* Image 原图
* ImageMean 均值滤波后的图
* RegionDynThresh 输出的分割区域
* 5 : 阈值
* 'light '分割模式 (原图灰度值-均值滤波图灰度值) > 阈值:light (原图灰度值-均值滤波图灰度值) < -阈值:dark
* >阈值 或 <-阈值 'not_equal' (-阈值,阈值) equal
*dyn_threshold (Image, ImageMean, RegionDynThresh, 5, 'light')
*四、动态均方差阈值分割
* 均值滤波,多了标准差和因子的输入参数
*15,15 滤波核 15X15的均值计算
*var_threshold (Image, Region, 100, 100, 0.2, 2, 'light')
*五、灰度直方图阈值分割
* 优势:自动化分割、分割出多个区域
*高斯系数: 越大 分割出区域种类越少
*auto_threshold (Image, Regions, 2)
*六、快速阈值分割
*20 : minSize 越大 速度越快 Value range: 2 ≤ MinSize ≤ 200 (lin)
fast_threshold (Image, Region, 128, 255,20)