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

32 bit image scaler

dolevo_j_
Beginner
867 Views

Hi all,

This is my first question in this forum so be gentle please.

I have been using IPP 7.0 and currently I am trying to implement a scaler to scale my 32 bit image to its new resolution without changing anything else. Here is what I have done but I am lost in ippiResizeSqrPixel_8u_C4R function.

Could you please guide me through?

              IppiRectoldRect,newRect;

oldRect.x=0; oldRect.y=0; oldRect.height=1024; oldRect.width=768;
newRect.x=0; newRect.y=0; newRect.height=800; newRect.width=600;
Ipp8u *newImage=ippsMalloc_8u(newRect.height*newRect.width*4);
ippiResizeSqrPixel_8u_C4R(oldImage,oldRect.height*oldRect.width*4,oldRect.width,oldRect,newImage,newRect.width,newRect,,,,,);

Regards,

0 Kudos
5 Replies
Igor_A_Intel
Employee
867 Views

Hi,

take a look at the header file:

/* /////////////////////////////////////////////////////////////////////////////
//
//  Name:               ippiResizeSqrPixel
//  Purpose:            Performs RESIZE transform of the source image by xFactor and yFactor
//                            |X'|   |xFactor    0   |   |X|   |xShift|
//                            |  | = |               | * | | + |      |
//                            |Y'|   |   0    yFactor|   |Y|   |yShift|
//  Parameters:
//    pSrc              source image data
//    srcSize           size of source image
//    srcStep           step in source image
//    srcROI            region of interest of source image
//    pDst              resultant image data
//    dstStep           step in destination image
//    dstROI            region of interest of destination image
//    xFactor, yFactor  they specify fractions of resizing
//    xShift, yShift    they specify shifts of resizing
//    interpolation     type of interpolation to perform for resizing the input image:
//                        IPPI_INTER_NN      Nearest Neighbor interpolation
//                        IPPI_INTER_LINEAR  Linear interpolation
//                        IPPI_INTER_CUBIC   Cubic polynomial interpolation
//                        IPPI_INTER_LANCZOS Interpolation by Lanczos3-windowed sinc function
//                        IPPI_INTER_SUPER   Super Sampling method
//                      including two-parameter cubic filters:
//                        IPPI_INTER_CUBIC2P_BSPLINE    B-spline filter (1, 0)
//                        IPPI_INTER_CUBIC2P_CATMULLROM Catmull-Rom filter (0, 1/2)
//                        IPPI_INTER_CUBIC2P_B05C03     Special filter with parameters (1/2, 3/10)
//                      including special feature for smoothing:
//                        IPPI_SMOOTH_EDGE    Edges smoothing in addition to one of the above methods
//                        IPPI_SUBPIXEL_EDGE Edges handling in addition to one of general methods
//                      including special feature for antialiasing:
//                        IPPI_ANTIALIASING  Anti-aliasing method in addition to Linear/Cubic/Lanczos
//    pBuffer           pointer to work buffer
//  Returns:
//    ippStsNoErr             no errors
//    ippStsNullPtrErr        pSrc == NULL or pDst == NULL or pBuffer == NULL
//    ippStsSizeErr           width or height of images is less or equal zero
//    ippStsWrongIntersectROI srcROI has not intersection with the source image, no operation
//    ippStsResizeFactorErr   xFactor or yFactor is less or equal zero
//    ippStsInterpolationErr  interpolation has an illegal value
//    ippStsNoAntialiasing    mode does not support antialiasing
*/

so the 2nd parameter should be a structure as is defined at ippdefs.h:

typedef struct {
    int width;
    int height;
} IppiSize;

also you should start from the maual that contains very simple example on ResizeSqrPixel usage:

IppStatus ResizeSqrPixel( void )

{

Ipp32f src[12*12], dst[12*12];

IppiSize size = {12,12};

IppiRect srect = {0,0,12,12};

IppiRect drect = {0,0,6,6};

Ipp8u *buf;

int bufsize , I;

IppStatus status = ippStsNoErr;

702

12

Intel®

Integrated Performance Primitives Reference Manual, Volume 2: Image and Video Processing

/* source image */

{

IppiSize roi = {12,12};

for( I=0; i<12; ++I ) {

ippiSet_32f_C1R( (Ipp32f)I, src+12*i+i, 12*sizeof(Ipp32f), roi );

--roi.width;

--roi.height;

}

}

/* calculation of work buffer size */

ippiResizeGetBufSize( srect, drect, 1, IPPI_INTER_SUPER, &bufsize );

/* memory allocate */

buf = ippsMalloc_8u( bufsize );

/* function call */

if( NULL != buf )

status = ippiResizeSqrPixel_32f_C1R(

src, size, 12*sizeof(Ipp32f), srect,

dst, 6*sizeof(Ipp32f), drect,

0.5, 0.5, 0, 0, IPPI_INTER_SUPER, buf );

/* memory free */

if( NULL != buf ) ippsFree( buf );

return status;

}

The source image

0 0 0 0 0 0 0 0 0 0 0 0

0 1 1 1 1 1 1 1 1 1 1 1

0 1 2 2 2 2 2 2 2 2 2 2

0 1 2 3 3 3 3 3 3 3 3 3

0 1 2 3 4 4 4 4 4 4 4 4

0 1 2 3 4 5 5 5 5 5 5 5

0 1 2 3 4 5 6 6 6 6 6 6

0 1 2 3 4 5 6 7 7 7 7 7

0 1 2 3 4 5 6 7 8 8 8 8

703

Image Geometry Transforms

