Search code examples
cintel-ippnpp

How to calculate image rotation shift for NPP?


ippiGetRotateTransform and nppiRotate both take x and y shift parameters but I am unsure how they work. IPP and NPP both rotate around (0, 0) then shift the result. This example shows using ippiGetRotateShift to rotate around the center, but does not explain how it is used.

Relevant part of the example:

Ipp8u src[4*4] = ...;
Ipp8u dst[6*6];
double xShift;
double yShift;
double xShiftTmp;
double yShiftTmp;
double xCenterSrc = 2.0;  
double yCenterSrc = 2.0; 
double xCenterDst = 3.5;
double yCenterDst = 2.5;
double angle = 35.0;
ippiGetRotateShift ( xCenterSrc, yCenterSrc, angle, &xShift, &yShift );
/* xShift = -0.79 , yShift = 1.51 */
ippiGetRotateShift ( 1.0, 1.0, angle, &xShiftTmp, &yShiftTmp);
xShift += xShiftTmp; yShift += yShiftTmp; 
/* xShift = -1.18, yShift = 2.26 */
xShift += xCenterDst - xCenterSrc;
yShift += yCenterDst - yCenterSrc;
/* xShift = 0.32, yShift = 2.76 */

The example documents what the values change to but not how or why. Even the destination center point is unexplained. Why is it (3.5, 2.5) instead of (3, 3)?

Anyway, the x and y shift parameters appear to behave the same. How can I calculate them for NPP without depending on IPP?


Solution

  • Alright, working out the math. It seems ippiGetRotateShift returns the difference of P and P' after rotation. (P'.x = x - x cos(-angle) - y sin(-angle); P'.y = y cos(-angle) + x sin(-angle)).