相似度--欧氏距离(归一化)

<!-- lang: cpp -->
double CalcSimilarity(IplImage* S,IplImage* T)

{

double r = 0.f;
int width = T->width;
int height = T->height;

uchar* ptrS = NULL;
uchar* ptrT = NULL;
float a = 0,b = 0,c = 0;
for(int i=0;i<height;i++)
{
    ptrS = (uchar*)S->imageData+i*S->widthStep;
    ptrT = (uchar*)T->imageData+i*T->widthStep;
    for(int j=0;j<width;j++)
    {
        a += ptrS[j]*ptrS[j];
        c += ptrT[j]*ptrT[j];
        b += ptrS[j]*ptrT[j];
    }
}

return b / (sqrt(a) * sqrt(c));

}

你可能感兴趣的:(相似度,欧氏距离,归一化)