Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
6815 Discussions

How to correctly use ippiRotate to get expected result

Xiang_Ma
Beginner
987 Views
I need to rotate an imagewhich is 16 bitswith a w/h. After rotation, the new rotated image should have bigger size. say (w+ deltaW)/(h+deltaH).

I found it only work correctly for some size images (say 640x512), but not correct for other size image- image is distorted a lot.

Following is my code. Thanks very much for any help to find what is wrong on this code.


void Rotate(
unsigned short *pInputImage,
int m_iImage_width,
int m_iImage_height,
double angle,
bool bKeepOrigiImageSize,
unsigned short *& pRotatedImage, // rotated image
int & rImage_Width, // rotated image width
int &rImage_Height, // rotated image height
int iInterpolationMethod)

{

double xShift= 0;

double yShift= 0;

double xCenterSrc = m_iImage_width/2.0;

double yCenterSrc = m_iImage_height/2.0;

double bound[2][2];

IppStatus Status;

int srcStep_16u= 0;

int desStep_16u =0;

IppiSize srcSize = { m_iImage_width, m_iImage_height };

IppiRect srcRect = { 0, 0, m_iImage_width, m_iImage_height };

// find rotate shift

Status = ippiGetRotateShift ( xCenterSrc, yCenterSrc, angle, &xShift, &yShift );

// find rotated boundary box

Status = ippiGetRotateBound ( srcRect, bound, angle, xShift, yShift);

double xTotalShift = xShift;

double yTotalShift = yShift;

if ( !bKeepOrigiImageSize)

{

rImage_Width = bound[1][0] - bound[0][0]+1;

rImage_Height = bound[1][1] - bound[0][1]+1;

xTotalShift = xTotalShift - bound[0][0];

yTotalShift = yTotalShift - bound[0][1];

}

else

{

rImage_Width = m_iImage_width;

rImage_Height = m_iImage_height;

}

IppiRect dstRect = { 0,0, rImage_Width , rImage_Height };

IppiSize dstSize = { rImage_Width, rImage_Height};

// allocate memory

Ipp16u *pIpp16Images = ippiMalloc_16u_C1(m_iImage_width, m_iImage_height, &srcStep_16u);
// Where I should use srcStep_16u?

Ipp16u *pIpp16Imaged = ippiMalloc_16u_C1(rImage_Width , rImage_Height, &desStep_16u);

// Where I should use desStep_16u?

Status = ippiSet_16u_C1R(0, pIpp16Imaged, desStep_16u, dstSize);

// should I use memcpy or ippiCopy_16u_C1R?

memcpy(pIpp16Images,pInputImage,m_iImage_width* m_iImage_height*sizeof(Ipp16u));

Status = ippiRotate_16u_C1R(pIpp16Images, srcSize, 2*m_iImage_width, srcRect, pIpp16Imaged, 2*(rImage_Width), dstRect, angle, xTotalShift, yTotalShift, iInterpolationMethod);

pRotatedImage = new unsigned short[rImage_Width * rImage_Height];

memcpy(pRotatedImage,pIpp16Imaged,rImage_Width * rImage_Height*sizeof(unsigned short));

ippiFree(pIpp16Images);

ippiFree(pIpp16Imaged);

}

0 Kudos
1 Reply
Chao_Y_Intel
Moderator
987 Views


Hello,

The image step does not look correct in the code.


Change:
memcpy(pIpp16Images,pInputImage,m_iImage_width* m_iImage_height*sizeof(Ipp16u));

Status = ippiRotate_16u_C1R(pIpp16Images, srcSize, 2*m_iImage_width, srcRect, pIpp16Imaged, 2*(rImage_Width), dstRect, angle, xTotalShift, yTotalShift, iInterpolationMethod);

memcpy(pRotatedImage,pIpp16Imaged,rImage_Width * rImage_Height*sizeof(unsigned short));

to the followngs:
ippiCopy_16u_C1R( pInputImage, m_iImage_width*sizeof(Ipp16u), pIpp16Images, srcStep_16u, srcSize);

Status = ippiRotate_16u_C1R(pIpp16Images, srcSize, srcStep_16u, srcRect, pIpp16Imaged, desStep_16u, dstRect, angle, xTotalShift, yTotalShift, iInterpolationMethod);

ippiCopy_16u_C1R( pIpp16Imaged, desStep_16u, pRotatedImage, rImage_Width*sizeof(unsigned short), dstSize);

The article may provide more information on this problem.

http://software.intel.com/sites/products/documentation/hpc/ipp/ippi/ippi_ch2/ch2_regions_of_interest_in_intel_ipp.html

Thanks,
Chao

0 Kudos
Reply