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

Optimized (un)rotation of rectangular ROI

zxs
Beginner
440 Views
I have an 8-bit grayscale image (e.g. 1000x1000) and rotated rectangular
ROI (typically 8x32).

I want to copy this rotated ROI to a regular C-style 2D array.
In other words I want to undo rotation of the ROI and convert it to
an easy-to-use 2D array.

The array's values must be computed using bilinear interpolation.

ROI's width and height are integers.
ROI's origin and rotation angle are "float"-s.
Does there exist an IPP function which would allow me to do this efficiently?
WarpBiliniar is more powerful than necessary for this taskand, as a result, isn't fast enough. All other geometric image transformation functions I checked seem to be not quite suitable. Am I missing something?
0 Kudos
4 Replies
Intel_C_Intel
Employee
440 Views

Hi

You can try to use the ippWarpAffineQuad function with interpolation IPPI_INTER_LINEAR.

It performs an Affine transform (Rotate is a subset of Affine Transform) from src Quadrangle to dst Quadrangle.

You should specify the vertexes of srcQuad by the values of the coordinates of the rotated ROI. You can use ippiGetRotateQuad to get coordinates of rotated ROI.

You need to set up the dstQuad as rectangle.

Ipp8u arr2D[32][8];

IppRect dstROI = {0,0,8,32}, srcFull = {0, 0, srcWidth, srcHeight};

double dstQuad = {{0,0},{0,7},{7,31},{0,31}};

ippiGetRotateQuad(srcRoi, srcQuad, angle, xShift, yShift);

ippiWarpAffineQuad(pSrc, srcSize, srcStep, srcFull, srcQuad, arr2D, 8, dstROI, dstQuad, IPPI_INTER_LINEAR);

look at the picture attached

Regards, Vladimir

Message Edited by vdudnik on 05-24-2004 09:05 PM

Message Edited by vdudnik on 05-24-2004 09:11 PM

Message Edited by vdudnik on 05-24-2004 10:12 PM

0 Kudos
Intel_C_Intel
Employee
440 Views

You can try to use the ippWarpAffineQuad function with interpolation IPPI_INTER_LINEAR.

It performs an Affine transform (Rotate is a subset of Affine Transform) from src Quadrangle to dst Quadrangle.

You should specify the vertexes of srcQuad by the values of the coordinates of the rotated ROI. You can use ippiGetRotateQuad to get coordinates of rotated ROI.

You need to set up the dstQuad as rectangle.

Ipp8u arr2D[32][8];

IppRect dstROI = {0,0,8,32}, srcFull = {0, 0, srcWidth, srcHeight};

double dstQuad = {{0,0},{0,7},{7,31},{0,31}};

ippiGetRotateQuad(srcRoi, srcQuad, angle, xShift, yShift);

ippiWarpAffineQuad(pSrc, srcSize, srcStep, srcFull, srcQuad, arr2D, 8, dstROI, dstQuad,

IPPI_INTER_LINEAR);

0 Kudos
zxs
Beginner
440 Views
Thanks, I guess WarpAffine must be faster than the function I previously tried. I will have to test it for my data and report the result later.

Another issue left is data types. Ideally I want to have Ipp32f output and "standard" Ipp8u input. Of course, I can live with Ipp8u output, but it will introduce some unnecessary interpolation error. Alternatively, I can pre-convert my 8u input to 32f.

But still IMHO it's probably an overlook in IPP function set: IPP supports functions to perform image rotation (i.e. to convert axis-aligned ROI to a rotated one) but there are no explicit functions to do "un-rotation" (i.e. convert rotated ROI to axis-aligned one).

This might make sense if Rotate functions are just shortcuts for WarpAffine. Is this guess correct?
0 Kudos
Intel_C_Intel
Employee
440 Views

Hi, please find comments with "--"

Thanks, I guess WarpAffine must be faster than the function I previously tried. I will have to test it for my data and report the result later.

Another issue left is data types. Ideally I want to have Ipp32f output and "standard" Ipp8u input. Of course, I can live with Ipp8u output, but it will introduce some unnecessary interpolation error. Alternatively, I can pre-convert my 8u input to 32f.
--Yes, you can preconvert 8u input to 32f, and use ipp functions with 32f flavor.

But still IMHO it's probably an overlook in IPP function set: IPP supports functions to perform image rotation (i.e. to convert axis-aligned ROI to a rotated one) but there are no explicit functions to do "un-rotation" (i.e. convert rotated ROI to axis-aligned one).

This might make sense if Rotate functions are just shortcuts for WarpAffine. Is this guess correct?
--Yes, you are right. Rotate uses WarpAffine for most of angles. With WarpAffine you can do any Rotate operation you need

Regards,
Vladimir
0 Kudos
Reply