Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

## Why is ippiRotate not giving me correct results?

Beginner
631 Views

I'm having trouble getting an image to rotate in some code I'm working on. This is the problem I'm having:

1. I have a source image. It has a size (w, h) which is not necessarily square.
2. It is going to be rotated by angle a.
3. I've calculated the output size required to fit an image of size (w, h) rotated by angle a using a bit 'o trig. This size is (dw, dh), and I can verify on paper it is being computed correctly.

I cannot get ippiRotate to center the rotated image in the destination image. It's always off center.

My best guess for what xShift and yShift should be is the following:

xShift = (dw / 2.0) - (w / 2.0)
yShift = (dh / 2.0) - (h / 2.0)

But this doesn't work, and I'm not sure what else to do to calculate xShift and yShift.I've attempted to use ippiGetRotateShift to calculate xShift and yShift, again, to no avail.

I originally tried this, thinking that it would center my rotated image in the destination image:

ippiGetRotateShift(dw / 2.0, dh / 2.0, a, &xShift, &yShift);

But it doesn't it's very much off center. If I do this:

ippiGetRotateShift(w / 2.0, h / 2.0, a, &xShift, &yShift);

It's not as off center, but it's still off.
I'm at the end of my rope here, I need to get this working ASAP, I'd really appreciate any help I can get.

8 Replies
Employee
631 Views
Well, you always can check your implementation with IPP samples which are available fordownload from IPP product page. Please pay attention to ipp-samplesimage-processing folder where you will find several application which showcase the use of IPP functions for image processing.

Regards,
Vladimir
Beginner
631 Views
Well, you always can check your implementation with IPP samples which are available fordownload from IPP product page. Please pay attention to ipp-samplesimage-processing folder where you will find several application which showcase the use of IPP functions for image processing.

Regards,
Vladimir

Thanks, but the samples aren't much of a help in this case - I've scoured over them, but none of them that deal with rotation appear to be doing what I'm looking for - rotating aninput bufferaround it's center, and centering that rotated image in a destination buffer that is sized to fit the rotated input. That seems to be impossible to get right. I'm surprised that such a simple sounding task is so difficult to do with either IPL or IPP.
Employee
631 Views
Did you noticed ippiRotateCenter function? Might be this what you are looking for?

Regards,
Vladimir
Beginner
631 Views
Did you noticed ippiRotateCenter function? Might be this what you are looking for?

Regards,
Vladimir

ippiRotateCenter does not work either.
Employee
631 Views
Hello,

could you please attach output images you get with IPP function and what should be correct from your point of view?

Regards,
Vladimir
Beginner
631 Views
Hello,

could you please attach output images you get with IPP function and what should be correct from your point of view?

Regards,
Vladimir

Hi,

I'll post some images later, but right now, I need to know if what I'm trying to accomplish is even possible with IPP. Unfortunately it seems it isn't - which is surprising to me because what I'm trying to do is conceptually very simple.

I want to rotate an image by an arbitrary angle. I want the rotated image to fit entirely within the destination image. If I have a 20x20 image of a square that is rotated by 90 degrees, I want the destination image to show the entire rotated square. I want the rotated square to be at the very center of the destination image.

I don't understand why this has to be so difficult to accomplish in IPP. In all of the searching I've done I've only found one or two other people trying to accomplish what I'm trying to do, and the responses to their questions did not help me. I'm very frustrated. If I can't get this to work, I'm going to ditch IPP and find a better way of rotating images. It's not worth wasting my time with this.
New Contributor I
631 Views
Quoting - unforgiven3

Hi,

I'll post some images later, but right now, I need to know if what I'm trying to accomplish is even possible with IPP. Unfortunately it seems it isn't - which is surprising to me because what I'm trying to do is conceptually very simple.

I want to rotate an image by an arbitrary angle. I want the rotated image to fit entirely within the destination image. If I have a 20x20 image of a square that is rotated by 90 degrees, I want the destination image to show the entire rotated square. I want the rotated square to be at the very center of the destination image.

I don't understand why this has to be so difficult to accomplish in IPP. In all of the searching I've done I've only found one or two other people trying to accomplish what I'm trying to do, and the responses to their questions did not help me. I'm very frustrated. If I can't get this to work, I'm going to ditch IPP and find a better way of rotating images. It's not worth wasting my time with this.
Hi,

Please don't let the trouble get the better of you. It is not that difficult with IPP, you are almost there, this works for me:

int xOffset = (dw-w)/2;
int yOffset = (dh-h)/2;

double xShift,yShift;
ippiGetRotateShift(w/2, h/2, a, &xShift, &yShift);
if ( xOffset > 0 )
xShift += xOffset;
if ( yOffset > 0 )
yShift += yOffset;

and call ippiRotate.

Regards,

Rob
Beginner
631 Views
Quoting - Rob Ottenhoff
Hi,

Please don't let the trouble get the better of you. It is not that difficult with IPP, you are almost there, this works for me:

int xOffset = (dw-w)/2;
int yOffset = (dh-h)/2;

double xShift,yShift;
ippiGetRotateShift(w/2, h/2, a, &xShift, &yShift);
if ( xOffset > 0 )
xShift += xOffset;
if ( yOffset > 0 )
yShift += yOffset;

and call ippiRotate.

Regards,

Rob

This is *exactly* what I needed. Thank you very much!

-HDaSilva