orientation smoothing
Is there a function for orientation smoothing?
Note: If orientation smooths by cvSmooth the orientation map will be broken.
Is there a function for orientation smoothing?
Note: If orientation smooths by cvSmooth the orientation map will be broken.
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);
}
Asked: 2012-10-24 04:25:11 -0600
Seen: 866 times
Last updated: Nov 11 '12
Getting a smooth outline for a picture
Find how smooth or rough a surface in an image is
Output image which combine pixels from different smoothing filter mask
Gaussian smoothing of cv::Mat column
Smoothing Floatingpoint Mat, with a mask
Efficient way to scan an image with a window
Get smoothing point using B-spline curve C++
Smoothing motion by using Kalman Filter or Particle Filter in video stabilization
What do you mean by the orientation map? Are you talking about affine or perspective transformation matrices? Please update your question with more details.
Please search "fingerprint orientation map" .