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

Understanding linear interpolation of ippiresizesqrpixel

Rosenstiel__Marcus
166 Views
Hi,

I have a problem understanding the grid positions in ippiresizesqr. The documentation describes the new grid positions as x' = xFactor * x + xShift. With xShift = 0 the upper left pixel should be always equal to the upper left pixel in the destination image. Subsequent pixels should be a linear interpolation between the first and the second pixel of the source image. In my test sample the border pixels are repeated mutiple times.

Example:
int scale = 6;
int in = 3;
int out = in*scale;
IppiRect inR = {0, 0, in, 1};
IppiRect outR = {0, 0, out, 1};
IppiSize inS = {in, 1};
IppiSize outS = {out, 1};

int stepIn = 0;
Ipp32f* pIn = ippiMalloc_32f_C1(in, 1, &stepIn);
int stepOut = 0;
Ipp32f* pOut = ippiMalloc_32f_C1(out, 1, &stepOut);

// Set data 1.0 2.0 3.0
*pIn = 1.0; *(pIn+1) = 2.0; *(pIn+2) = 3.0;

Ipp8u* buf = 0;
int bufsize = 0;
ippiResizeGetBufSize( inR, outR, 1, IPPI_INTER_LINEAR, &bufsize);
buf = ippsMalloc_8u(bufsize);
double fac = static_cast(out) / static_cast(in);

IppStatus status = ippiResizeSqrPixel_32f_C1R(
pIn, inS , stepIn, inR,
pOut, stepOut, outR, fac, 1, 0, 0, IPPI_INTER_LINEAR, buf);

The input image has three pixels with the values 1.0, 2.0 and 3.0. Upscaling by the factor 6 gives the image
1.0, 1.0, 1.0, 1.083, 1.25, 1.416, 1.583, 1.75, 1.916, 2.083, 2.25, 2.416, 2.583, 2.75, 2.916, 3.0, 3.0, 3.0

IppiResizeSqr produces the same results for 2D data. I have no idea why the border pixels are repeated several times.

Best regards,

Marcus
0 Kudos
1 Reply
Ying_H_Intel
Employee
166 Views
Hi Marcus,

The result is expected. Please see the experts comment:

>>>
its right and expected result.The image 3x1 is not enough pixels for the interpolation, so the pixels are replicated.

For horizontal interpolation we need source pixels [-1], [-1], [-1], [0], [0], [0] , [0], [0], [0] , [1], [1], [1] , [1], [1], [1] , [2], [2], [2]

For example

(int)floor((0+0.5)/scaleX-0.5) = (int)floor(-0.41666666) = -1

(int)floor((1+0.5)/scaleX-0.5) = (int)floor(-0.25) = -1

(int)floor((2+0.5)/scaleX-0.5) = (int)floor(-0.08333333) = -1

(int)floor((3+0.5)/scaleX-0.5) = (int)floor( 0.08333333) = 0

.......

dst[0] = (src[0] src[0]) * 0.58333331 + src[0] = src[0];

dst[1] = (src[0] src[0]) * 0.75 + src[0] = src[0];

dst[2] = (src[0] src[0]) * 0.91666669 + src[0] = src[0];

dst[3] = (src[1] src[0]) * 0.083333336 + src[0] = 1.0833334;

.......

dst[14] = (src[2] src[1]) * 0.91666669 + src[1] = 2.9166667;

dst[15] = (src[in-1] src[in-1]) * 0.083333336 + src[in-1] = src[in-1];

dst[16] = (src[in-1] src[in-1]) * 0.25 + src[in-1] = src[in-1];

dst[17] = (src[in-1] src[in-1]) * 0.41666666 + src[in-1] = src[in-1];


Regards,
Ying H.

0 Kudos
Reply