来套大律法动态阈值
时间:06-25 09:03 阅读:1602次
*温馨提示:点击图片可以放大观看高清大图
简介:
/***************************大律法动态阈值*********************************/
来套大律法动态阈值的
/***************************大律法动态阈值*********************************/
void otsu_yuzhi( )
{
int wh = 128;
int inIm[128];
int i, t;
int L = 128;
double p[128];
double w1=0;
double u0=0;
double u1 = 0;
double max = 0.0;
double w0 = 0;
int m =0;
double sigma[128];
for (i = 0; i < 128; i++)
inIm= ADV&0xff;
for (i = 0; i < L; i++)
p= 0;
//计算各灰度出现次数
for (i = 0; i < 128; i++)
p[inIm]++;
//计算各灰度级出现概率
for (m = 0; m < L; m++)
p[m] = p[m] / wh;
for (t = 0; t < L; t++)
{
w0 = 0;
for (m = 0; m < t+1; m++)
w0 += p[m];
w1 = 1 - w0;
u0 = 0;
for (m = 0; m < t + 1; m++)
u0 += m * p[m] / w0;
u1 = 0;
for (m = t; m < L; m++)
u1 += m * p[m] / w1;
sigma[t] = w0*w1*(u0-u1)*(u0-u1);
}
max = 0.0;
for (i = 0; i < L-1; i++)
{
if (max < sigma)
{
max = sigma;
THRESHOLD = i;
}
}
//二值化
for (i=0; i<128; i++)
{
ADV=ADV>THRESHOLD?225:0;
}
}