OpenCV画像のグローバルしきい値二値化関数(OTSU)

1031 ワード

cv::threshold(GrayImg, Bw, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);//       

CV_THRESH_OTSUは画像抽出に最適なしきい値アルゴリズムである.この方法はクラス間分散が最も大きい場合に最適であり,OTSUは画像の階調値に関して最適なクラス間分離の閾値を与える.
 
OpenCVしきい値分割のいくつかの方法(types_c.hの定義):
/* Threshold types */
enum
{
    CV_THRESH_BINARY      =0,  /* value = value > threshold ? max_value : 0       */
    CV_THRESH_BINARY_INV  =1,  /* value = value > threshold ? 0 : max_value       */
    CV_THRESH_TRUNC       =2,  /* value = value > threshold ? threshold : value   */
    CV_THRESH_TOZERO      =3,  /* value = value > threshold ? value : 0           */
    CV_THRESH_TOZERO_INV  =4,  /* value = value > threshold ? 0 : value           */
    CV_THRESH_MASK        =7,
    CV_THRESH_OTSU        =8  /* use Otsu algorithm to choose the optimal threshold value;
                                 combine the flag with one of the above CV_THRESH_* values */
}

 
転載先:https://www.cnblogs.com/meadow-glog/p/4675548.html