- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am tring to use ippiCrossCorrValid_Norm_16u32f_C1R function to calculate cross correlation between a square template and rectangular search window. Some how my code works only if i take a square seach window and not with rectangular search window.
here i give a small sample code that create problem,
int blockSize=3; // template size 3x3
int searchWSizeX=9;
int searchWSizeY=5;
int resultWindowSizeX=7;
int resultWindowSizeY=3;
int resultWindowTSize=resultWindowSizeX*resultWindowSizeY;
// i tried with ippmalloc, but i got same result
// template
unsigned short temp[]={697,666,618,666,669,591,666,591,512};
//search window
unsigned short image[]={669, 669, 690, 690, 693, 673, 710, 669, 659,
690, 663, 669, 714, 687, 687, 700, 680, 683,
700, 673, 700, 731, 690, 707, 727, 690, 666,
693, 714, 687, 714, 680, 669, 676, 721, 683,
707, 666, 704, 707, 618, 663, 700, 704, 680
};
IppStatus status;
int tplStep=blockSize*sizeof(Ipp16u); // ipp16u nothing but unsigned short
IppiSize tplRoiSize,srcRoiSize;
tplRoiSize.height=blockSize;
tplRoiSize.width=blockSize;
int srcStep=searchWSizeX*sizeof(Ipp16u);
srcRoiSize.height=searchWSizeY;
srcRoiSize.width=searchWSizeX;
Ipp32f* pDst;
pDst=ippsMalloc_32f(resultWindowTSize);
int dstStep=resultWindowSizeX*sizeof(Ipp32f);
status=ippiCrossCorrValid_Norm_16u32f_C1R(image,srcStep,srcRoiSize,temp,tplStep,tplRoiSize,pDst,dstStep);
if(status==ippStsNoErr)
{
&nbs p; printf("No error");
}
else
{
printf("error number %d ",status);
}
// print the result
for(int r=0;r
for(int s=0;s
fprintf(fp1,"%f ",pDst[resultWindowSizeY*r +s]);
}
fprintf(fp1," ");
}
ippsFree(temp);
ippsFree(image)
I expect to get some result of size 7x3 having the following values as ( i got first 3x3 values hand calculated and verified with matlab)
9.95402310773594E-01 |
9.93216121828153E-01 | 9.95709101211673E-01 |
9.95513545974447E-01 | 9.94066090279466E-01 | 9.96289650300696E-01 |
9.96263594187887E-01 | 9.94619810815054E-01 | 9.98277076699970E-01 |
I am getting the first line of the result as correct, but last 2 lines incorrect.
Anybody please help me
Thank you
Daniel
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Daniel,
our expert recommends you to try the following piece of code (this is reference code according to the formulae and provides results identical with IPP. We do not know how it was implemented in MATLAB)
#include
#include "ipp.h"
IppStatus altCrossCorrValid_Norm_16u32f_C1R(
Ipp16u* src,
int srcStep,
IppiSize srcSize,
Ipp16u* tpl,
int tplStep,
IppiSize tplSize,
Ipp32f* dst,
int dstStep)
{
int elmSize = sizeof(Ipp16u);
int sStep = srcStep/elmSize;
int tStep = tplStep/elmSize;
int rStep = dstStep/4;
int rWidth = srcSize.width - tplSize.width + 1;
int rHeight = srcSize.height - tplSize.height + 1;
int tWidth = tplSize.width;
int tHeight = tplSize.height;
Ipp32f thresh;
Ipp16u* tmpSrc, *tmpTpl;
double tplL2;
int i, j, hT, wT;
ippiNorm_L2_16u_C1R( tpl, tplStep, tplSize, &tplL2 );
if( elmSize > 2 )
thresh = 1;
else
thresh = 5e-4;
for( i = 0; i < rHeight; i++)
{
for( j = 0; j < rWidth; j++)
{
Ipp32f tmpSum = 0.0f;
Ipp32f tmpSqrt = 0.0f;
tmpSrc = src + j;
tmpTpl = tpl;
for( hT = 0; hT < tHeight; hT++)
{
for( wT = 0; wT < tWidth; wT++)
{
tmpSum += (Ipp32f)tmpSrc[wT] * (Ipp32f)tmpTpl[wT];
tmpSqrt += (Ipp32f)tmpSrc[wT] * (Ipp32f)tmpSrc[wT];
} /* for */< p="">>
tmpSrc += sStep;
tmpTpl += tStep;
} /* for */
if( tplL2 < thresh )
tplL2 = thresh;
if( tmpSqrt < thresh )
tmpSqrt = thresh;
tmpSqrt = tmpSqrt * (Ipp32f)(tplL2 * tplL2);
tmpSqrt = (Ipp32f)(1.0/sqrt(tmpSqrt));
dst
= tmpSum * tmpSqrt; } /* for */
src += sStep;
dst += rStep;
} /* for */
return (IppStatus)0;
}
int main()
{
int blockSize = 3;// template size 3x3
int searchWSizeX = 9;
int searchWSizeY = 5;
int resultWindowSizeX = 7;
int resultWindowSizeY = 3;
int resultWindowTSize = resultWindowSizeX * resultWindowSizeY;
int r, s;
// i tried with ippmalloc, but i got same result
// template
unsigned short temp[] =
{
697, 666, 618, 666, 669, 591, 666, 591, 512
};
//search window
unsigned short image[] =
{
669, 669, 690, 690, 693, 673, 710, 669, 659,
690, 663, 669, 714, 687, 687, 700, 680, 683,
700, 673, 700, 731, 690, 707, 727, 690, 666,
693,&nb sp; 714, 687, 714, 680, 669, 676, 721, 683,
707, 666, 704, 707, 618, 663, 700, 704, 680
};
IppStatus status;
int tplStep = blockSize * sizeof(Ipp16u); // ipp16u nothing but unsigned short
IppiSize tplRoiSize, srcRoiSize;
int srcStep = searchWSizeX * sizeof(Ipp16u);
int dstStep = resultWindowSizeX * sizeof(Ipp32f);
Ipp32f* pDst;
tplRoiSize.height = blockSize;
tplRoiSize.width = blockSize;
srcRoiSize.height = searchWSizeY;
srcRoiSize.width = searchWSizeX;
pDst = ippsMalloc_32f(resultWindowTSize);
status=altCrossCorrValid_Norm_16u32f_C1R(image,srcStep,srcRoiSize,temp,tplStep,tplRoiSize,pDst,dstStep);
// status=ippiCrossCorrValid_Norm_16u32f_C1R(image,srcStep,srcRoiSize,temp,tplStep,tplRoiSize,pDst,dstStep);
if(status == ippStsNoErr)
{
printf("No error ");
}
else
{
printf("error number %d ",status);
}
// print the result
for(r = 0; r < resultWindowSizeY; r++)
{
for(s = 0; s < resultWindowSizeX; s++)
{
printf("%f ",pDst[resultWindowSizeY*r +s]);
}
printf(" ");
}
ippsFree(temp);
ippsFree(image);
return 0;
}
Regards,
Vladimir
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page