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

IPP and image scaling/ippiResize distortion issue

yunlint
Beginner
501 Views

I am trying to use ippiResize to scale images in a project of my company.

The input image is color bitmap. Its width and height are NOT 8-pixel aligned. The specified output image format is JPEG and color space is YUV_422. I observed that after image scaling, the output image is distorted and the color is black and white.

Is it required that the input image should be 8-pixle aligned?

Thanks !

0 Kudos
5 Replies
Vladimir_Dudnik
Employee
501 Views

Hello,

You are not required to align images neither for ippiResize call nor for JPEG codec call (if you use IPP JPEG codec).

Could you please attach piece of code to see in what way you are using IPP functions. It might be something wrong with parameters you use for IPP functions.

Regards,
Vladimir

0 Kudos
ilanASI
Beginner
501 Views

Hi,

I have a similar problem while using ippiResize_8u_C3R (IPPI_INTER_CUBIC) on a simple CBitmap image.

I found the distortion happens when the zoom factor is a fraction like 1.3333 etc. and func works fine when using 0.5 factor.

I may be using the func incorrectly since it's my first time.

0 Kudos
ilanASI
Beginner
501 Views

OK, my problem was solved by copying the CBitmap::m_bm.bmBits to an Intel Ipp8u image, and then copy the resized image to a pre-allocated CBitmap (double-copy).

I just wonder why working directly on a CBitmap using ippiResize worked nicely in some of the zoom factors but not others.

If anyone knows how to work directly on a CBitmap image using the resize func, your help will be most upreciated.

0 Kudos
Vladimir_Dudnik
Employee
501 Views
Remember, you have to specify lineStep (image pitch) parameter for IPP 2D functions. Did you specify correct value for CBitmap case?
If you can provide simple piece of code which reproduce the issue you mention we can investigate that
Regards,
Vladimir

0 Kudos
ilanASI
Beginner
501 Views

Thanks Vladimir,

I finally solved the problem (brutally) by copying of the CBitmap image to a previously allocated Ipp8u image, perform the zooming (using ippiResize_8u_C3R), and copy back to a new CBitmap image.

This means there's some unseen pixels at the end of each row of the CBitmap image.

I wanted to do the whole operation on a source CBitmap image and destination CBitmap image. It works in some zoom factors (like 2,3,4) but not others. Is this possible?

See the final (working) code below, and note that this function belongs to a class that inherit from CBitmap (i.e. Width() func return the width of the bitmap image) and the destination image is spDstRgbDib:

In header: class CRgbDib : public CBitmap

In CPP:

bool CRgbDib::DoInterpolationZoom(SPRgbDib spDstRgbDib) const
{
// calc zoom factor
double fZoom = max((double)spDstRgbDib->Width() / (double)Width(),
(double)spDstRgbDib->Height() / (double)Height());
// prepare for ippiResize
IppiRect rectSrcROI, rectDstROI;
IppiSize sizeSrcImg, sizeDstImg;
rectSrcROI.x = 0;
rectSrcROI.y = 0;
rectSrcROI.width = Width();
rectSrcROI.height = Height();
rectDstROI.x = 0;
rectDstROI.y = 0;
rectDstROI.width = spDstRgbDib->Width();
rectDstROI.height = spDstRgbDib->Height();
sizeSrcImg.width = Width();
sizeSrcImg.height = Height();
sizeDstImg.width = spDstRgbDib->Width();
sizeDstImg.height = spDstRgbDib->Height();

// copy source image to Intel image
int iStepBytesSrc, iStepBytesDst;
Ipp8u* pSrcIntel = ippiMalloc_8u_C3(sizeSrcImg.width, sizeSrcImg.height, &iStepBytesSrc);
Ipp8u* pDstIntel = ippiMalloc_8u_C3(sizeDstImg.width, sizeDstImg.height, &iStepBytesDst);
Ipp8u* pSrcImg = (Ipp8u*)m_bm.bmBits;
Ipp8u* pSrcCpy = pSrcIntel;
for (int i = 0; i < sizeSrcImg.height; i ++)
{
memcpy(pSrcCpy, pSrcImg, 3 * sizeSrcImg.width);
pSrcImg += m_bm.bmWidthBytes;
pSrcCpy += iStepBytesSrc;
}

// do interpolated zoom
ippiResize_8u_C3R(pSrcIntel, sizeSrcImg, iStepBytesSrc, rectSrcROI, pDstIntel,
iStepBytesDst, sizeDstImg, fZoom, fZoom, IPPI_INTER_LINEAR);

// copy Intel image to dest image
Ipp8u* pDstImg = (Ipp8u*)spDstRgbDib->m_bm.bmBits;
Ipp8u* pDstCpy = pDstIntel;
int bmWidthBytesDst = spDstRgbDib->m_bm.bmWidthBytes;
for (int i = 0; i < sizeDstImg.height; i ++)
{
memcpy(pDstImg, pDstCpy, 3 * sizeDstImg.width);
pDstImg += bmWidthBytesDst;
pDstCpy += iStepBytesDst;
}

// destroy images
ippiFree(pDstIntel);
ippiFree(pSrcIntel);
return true;
}

0 Kudos
Reply