概述
Otsu's method 也叫全局最优阈值处理,使用聚类思想,将图像分为“前景”和“背景”两类,并使得上述两类的类内方差最小,即类间方差最大。
图1 原图像
图2 使用 Otsu's method 进行二值化后的图像
算法
[sigma _{w}^{2}(t)=omega _{0}(t)sigma _{0}^{2}(t)+omega _{1}(t)sigma _{1}^{2}(t)
]
其中,
(t) 是将图像分为“前景”和“背景”两类的阈值,(omega _{0}) 和 (omega _{1}) 分别是这两个类的加权数,而 (sigma _{0}^{2}) 和 (sigma _{1}^{2}) 分别是这两个类的方差。
图3 算法可视化动图
Halcon
binary_threshold(Image : Region : Method, LightDark : UsedThreshold)
当 Method = 'max_separability'
时,即为 Otsu 算法。
OpenCV
double cv::threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
当 type = THRESH_BINARY | THRESH_OTSU
时,即为 Otsu 算法。