Showing results for 
Search instead for 
Did you mean: 

Different results from ippiMoments64f_16u_C1R moving roi.


I have to calculate the center of gravity of image stacks. This I have implemented with the ippiMoments64s_16u_C1R function. The x and y center coordinates of a image plane I get from ippiGetSpatialMoment_64s as x=m10/m00 and y=m01/m00 as described in the ipp 5.3 manual on page 750. This works fine as long as I use the full image. Using a roi shifts the center coordinates.

On 8 bit black and white data this looks like this (simplified):

IppiPoint roiOffset;
IppiSize roiSize;
int stepBytes;
IppiMomentState_64s* m_pMoments;
void* i_vpSrcData; // in "real life" this is a const pointer
// ... init roiOffset, roiSize, stepBytes, m_pMoments
int pOffset = roiSize.width * roiOffset.y + roiOffset.x;
Ipp8u* pTmp = (Ipp8u*)i_vpSrcData + pOffset;
ippiMoments64s_8u_C1R(pTmp, stepBytes, roiSize, m_pMoments);
Ipp64s m00;
ippiGetSpatialMoment_64s(m_pMoments, 0, 0, 0, roiOffset, &m00, 1);
Ipp64s m10;
ippiGetSpatialMoment_64s(m_pMoments, 1, 0, 0, roiOffset, &m10, 1);
Ipp64s m01;
ippiGetSpatialMoment_64s(m_pMoments, 0, 1, 0, roiOffset, &m01, 1);
Ipp64s xCenter = (m10 / m00);
Ipp64s yCenter = (m01 / m00);

In an image (128*128 Pixels) with black background a roughly centered circle, radius 10 pixels is found correctly. The data for the calculation are:
roiOffset = {0,0};
roiSize = {128,128};
stepBytes = 128;

Correct result: x=62, y=62.

If I set a roi of 40/40 at 45/45 the result is wrong. Used Data:

roiOffset = {45,45};
roiSize = {40,40};
stepBytes = 128;

Wrong result: x=54, y=83.

Any idea of what I am doing wrong?

Thanks in advance,


0 Kudos
0 Replies