Changes an image size using different interpolation algorithm.
Case 1: Operation on pixel-order data
IppStatus ippiResizeSqrPixel_<mod>(const Ipp<datatype>* pSrc, IppiSize srcSize, int srcStep, IppiRect srcRoi, Ipp<datatype>* pDst, int dstStep, IppiRect dstRoi, double xFactor, double yFactor, double xShift, double yShift, int interpolation, Ipp8u* pBuffer);
Supported values for mod:
8u_C1R |
16u_C1R |
16s_C1R |
32f_C1R |
64f_C1R |
8u_C3R |
16u_C3R |
16s_C3R |
32f_C3R |
64f_C3R |
8u_C4R |
16u_C4R |
16s_C4R |
32f_C4R |
64f_C4R |
8u_AC4R |
16u_AC4R |
16s_AC4R |
32f_AC4R |
64f_AC4R |
Case 2: Operation on planar-order data
IppStatus ippiResizeSqrPixel_<mod>(const Ipp<datatype>* const pSrc[3], IppiSize srcSize, int srcStep, IppiRect srcRoi, Ipp<datatype>* const pDst[3], int dstStep, IppiRect dstRoi, double xFactor, double yFactor, double xShift, double yShift, int interpolation, Ipp8u* pBuffer);
Supported values for mod:
8u_P3R |
16u_P3R |
16s_P3R |
32f_P3R |
64f_P3R |
IppStatus ippiResizeSqrPixel_<mod>(const Ipp<datatype>* const pSrc[4], IppiSize srcSize, int srcStep, IppiRect srcRoi, Ipp<datatype>* const pDst[4], int dstStep, IppiRect dstRoi, double xFactor, double yFactor, double xShift, double yShift, int interpolation, Ipp8u* pBuffer);
Supported values for mod:
8u_P4R |
16u_P4R |
16s_P4R |
32f_P4R |
64f_P4R |
pSrc |
Pointer to the source image origin. An array of 3 or 4 pointers to the planes for planar image. |
srcSize |
Size in pixels of the source image. |
srcStep |
Distance in bytes between starts of consecutive lines in the source image buffer. |
srcRoi |
Region of interest in the source image (of the IppiRect type). |
pDst |
Pointer to the destination image. An array of 3 or 4 pointers to the planes for planar image. |
dstStep |
Distance in bytes between starts of consecutive lines in the destination image buffer. |
dstRoi |
Region of interest in the destination image (of the IppiRect type). |
xFactor, yFactor |
Factors by which the x and y dimensions of the source ROI are changed. The factor value greater than 1 means increasing the image size in that dimension. |
xShift, yShift |
Shift values in the x and y directions respectively. |
interpolation |
Specifies the interpolation mode. Possible values are: |
IPPI_INTER_NN - nearest neighbor interpolation |
|
IPPI_INTER_LINEAR - linear interpolation |
|
IPPI_INTER_CUBIC - cubic interpolation |
|
IPPI_INTER_LANCZOS - interpolation with Lanczos window |
|
IPPI_INTER_CUBIC2P_BSPLINE - B-spline |
|
IPPI_INTER_CUBIC2P_CATMULLROM - Catmull-Rom spline |
|
IPPI_INTER_CUBIC2P_B05C03 - special two-parameter cubic filter |
|
IPPI_INTER_SUPER - supersampling interpolation the following flags are used additionally to the above modes: |
|
IPPI_SMOOTH_EDGE, or IPPI_SUBPIXEL_EDGE - edge smoothing |
|
IPPI_ANTIALIASING - antialiasing method, is not applicable with IPPI_INTER_NN or IPPI_INTER_SUPER |
|
pBuffer |
Pointer to the external buffer. |
The function ippiResizeSqrPixel is declared in the ippi.h file. It operates with ROI (see ROI Processing in Geometric Transforms).
This function works with different interpolation modes and can be used for general resize operations in image processing, in different mathematic and geometric tasks.
This function resizes the source image ROI by xFactor in the x direction and yFactor in the y direction. The image size can be either reduced or increased in each direction, depending on the values of xFactor, yFactor. The result is resampled using the interpolation mode specified by the interpolation parameter, and written to the destination image ROI. Interpolation modes with two-parameter cubic filters perform additional filtering to improve quality of the destination image.
Pixel coordinates x' and y' in the resized image are obtained from the following equations:
x' = xFactor * x + xShift
y' = yFactor * y + yShift
where x and y denote the pixel coordinates in the source image.
The interpolation algorithms may skip edge pixels in the source image out of the ROI. The function ippiResizeSqrPixel uses in calculation the weighted values of these outer pixels. If a source edge pixel and outer pixel have intersection a<1 in the corresponding direction, that pixels' value is taken with the weight a. If no edge smoothing flag is set, the function does not process the outer pixels with the weight less than 0.5.
If the flag IPPI_SMOOTH_EDGE is set, then the function processes outer pixels with the weight of original destination background:
DstRes = SrcSampled*(1-a) + DstExist*a;
If the flag IPPI_SUBPIXEL_EDGE is set, then the function proceeds outer pixels without the weight of original destination background:
DstRes = SrcSampled*(1-a);
where SrcSampled - intensity if the source pixel after resizing, DstExist - intensity of the destination pixel before resizing, DstRes - intensity of the result destination pixel, a - weight of the outer pixel; it is set by the function.
The size of the destination image can vary depending on the edge smoothing settings.
The edge smoothing does not work on images with the high contrast borders.
If an image is compressed, use antialiasing method to limit the impact of aliasing (artifacts). In this case the function modifies (stretches out) the interpolation kernel and reduces amplitude; resampling is performed on the x and y directions independently. This method can be performed by setting interpolation to IPPI_ANTIALIASING . The factor values must be less than 1, and interpolation can not be set to IPPI_INTER_NN or IPPI_INTER_SUPER.
Only one of the flags IPPI_SMOOTH_EDGE, IPPI_SUBPIXEL_EDGE, IPPI_ANTIALIASING can be used.
The function requires the external buffer pBuffer, its size must be previously computed by calling the function ippiResizeGetBufSize_64f for 64f flavors, and ippiResizeGetBufSize for all other flavors.
Example “Using the Function ippiResizeSqrPixel” shows how to use the function ippiResizeSqrPixel_32f_C1R.
The source and destination image ROI are specified in independent systems of coordinates. The destination pixels are mapped back to the source image (see figure in ROI Processing in Geometric Transforms) and interpolated if they hit it. The following pseudocode approximately describes the process:
For (j = dstROI.y; j < dstROI.y + dstROI.height; j++) {
For (i = dstROI.x; i < dstROI.x + dstROI.width; i++) {
xCoordSrc = 1 / xFactor * (j + 0.5) - xShift / xFactor;
yCoordSrc = 1 / yFactor * (i + 0.5) - yShift / yFactor;
if (pixel (xCoordSrc, xCoordSrc) is in source image) {
interpolate;
}
}
}
ippStsNoErr |
Indicates no error. Any other value indicates an error or a warning. |
ippStsNullPtrErr |
Indicates an error condition if one of the specified pointers is NULL. |
ippStsSizeErr |
Indicates an error condition if width or height of images or source image ROI has zero or negative value, of if one of the specified coordinates of the image ROI origin is negative. |
ippStsResizeFactorErr |
Indicates an error condition if xFactor or yFactor is less than or equal to zero. |
ippStsInterpolationErr |
Indicates an error condition if interpolation has an illegal value. |
ippStsWrongIntersectROI |
Indicates a warning if srcRoi has no intersection with the source image. |
ippStsNoAntialiasing |
Indicates a warning if the selected interpolation mode does not support antialiasing. |
The following example shows how the Intel IPP functions can be used to resample the source image of size 12x12 to the destination image of size 6x6 .
Please note that this code is developed for demonstration purposes only.
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;
/* 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
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
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
Copyright © 2000 - 2011, Intel Corporation. All rights reserved.