writen by wqj1212@yahoo.com.cn
double CRecognise::recogniseNMI(IplImage *src)
{
IplImage *src1;
int width;
int height;
width=src->width;
height=src->height;
int i,j;
double cx=0.0;double cy=0.0; J=0.0;double M=0.0;
src1=cvCreateImage(cvSize(src->width,src->height),src->depth,1);
if((src->nChannels)!=1)
{ cvCvtColor(src,src1,CV_BGR2GRAY);
}
else
//cvCopy(src,src1);
src1=(IplImage *)cvClone(src);
//cvAdaptiveThreshold(src1,src1,1,CV_ADAPTIVE_THRESH_GAUSSIAN_C,CV_THRESH_BINARY ,5);
for(j=1;j<=height;j++)
for(i=1;i<=width;i++)
{
M+=(float)CV_IMAGE_ELEM(src1,uchar,j,i);
cx+=i*CV_IMAGE_ELEM(src1,uchar,j,i);
cy+=j*CV_IMAGE_ELEM(src1,uchar,j,i);
}
cx/=M;
cy/=M;
for(j=1;j<=height;j++)
for( i=1;i<width;i++)
{
J+=((i-cx)*(i-cx)+(j-cy)*(j-cy))*((float)CV_IMAGE_ELEM(src1,uchar,j,i));
}
J=sqrt(J)/M;
return J;
}
{
IplImage *src1;
int width;
int height;
width=src->width;
height=src->height;
int i,j;
double cx=0.0;double cy=0.0; J=0.0;double M=0.0;
src1=cvCreateImage(cvSize(src->width,src->height),src->depth,1);
if((src->nChannels)!=1)
{ cvCvtColor(src,src1,CV_BGR2GRAY);
}
else
//cvCopy(src,src1);
src1=(IplImage *)cvClone(src);
//cvAdaptiveThreshold(src1,src1,1,CV_ADAPTIVE_THRESH_GAUSSIAN_C,CV_THRESH_BINARY ,5);
for(j=1;j<=height;j++)
for(i=1;i<=width;i++)
{
M+=(float)CV_IMAGE_ELEM(src1,uchar,j,i);
cx+=i*CV_IMAGE_ELEM(src1,uchar,j,i);
cy+=j*CV_IMAGE_ELEM(src1,uchar,j,i);
}
cx/=M;
cy/=M;
for(j=1;j<=height;j++)
for( i=1;i<width;i++)
{
J+=((i-cx)*(i-cx)+(j-cy)*(j-cy))*((float)CV_IMAGE_ELEM(src1,uchar,j,i));
}
J=sqrt(J)/M;
return J;
}