12

0 1 2 3 4 5 6 7 8 9 9 9

0 1 2 3 4 5 6 7 8 9 10 10

0 1 2 3 4 5 6 7 8 9 10 11

The image has the following contents after resizing with NEAREST NEIGHBOR interpolation

1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000

1.0000000 3.0000000 3.0000000 3.0000000 3.0000000 3.0000000

1.0000000 3.0000000 5.0000000 5.0000000 5.0000000 5.0000000

1.0000000 3.0000000 5.0000000 7.0000000 7.0000000 7.0000000

1.0000000 3.0000000 5.0000000 7.0000000 9.0000000 9.0000000

1.0000000 3.0000000 5.0000000 7.0000000 9.0000000 11.0000000

The image has the following contents after resizing with LINEAR interpolation

0.25000000 0.5000000 0.5000000 0.5000000 0.5000000 0.5000000

0.50000000 2.2500000 2.5000000 2.5000000 2.5000000 2.5000000

0.50000000 2.5000000 4.2500000 4.5000000 4.5000000 4.5000000

0.50000000 2.5000000 4.5000000 6.2500000 6.5000000 6.5000000

0.50000000 2.5000000 4.5000000 6.5000000 8.2500000 8.5000000

0.50000000 2.5000000 4.5000000 6.5000000 8.5000000 11.2500000

The image has the following contents after resizing with CUBIC interpolation

0.25390625 0.4335938 0.4375000 0.4375000 0.4375000 0.4375000

0.43359375 2.3828125 2.4960938 2.5000000 2.5000000 2.5000000

0.43750000 2.4960938 4.3828125 4.4960938 4.5000000 4.5000000

0.43750000 2.5000000 4.4960938 6.3828125 6.4960938 6.5000000

0.43750000 2.5000000 4.5000000 6.4960938 8.3828125 8.4960938

0.43750000 2.5000000 4.5000000 6.5000000 8.4960938 10.3789060

The image has the following contents after resizing with LANCZOS interpolation

0.26301101 0.3761742 0.4124454 0.4130435 0.4130435 0.4130435

0.37617415 2.4499352 2.4631310 2.4994020 2.5000002 2.5000002

704

12

Intel®

Integrated Performance Primitives Reference Manual, Volume 2: Image and Video Processing

0.41244543 2.4631310 4.4499354 4.4631310 4.4994025 4.5000005

0.41304356 2.4994023 4.4631310 6.4499359 6.4631314 6.4994025

0.41304356 2.5000005 4.4994020 6.4631314 8.4499359 8.4631310

0.41304356 2.5000005 4.5000000 6.4994025 8.4631310 10.4369250

The image has the following contents after resizing with SUPERSAMPLING interpolation

0.25000000 0.5000000 0.5000000 0.5000000 0.5000000 0.5000000

0.50000000 2.2500000 2.5000000 2.5000000 2.5000000 2.5000000

0.50000000 2.5000000 4.2500000 4.5000000 4.5000000 4.5000000

0.50000000 2.5000000 4.5000000 6.2500000 6.5000000 6.5000000

0.50000000 2.5000000 4.5000000 6.5000000 8.2500000 8.5000000

0.50000000 2.5000000 4.5000000 6.5000000 8.5000000 10.2500000

regards, Igor

0 Kudos
dolevo_j_
Beginner
867 Views

Is there any other API to scale the 32 bit image to a new 32 bit image? In ippiResizeSqrPixel, I need to probide xFactor parameters which I don't want. I just want to give the new resolution that I want, that's it. Is this possible?

0 Kudos
Igor_A_Intel
Employee
867 Views

In such case please use the new Resize API (available since 7.1):

IPPAPI (IppStatus, ippiResizeGetSize_8u, (
    IppiSize srcSize, IppiSize dstSize,
    IppiInterpolationType interpolation, Ipp32u antialiasing,
    Ipp32s* pSpecSize, Ipp32s* pInitBufSize))

IPPAPI (IppStatus, ippiResizeNearestInit_8u, (
    IppiSize srcSize, IppiSize dstSize,
    IppiResizeSpec_32f* pSpec))

IPPAPI (IppStatus, ippiResizeNearest_8u_C4R, (
    const Ipp8u* pSrc, Ipp32s srcStep,
    Ipp8u* pDst, Ipp32s dstStep, IppiPoint dstOffset, IppiSize dstSize,
    IppiResizeSpec_32f* pSpec, Ipp8u* pBuffer))

where "Nearest" suffix can be substituted with Linear, Cubic, Lanczos or Super (Super provides the best quality for decreasing resolution)

Regards, Igor

0 Kudos
dolevo_j_
Beginner
867 Views

Hi,

Thanks for your input but I couldn't get it working. I have the following code:


Ipp32s specSize = 0;
pSpec = (IppiResizeSpec_32f*)ippsMalloc_8u(specSize);
status = ippiResizeNearest_8u_C4R(SrcRGB32, srcWidthStep, DstRGB32, dstWidthStep, dstOffset, dstSize, pSpec, buf);

where
   SrcRGB32 = 32 bit source image in pixel format 1920x1200
   srcWidthStep = 7680
   DstRGB32 = 32 bit destination in pixel format 1888x1180
   dstWidthStep = 7552
   dstOffset = {0, 0}
   dstSize = {1888, 1180}
   pSpec = as calculated above,
   buf = allocated by initilize function.




0 Kudos
dolevo_j_
Beginner
867 Views

I got it working. The above code works pretty much ok.

Thanks.

0 Kudos
Reply