Image scaling based on YUV422 (bilinear interpolation)

Source: Internet
Author: User
Tags prev

The usual camera read data are YUV422 format, if you want to support digital zoom, we need to zoom to him, of course, the specific point should be amplification operation, because we are the captured image of the local amplification, called digital zoom.

A number of different methods were tried during the test, including Gdiplus, OPENCV, Ippi, and the YUV422-based interpolation operations you wrote.

Here is a brief introduction to scaling operations based on Gdiplus, OpenCV, and Ippi. Gdiplus and OPENCV can only operate on YUV444, so we need to convert YUV422 to YUV444, with yuv422,yuv444 easy to get and fast. With Gdiplus, OpenCV scales the YUV444, and then converts the scaled YUV444 to YUV422 to complete the zoom process. The Ippi provides a scaling function on the YUV422, which can be scaled directly.

The specific scaling is as follows:

Gdiplus:

int ZoomIn (byte* poridata, int width, int height, CRect rect)//yuv444 {bitmapinfoheader bmih; memset (&BMIH, 0, sizeof (Bitmapinfoheader)); bmih.bisize = sizeof (Bitmapinfoheader); Bmih.biwidth = width; Bmih.biheight = height; Bmih.biplanes = 1; Bmih.bibitcount = 24; Bmih.bisizeimage = WIDTH*HEIGHT*BMIH.BIBITCOUNT/8; bitmap* Pbitmap = Bitmap::frombitmapinfo ((bitmapinfo*) &bmih, poridata); bitmap* ptemp = Pbitmap->clone (Rect.left, Height-rect.bottom, rect. Width (), Rect. Height (), Pbitmap->getpixelformat ()); Graphics gph (PBITMAP); Gph. DrawImage (ptemp, 0, 0, width, height); Delete ptemp; Delete Pbitmap; return 0; }

OPENCV:

yuv4222yuv444 (pYUV422, pYUV444, iwidth, iheight); if (!pzoomsrciplimg) {pzoomsrciplimg = Cvcreateimage (Cvsize (iwidth, iheight), ipl_depth_8u, 3);} if (pzoomsrciplimg) {m emcpy (Pzoomsrciplimg->imagedata, pYUV444, g_iwidth*g_iheight*3); Cvsetimageroi (Pzoomsrciplimg, Cvrect (Drawrect.left, Drawrect.top, DrawRect. Width (), DrawRect. Height ())); } if (!pzoomdstiplimg) {pzoomdstiplimg = Cvcreateimage (Cvsize (iwidth, iheight), ipl_depth_8u, 3);} cvresize (PZOOMSRCIPL IMG, pzoomdstiplimg, cv_inter_linear); memcpy (pYUV444, Pzoomdstiplimg->imagedata, iwidth*iheight*3); yuv4442yuv422 (pYUV444, pYUV422, iwidth, iheight); Cvresetimageroi (PZOOMSRCIPLIMG);

Ippi:

Ippisize srcsize; Srcsize.width = iwidth; Srcsize.height = iheight; Ippirect Srcroi; srcroi.x = (drawrect.left>>2) <<1; SRCROI.Y = Drawrect.top; Srcroi.width = (drawrect. Width () >>1) <<1; Srcroi.height = (drawrect. Height () >>1) <<1; Ippisize dstsize; Dstsize.width = iwidth; Dstsize.height = iheight; Double xfactor = double (dstsize.width)/srcroi.width; Double yfactor = double (dstsize.height)/srcroi.height; IPPIRESIZEYUV422_8U_C2R (PYUV422SRC, Srcsize, g_iwidth*2, Srcroi, PYUV422DST, iwidth*2, Dstsize, XFactor, YFactor, IPPI_ Inter_linear); memcpy (G_PYUV422SRC, G_PYUV422DST, g_iwidth*g_iheight*2);

In the above method, DrawRect is the desired zoom area, iwidth, Iheight is the scaled width (assuming the same as the overall width of the original image, the portion of the image will be scaled to all)

Using bilinear interpolation, I wrote a scaling code based on YUV422, considering the problem of computational quantity, the efficiency cannot be compared with the above several. (need to be optimized)

The above algorithm, Gdiplus and OpenCV speed similar, Ippi speed is significantly faster than Gdiplus and OpenCV. Ippi and OpenCV are all software packages provided by Intel.

I write YUV422-based scaling:

int Yuvzoomin (void* pyuv, int width, int height, CRect rect) {if (rect). Width ()%2!=0) {rect.left++;} if (rect.left%2!=0) {rect.left++; rect.right++;} byte* pzoomindata = new Byte[width*height*2]; memset (pzoomindata, 0, width*height*2); Double scale = ((double) (rect.right-rect.left))/width; byte* PORIYUV = (byte*) pyuv; byte* PZOONINYUV = (byte*) pzoomindata; Double Indexi, Indexj, u, v; int Roundi, ROUNDJ; int left, right, Rectwidth, Preu, PreV; left= (rect.left>>1) <<1; right= (rect.right>>1) <<1; Rectwidth=right-left; for (int i=0, i

Test can be used, the speed there are some problems, there are improved ideas can directly contact me, haha

Mosesyuan at gmail dot com

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.