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

Pan/Zoom image using ResizeLanczos

umundry
Beginner
652 Views

I am having trouble with ref function/ functionality - code below. When I increase dZoom beyond some value it crashes. It also misaligns the rows of the output image (I uploaded an image showing this). Input/Output is grayscale (8u). I likely have an incorrect understanding of sizeSrc, sizeDst and zoomImgSize. Can someone please check what is going on?

Thank you!

bool PanZoomImg(byte* pImgSrc, byte* pImgDst, int nSrcX, int nSrcY, int nDstX, int bDstY, double dZoom, double dPanX, double dPanY)
{
 IppStatus ippStatus = ippStsNoErr;
 IppiSize zoomImgSize = { static_cast<int>(nSrcX*dZoom), static_cast<int>(nSrcY*dZoom) };
 uint32_t nrLobes = 2;
 IppiResizeSpec_32f* pSpec = 0;
 int specSize = 0;
 int initSize = 0;
 int bufSize = 0;
 Ipp8u* pInitBuf = 0;
 Ipp8u* pBuffer = 0;
 IppiBorderSize *pBordersize = new IppiBorderSize();
 pBordersize->borderBottom = pBordersize->borderLeft = pBordersize->borderRight = pBordersize->borderTop = 0;
 IppiPoint dstOffset = { (int)dPanX, (int)dPanY };
 IppiBorderType borderType = ippBorderRepl;
 Ipp8u borderValue = 0;
 IppiInterpolationType interpolType = ippLanczos;
 Ipp32u antialiasing = 1;
 Ipp32u numChannels = 1;

 IppiSize *sizeSrc = new IppiSize();
 sizeSrc->width = nSrcX;
 sizeSrc->height = nSrcY;

 IppiSize *sizeDst = new IppiSize();
 sizeDst->width = nDstX;
 sizeDst->height = bDstY;

 ippStatus = ippiResizeGetSize_8u(*sizeSrc, *sizeDst, interpolType, antialiasing, &specSize, &initSize);
 if (ippStatus > ippStsNoErr) return ippStatus;
 pSpec = (IppiResizeSpec_32f*)ippsMalloc_8u(specSize);
 if (pSpec == 0) throw 0;
 pInitBuf = ippsMalloc_8u(initSize);
 if (pInitBuf == 0) { ippsFree(pSpec); throw 0; }
 ippStatus = ippiResizeLanczosInit_8u(*sizeSrc, zoomImgSize, nrLobes, pSpec, pInitBuf);
 if (ippStatus > ippStsNoErr) { ippsFree(pInitBuf); ippsFree(pSpec); throw 0; }

 ippStatus = ippiResizeGetBufferSize_8u(pSpec, *sizeDst, numChannels, &bufSize);
 if ((ippStatus > ippStsNoErr) && (ippStatus != ippStsSizeWrn)) { ippsFree(pInitBuf); ippsFree(pSpec); throw 0; }
 pBuffer = ippsMalloc_8u(bufSize);
 if (pBuffer == 0) { ippsFree(pInitBuf); ippsFree(pSpec); throw 0; }

 ippStatus = ippiResizeGetBorderSize_8u(pSpec, pBordersize);
 if (ippStatus > ippStsNoErr) { ippsFree(pBuffer); ippsFree(pInitBuf); ippsFree(pSpec); throw 0; }

 ippStatus = ippiResizeLanczos_8u_C1R(pImgSrc, zoomImgSize.width, pImgDst, nDstX, dstOffset, *sizeDst, borderType, &borderValue, pSpec, pBuffer);
 if ((ippStatus > ippStsNoErr) && (ippStatus != ippStsSizeWrn)) { ippsFree(pBuffer); ippsFree(pInitBuf); ippsFree(pSpec); throw 0; }

 ippsFree(pBuffer);
 ippsFree(pInitBuf);
 ippsFree(pSpec);

 return true;
}

 

0 Kudos
4 Replies
Zhen_Z_Intel
Employee
652 Views

Hi,

Here's a problem in your source code, in "ippiResizeLanczosInit_8u" you set size of 'zoomImgSize' as dstImg size. However, in "ippiResizeLanczos_8u_C1R", you set 'zoomImgSize.width' as srcStep. You may lead to problem. 

Best regards,
Fiona

0 Kudos
umundry
Beginner
652 Views

Thank you Fiona! I fixed that in the new line

ippStatus = ippiResizeLanczos_8u_C1R(pImgSrc, nSrcX, pImgDst, nDstX, dstOffset, *sizeDst, borderType, &borderValue, pSpec, pBuffer);

With that of course the row misalignment is gone. A few problems remain though:

* I get a ippStsSizeWrn error in the ippiResizeGetBufferSize_8u() as well as the ippiResizeLanczos_8u_C1R() calls. The latter crashes for certain zoom/pan values.

* The zoom originates in the upper left corner of the image. I need it to originate in the center of the image.

How do I fix those problems?

Thank you!

0 Kudos
Zhen_Z_Intel
Employee
652 Views

Hi,

Please check following points:

1. You specify with antialising in ''ippiResizeGetSize_8u" function, however you did not use initial fucntion "ippiResizeLanczosInit" and computing function "ippiResizeAntialiasing". 

2. You specify size of Dst image as 'zoomImgSize' in "ippiResizeLanczosInit_8u" fucntion. Please make sure if the zoomImgSize is same as sizeDst. You only need one parameter for describing size of Dst Img.

Please follow this sample to see how to use IPP resize with antialiasing:

https://software.intel.com/en-us/ipp-dev-reference-ResizeAntialiasing.html

Best regards,
Fiona

0 Kudos
umundry
Beginner
652 Views

Thank you Fiona!

The antialiasing part I am not sure about if I need that at all. I'll only be able to tell once I can look at output images.

I think the basic problem is that I am not sure which sizes to use in which of the function calls. In my view, there are 3 sizes to deal with:

* the source image size

* a "zoom" image size

* a viewport size

As an example, the source is 1,000 x 1,000 pixels. Zoom factor is 3, therefore the "zoom" image size is 3,000 x 3,000. A viewport of size 600 x 300 will need to display a 600 x 300 region of interest from the 3,000 x 3,000 "zoom" image, taking into account panX and panY.

Can you please look at the code in light of above example and see what is wrong?

Thank you!!

0 Kudos
Reply