比如说有两个图形都是圆,那么他们肯定相似,但是如何作出最快的判断啊?

解决方案 »

  1.   

    顺便问一下,MatLab的小波包工具箱有用于重建的部分吗,好用吗。马上揭帖!
      

  2.   

    是不是相关系数理论,如下代码
    BOOL WINAPI TemplateTimeDetect(LPSTR lpDIBBits,LPSTR lpTemplateDIBBits,LONG lWidth,LONG lHeight,LONG lTemplateWidth,LONG lTemplateHeight)
    { LPSTR lpSrc,lpTemplateSrc; //中间结果
    double dSigmaST;   //源图像和模板的关联性
    double dSigmaS;    //源图象的关联性
    double dSigmaT;    //模板的关联性

    //相似性测度
    double R;
    //最大相似性测度
    double MaxR;
    //最大相似性出现位置
    long lMaxWidth;
    long lMaxHeight;
    unsigned char pixel, templatepixel;
    LONG lLineBytes=WIDTHBYTES(lWidth*8),lTemplateLineBytes=WIDTHBYTES(lTemplateWidth*8);    
    //计算dSigmaT
    dSigmaT = 0;
    for (LONG n = 0;n < lTemplateHeight ;n++)
    {
    for(LONG m = 0;m < lTemplateWidth ;m++)
    {
    // 指向模板图像倒数第j行,第i个象素的指针
    lpTemplateSrc = (char *)lpTemplateDIBBits + lTemplateLineBytes * n + m;
    templatepixel = (unsigned char)*lpTemplateSrc;
    dSigmaT += (double)templatepixel*templatepixel;
    }
    } //在计算相似性时,不需要从图像第一行往下,因为得到是整体的值
    MaxR = 0.0;
    for (LONG j = 0;j < lHeight - lTemplateHeight +1 ;j++)  
    {
    for(LONG i = 0;i < lWidth - lTemplateWidth + 1;i++)
    {
    dSigmaST = 0;
    dSigmaS = 0;

    for (LONG n = 0;n < lTemplateHeight ;n++)
    {
    for(LONG m = 0;m < lTemplateWidth ;m++)
    {
    // 指向源图像倒数第j+n行,第i+m个象素的指针
    lpSrc  = (char *)lpDIBBits + lLineBytes * (j+n) + (i+m);

    // 指向模板图像倒数第n行,第m个象素的指针
    lpTemplateSrc  = (char *)lpTemplateDIBBits + lTemplateLineBytes * n + m;

    pixel = (unsigned char)*lpSrc;
    templatepixel = (unsigned char)*lpTemplateSrc;

    dSigmaS += (double)pixel*pixel;
    dSigmaST += (double)pixel*templatepixel;
    }
    }
    //相关系数等于源图与模板象素的点乘(除以源图的点乘乘以模板的点乘)
    R = dSigmaST / ( sqrt(dSigmaS)*sqrt(dSigmaT));
    //与最大相似性比较
    if (R > MaxR)
    {
    MaxR = R;
    lMaxWidth = i;
    lMaxHeight = j;
    }
    }
    }// CString result;
    // result.Format("Max Cof= %f",MaxR);
    // AfxMessageBox(result); //将图像其余部分置黑,使匹配的那一部分能够更好的呈现
    for (LONG i=0;i<lHeight;i++)
    for (LONG j=0;j<lWidth;j++)
    {
    lpSrc  = (char *)lpDIBBits + lLineBytes * i + j;
    if (i>=lMaxHeight && i<lMaxHeight+lTemplateHeight && j>=lMaxWidth && j<lMaxWidth+lTemplateWidth)
                {
    pixel=(unsigned char)(*lpSrc);
    pixel=(pixel<226?pixel+30:pixel);
    *lpSrc=pixel;     
    }
    else
    {
    pixel=(unsigned char)(*lpSrc);
    pixel=(pixel>100?pixel-100:pixel);
    *lpSrc=pixel;
    }
    } return TRUE;
    }
      

  3.   

    To:qqhuangshen(雨淋淋) 您提供的算法示对相似图像有效吗,而且如果一幅图中有多个图形与模版匹配,那么这样的计算还可行吗?