Ask Your Question
2

orientation smoothing

asked 2012-10-24 04:25:11 -0600

updated 2012-10-24 06:09:49 -0600

Is there a function for orientation smoothing?

Note: If orientation smooths by cvSmooth the orientation map will be broken.

edit retag flag offensive close merge delete

Comments

What do you mean by the orientation map? Are you talking about affine or perspective transformation matrices? Please update your question with more details.

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-10-25 02:34:10 -0600 )edit

Please search "fingerprint orientation map" .

Mostafa Sataki gravatar imageMostafa Sataki ( 2012-10-26 04:06:17 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2012-11-11 00:31:18 -0600

I solve it by the following code:

#define BH_RAD_TO_DEG   180/CV_PI
#define BH_DEG_TO_RAD   CV_PI/180
void bh2Rad(CvMat* srcMat,CvMat* dstMat)
{
    for (int i=0; i < srcMat->rows ;i++)
    {
        float* srcP = srcMat->data.fl + srcMat->width * i;
        float* dstP = dstMat->data.fl + dstMat->width * i;

        for (int j = 0; j < srcMat->cols ;j++)
            dstP[j] = srcP[j] * BH_DEG_TO_RAD;
    }
}

void bh2Deg(CvMat* srcMat,CvMat* dstMat)
{
    for (int i=0; i < srcMat->rows ;i++)
    {
        float* srcP = srcMat->data.fl + srcMat->width * i;
        float* dstP = dstMat->data.fl + dstMat->width * i;

        for (int j = 0; j < srcMat->cols ;j++)
            dstP[j] = srcP[j] * BH_RAD_TO_DEG;
    }
}
void bhSin2Mat(CvMat* srcMat,CvMat* dstMat)
{
    for (int i=0; i < srcMat->rows;i++)
    {
        float* srcP = srcMat->data.fl + srcMat->width * i;
        float* dstP = dstMat->data.fl + dstMat->width * i;

        for (int j=0; j < srcMat->cols;j++)
            dstP[j] = sin(2 * srcP[j]);

    }
}
void bhCos2Mat(CvMat* srcMat,CvMat* dstMat)
{
    for (int i=0; i < srcMat->rows;i++)
    {
        float* srcP = srcMat->data.fl + srcMat->width * i;
        float* dstP = dstMat->data.fl + dstMat->width * i;

        for (int j=0; j < srcMat->cols;j++)
            dstP[j] = cos(2 * srcP[j]);

    }

}

void bhATanMat(CvMat* sinMat,CvMat* cosMat, CvMat* dstMat)
{
    for (int i=0; i < dstMat->rows;i++)
    {
        float* sinP = sinMat->data.fl + sinMat->width * i;
        float* cosP = cosMat->data.fl + cosMat->width * i;

        float* dstP = dstMat->data.fl + dstMat->width * i;

        for (int j=0; j < dstMat->cols;j++)
        {
            dstP[j] = float(atan2(sinP[j],cosP[j])/2 * BH_RAD_TO_DEG);
            if (dstP[j] < 0) dstP[j] = 180 + dstP[j];
        }
    }

}
void bhSmoothOrientation(CvMat* srcMat,CvMat* dstMat,bool normalize, int smoothType,int size1 ,int size2 ,double sigma1 ,double sigma2)
{
    double min_value,max_value;
    if (normalize)
    {
      cvMinMaxLoc(srcMat,&min_value,&max_value);
      cvNormalize(srcMat,dstMat,0,180,CV_MINMAX);
    }

    bh2Rad(dstMat,dstMat);

    CvMat* sinMat = cvCreateMat(dstMat->rows,dstMat->cols,CV_32FC1);
    CvMat* cosMat = cvCreateMat(dstMat->rows,dstMat->cols,CV_32FC1);

    bhSin2Mat(dstMat,sinMat);
    cvSmooth(sinMat,sinMat,smoothType, size1,size2,sigma1,sigma2);
    bhCos2Mat(dstMat,cosMat);
    cvSmooth(cosMat,cosMat,smoothType, size1,size2,sigma1,sigma2);

    bhATanMat(sinMat,cosMat,dstMat);

    bh2Deg(dstMat,dstMat);

    if (normalize)
      cvNormalize(srcMat,dstMat,min_value,max_value,CV_MINMAX);

    cvReleaseMat(&sinMat);
    cvReleaseMat(&cosMat);
}
edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-10-24 04:25:11 -0600

Seen: 849 times

Last updated: Nov 11 '12