Community
cancel
Showing results for 
Search instead for 
Did you mean: 
haerle1
Beginner
48 Views

ROI problem with ippiMoments64f

Hello,

I am calculation the center of mass of an image using the ippiMoments64f_16u_C1R and the ippiGetSpatialMoment_64f functions. This only works if my roi starts at 0/0.

To give a copy'n'paste example:

IppiSize roiSize;
roiSize.height = 100;
roiSize.width = 100;
IppiPoint roiOffset;
roiOffset.x = 500;
roiOffset.y = 500;
int pOffset = roiSize.width * roiOffset.y + roiOffset.x;
Ipp16u* pSrc = (Ipp16u*)i_vpSrcData + pOffset; // i_vpSrcData is a pointer to a mem block containing an image of 1344*1024 unsigned short image
int bytesPerScanLine = 2688;
IppiMomentState_64f* m_pMoments;
ippiMomentInitAlloc_64f(&m_pMoments, ippAlgHintNone);
ippiMoments64f_16u_C1R(pSrc,bytesPerScanLine, roiSize, m_pMoments);

Ipp64f m00;
ippiGetSpatialMoment_64f(m_pMoments, 0, 0, 0, roiOffset, &m00);
Ipp64f m10;
ippiGetSpatialMoment_64f(m_pMoments, 1, 0, 0, roiOffset, &m10);
Ipp64f m01;
ippiGetSpatialMoment_64f(m_pMoments, 0, 1, 0, roiOffset, &m01);

Ipp64f xCenter = (m10 / m00);
Ipp64f yCenter = (m01 / m00);

ippiMomentFree_64f(m_pMoments);

The results for xCenter and yCenter are definitely wrong even if a simple object is in the roi. Only if my roi starts at 0/0 I get correct results. Do you have any idea about what I am doing wrong?

Best regards,

Fabian

0 Kudos
1 Reply
matthieu_darbois
New Contributor III
48 Views

Quoting - haerle@embl.de

Hello,

I am calculation the center of mass of an image using the ippiMoments64f_16u_C1R and the ippiGetSpatialMoment_64f functions. This only works if my roi starts at 0/0.

To give a copy'n'paste example:

IppiSize roiSize;
roiSize.height = 100;
roiSize.width = 100;
IppiPoint roiOffset;
roiOffset.x = 500;
roiOffset.y = 500;
int pOffset = roiSize.width * roiOffset.y + roiOffset.x;
Ipp16u* pSrc = (Ipp16u*)i_vpSrcData + pOffset; // i_vpSrcData is a pointer to a mem block containing an image of 1344*1024 unsigned short image
int bytesPerScanLine = 2688;
IppiMomentState_64f* m_pMoments;
ippiMomentInitAlloc_64f(&m_pMoments, ippAlgHintNone);
ippiMoments64f_16u_C1R(pSrc,bytesPerScanLine, roiSize, m_pMoments);

Ipp64f m00;
ippiGetSpatialMoment_64f(m_pMoments, 0, 0, 0, roiOffset, &m00);
Ipp64f m10;
ippiGetSpatialMoment_64f(m_pMoments, 1, 0, 0, roiOffset, &m10);
Ipp64f m01;
ippiGetSpatialMoment_64f(m_pMoments, 0, 1, 0, roiOffset, &m01);

Ipp64f xCenter = (m10 / m00);
Ipp64f yCenter = (m01 / m00);

ippiMomentFree_64f(m_pMoments);

The results for xCenter and yCenter are definitely wrong even if a simple object is in the roi. Only if my roi starts at 0/0 I get correct results. Do you have any idea about what I am doing wrong?

Best regards,

Fabian

Hi Fabian,

From what I can read, I think that the pOffset line is incorrect, you're using roiSize.width as step for your source image. It should be something like that : int pOffset = bytesPerScanLine * roiOffset.y + roiOffset.x;

That being said, another error would appear at this line : Ipp16u* pSrc = (Ipp16u*)i_vpSrcData + pOffset;

It should now be : Ipp16u* pSrc = (Ipp16u*)((Ipp8u*)i_vpSrcData + pOffset);

Regards,

Matthieu