資源簡介
Otsu雙閾值分割。將圖像分為三層,在根據Middle與top的關系進行二值化
代碼片段和文件信息
void?Otsu2Threshold(Mat&?src?Mat&?dst)
{
Mat?img?=?src;
//dst.create(src.size()?src.type());
CV_Assert(1?==?img.channels());
int?height?=?img.rows;
int?width??=?img.cols;
int?Threshold1?=?0;//閾值
int?Threshold2?=?0;//閾值
double?gSum_object;//第一類前景灰度總值
double?gSum_middle;
double?gSum_blackground;//第二類,背景灰度總值
double?N_object?=?0;//前景像素數
double?N_middle?=?0;
double?N_blackground?=?0;//背景像素數
double?u0?=?0;//前景像素平均灰度
double?u1?=?0;
double?u2?=?0;//背景像素平均灰度
double?w0?=?0;//前景像素點數占整幅圖像的比例為ω0
double?w1?=?0;
double?w2?=?0;//背景像素點數占整幅圖像的比例為ω1
double?u?=?0;//總平均灰度
double?tempg?=?-1;//臨時類間方差
double?g?=?-1;//類間方差
double?Histogram[256]={0};//灰度直方圖
double?N_allpixel?=?width?*?height;//總像素數
for(int?k?=?0;?k? {
//計算直方圖
uchar*?d
- 上一篇:VS2010 MFC 計算器
- 下一篇:C++實現異質鏈表
評論
共有 條評論