在opencv工程里面使用otsu分割灰度图像类似于matlab里的graythresh, opencv里面提供了otsu threshold的源代码“icvGetThreshVal_Otsu”,但是我们却不能直接调用它,只能把它拷贝出来使用(这就是开源的好处) //Input: //pTile_pic: 灰度图像,*IplImage //output: //im_th: pTile_pic 的otsu阈值 otsu threshold: int size = 256; float range[] = {0, 255}; float *pRange[] = {&range[0]}; CvHistogram *p_imhist = cvCreateHist(1, &size, CV_HIST_ARRAY, pRange); cvCalcHist(&pTile_pic, p_imhist); double im_th = icvGetThreshVal_Otsu(p_imhist); Source code: static double icvGetThreshVal_Otsu( const CvHistogram* hist ) |