YUY2(YUV) 与 RGB 格式图片的相互转换
[版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/jtujtujtu/article/details/3874621]
YUY2经常用于电视制式以及许多摄像头的输出格式.而我们在处理时经常需要将其转化为RGB进行处理,这里简单介绍下YUY2(YUV)与RGB之间相互转化的关系:
http://msdn2.microsoft.com/en-us/lib
YUY2(YUV) To RGB:
C = Y - 16
D = U - 128
E = V - 128
R = clip(( 298 * C + 409 * E + 128) >> 8)
G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8)
B = clip(( 298 * C + 516 * D + 128) >> 8)
其中 clip()为限制函数,将其取值限制在0-255之间.
RGB To YUY2(YUV):
Y = ( ( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16
U = ( ( -38 * R - 74 * G + 112 * B + 128) >> 8) + 128
V = ( ( 112 * R - 94 * G - 18 * B + 128) >> 8) + 128
上述两个公式在代码中的:
int YUV2RGB(void* pYUV, void* pRGB, int width, int height, bool alphaYUV, bool alphaRGB);
int RGB2YUV(void* pRGB, void* pYUVX, int width, int height, bool alphaYUV, bool alphaRGB);
函数中转换。
在诸如摄像头的数据获取中,我们往往需要直接在YUY2(YUV)空间上进行一些图象处理,我们希望能够在YUY2
(YUV)进行一些RGB上可以做到的处理。这里已blending为例,将两张带有透明度的YUY2(YUV)图片进行叠加,
以达到在RGB空间进行图像合成的效果。
RGB空间进行图像叠加,通常背景(BG)是不透明的,而前景(FG)是带有透明度的。在RGB空间,可以简单表示为:
Rdest = Rfg*alpha + Rbg*(1-alpha);
Gdest = Gfg*alpha + Gbg*(1-alpha);
Bdest = Bfg*alpha + Bbg*(1-alpha);
Rdest、Gdest、Bdest 为最终合成后的像素值
考虑到
Y = ( ( 66 * R + 129 * G + 25 * B + 128) >> 8) + 16
U = ( ( -38 * R - 74 * G + 112 * B + 128) >> 8) + 128
V = ( ( 112 * R - 94 * G - 18 * B + 128) >> 8) + 128
我们可以推导出
(Ydest-16)<<8 = ((Yfg-16)<<8)*alpha + ((Ybg-16)<<8)*(1-alpha);
(Udest-128)<<8 = ((Ufg-128)<<8)*alpha + ((Ubg-128)<<8)*(1-alpha);
(Vdest-128)<<8 = ((Vfg-128)<<8)*alpha + ((Vbg-128)<<8)*(1-alpha);
从而可以得到
Ydest = (Yfg-16)*alpha + (Ybg-16)*(1-alpha) + 16;
Udest = (Ufg-128)*alpha + (Ubg-128)*(1-alpha) + 128;
Vdest = (Vfg-128)*alpha + (Vbg-128)*(1-alpha) + 128;
这个叠加过程在函数
int YUVBlending(void* pBGYUV, void* pFGYUV, int width, int height, bool alphaBG, bool alphaFG)
中实现。
由于本文针对摄像头采集所得的数据进行处理,因此数据为YUY2格式,即4个字节来表示两个像素点的YUV信息,
排列为Y1 U1 Y2 V2, 对于像素点1为(Y1, U1, V1),像素点2为(Y2, U1, V1)。即两个像素点共用U、V信息。
这里假设带有alpha透明度的YUV格式用6个字节来表示两个像素点的YUV以及alpha信息,排列为 Y1 U1 Y2 V1 alpha1 alpha2
其中像素点1为(Y1, U1, V1, alpha1),像素点2为(Y2, U1, V1, alpha2)。其中alpha为对应点的透明度信息。
而带有alpha透明度RGB格式的图片,假设为32bits的BMP图片,每个像素点用4bytes来表示,分别为B G R alpha信息。
上述函数的具体实现为:
//
// YUV2RGB
// pYUV point to the YUV data
// pRGB point to the RGB data
// width width of the picture
// height height of the picture
// alphaYUV is there an alpha channel in YUV
// alphaRGB is there an alpha channel in RGB
//
int YUV2RGB(void* pYUV, void* pRGB, int width, int height, bool alphaYUV, bool alphaRGB) {if (NULL == pYUV) {return -1;}unsigned char* pYUVData = (unsigned char *)pYUV;unsigned char* pRGBData = (unsigned char *)pRGB;if (NULL == pRGBData) {if (alphaRGB) {pRGBData = new unsigned char[width*height*4];}elsepRGBData = new unsigned char[width*height*3];}int Y1, U1, V1, Y2, alpha1, alpha2, R1, G1, B1, R2, G2, B2;int C1, D1, E1, C2;if (alphaRGB){if (alphaYUV){for (int i=0; i<height; ++i){for (int j=0; j<width/2; ++j){Y1 = *(pYUVData+i*width*3+j*6);U1 = *(pYUVData+i*width*3+j*6+1);Y2 = *(pYUVData+i*width*3+j*6+2);V1 = *(pYUVData+i*width*3+j*6+3);alpha1 = *(pYUVData+i*width*3+j*6+4);alpha2 = *(pYUVData+i*width*3+j*6+5);C1 = Y1-16;C2 = Y2-16;D1 = U1-128;E1 = V1-128;R1 = ((298*C1 + 409*E1 + 128)>>8>255 ? 255 : (298*C1 + 409*E1 + 128)>>8);G1 = ((298*C1 - 100*D1 - 208*E1 + 128)>>8>255 ? 255 : (298*C1 - 100*D1 - 208*E1 + 128)>>8); B1 = ((298*C1+516*D1 +128)>>8>255 ? 255 : (298*C1+516*D1 +128)>>8); R2 = ((298*C2 + 409*E1 + 128)>>8>255 ? 255 : (298*C2 + 409*E1 + 128)>>8);G2 = ((298*C2 - 100*D1 - 208*E1 + 128)>>8>255 ? 255 : (298*C2 - 100*D1 - 208*E1 + 128)>>8);B2 = ((298*C2 + 516*D1 +128)>>8>255 ? 255 : (298*C2 + 516*D1 +128)>>8); *(pRGBData+(height-i-1)*width*4+j*8+2) = R1<0 ? 0 : R1;*(pRGBData+(height-i-1)*width*4+j*8+1) = G1<0 ? 0 : G1;*(pRGBData+(height-i-1)*width*4+j*8) = B1<0 ? 0 : B1;*(pRGBData+(height-i-1)*width*4+j*8+3) = alpha1; *(pRGBData+(height-i-1)*width*4+j*8+6) = R2<0 ? 0 : R2;*(pRGBData+(height-i-1)*width*4+j*8+5) = G2<0 ? 0 : G2;*(pRGBData+(height-i-1)*width*4+j*8+4) = B2<0 ? 0 : B2;*(pRGBData+(height-i-1)*width*4+j*8+7) = alpha2; }} }else{int alpha = 255;for (int i=0; i<height; ++i){for (int j=0; j<width/2; ++j){Y1 = *(pYUVData+i*width*2+j*4);U1 = *(pYUVData+i*width*2+j*4+1);Y2 = *(pYUVData+i*width*2+j*4+2);V1 = *(pYUVData+i*width*2+j*4+3);C1 = Y1-16;C2 = Y2-16;D1 = U1-128;E1 = V1-128;R1 = ((298*C1 + 409*E1 + 128)>>8>255 ? 255 : (298*C1 + 409*E1 + 128)>>8);G1 = ((298*C1 - 100*D1 - 208*E1 + 128)>>8>255 ? 255 : (298*C1 - 100*D1 - 208*E1 + 128)>>8); B1 = ((298*C1+516*D1 +128)>>8>255 ? 255 : (298*C1+516*D1 +128)>>8); R2 = ((298*C2 + 409*E1 + 128)>>8>255 ? 255 : (298*C2 + 409*E1 + 128)>>8);G2 = ((298*C2 - 100*D1 - 208*E1 + 128)>>8>255 ? 255 : (298*C2 - 100*D1 - 208*E1 + 128)>>8);B2 = ((298*C2 + 516*D1 +128)>>8>255 ? 255 : (298*C2 + 516*D1 +128)>>8); *(pRGBData+(height-i-1)*width*4+j*8+2) = R1<0 ? 0 : R1;*(pRGBData+(height-i-1)*width*4+j*8+1) = G1<0 ? 0 : G1;*(pRGBData+(height-i-1)*width*4+j*8) = B1<0 ? 0 : B1;*(pRGBData+(height-i-1)*width*4+j*8+3) = alpha; *(pRGBData+(height-i-1)*width*4+j*8+6) = R2<0 ? 0 : R2;*(pRGBData+(height-i-1)*width*4+j*8+5) = G2<0 ? 0 : G2;*(pRGBData+(height-i-1)*width*4+j*8+4) = B2<0 ? 0 : B2;*(pRGBData+(height-i-1)*width*4+j*8+7) = alpha; }} }}else{if (alphaYUV){for (int i=0; i<height; ++i){for (int j=0; j<width/2; ++j){Y1 = *(pYUVData+i*width*3+j*4);U1 = *(pYUVData+i*width*3+j*4+1);Y2 = *(pYUVData+i*width*3+j*4+2);V1 = *(pYUVData+i*width*3+j*4+3);C1 = Y1-16;C2 = Y2-16;D1 = U1-128;E1 = V1-128;R1 = ((298*C1 + 409*E1 + 128)>>8>255 ? 255 : (298*C1 + 409*E1 + 128)>>8);G1 = ((298*C1 - 100*D1 - 208*E1 + 128)>>8>255 ? 255 : (298*C1 - 100*D1 - 208*E1 + 128)>>8); B1 = ((298*C1+516*D1 +128)>>8>255 ? 255 : (298*C1+516*D1 +128)>>8); R2 = ((298*C2 + 409*E1 + 128)>>8>255 ? 255 : (298*C2 + 409*E1 + 128)>>8);G2 = ((298*C2 - 100*D1 - 208*E1 + 128)>>8>255 ? 255 : (298*C2 - 100*D1 - 208*E1 + 128)>>8);B2 = ((298*C2 + 516*D1 +128)>>8>255 ? 255 : (298*C2 + 516*D1 +128)>>8); *(pRGBData+(height-i-1)*width*3+j*6+2) = R1<0 ? 0 : R1;*(pRGBData+(height-i-1)*width*3+j*6+1) = G1<0 ? 0 : G1;*(pRGBData+(height-i-1)*width*3+j*6) = B1<0 ? 0 : B1;*(pRGBData+(height-i-1)*width*3+j*6+5) = R2<0 ? 0 : R2;*(pRGBData+(height-i-1)*width*3+j*6+4) = G2<0 ? 0 : G2;*(pRGBData+(height-i-1)*width*3+j*6+3) = B2<0 ? 0 : B2;}}}else{for (int i=0; i<height; ++i){for (int j=0; j<width/2; ++j){Y1 = *(pYUVData+i*width*2+j*4);U1 = *(pYUVData+i*width*2+j*4+1);Y2 = *(pYUVData+i*width*2+j*4+2);V1 = *(pYUVData+i*width*2+j*4+3);C1 = Y1-16;C2 = Y2-16;D1 = U1-128;E1 = V1-128;R1 = ((298*C1 + 409*E1 + 128)>>8>255 ? 255 : (298*C1 + 409*E1 + 128)>>8);G1 = ((298*C1 - 100*D1 - 208*E1 + 128)>>8>255 ? 255 : (298*C1 - 100*D1 - 208*E1 + 128)>>8); B1 = ((298*C1+516*D1 +128)>>8>255 ? 255 : (298*C1+516*D1 +128)>>8); R2 = ((298*C2 + 409*E1 + 128)>>8>255 ? 255 : (298*C2 + 409*E1 + 128)>>8);G2 = ((298*C2 - 100*D1 - 208*E1 + 128)>>8>255 ? 255 : (298*C2 - 100*D1 - 208*E1 + 128)>>8);B2 = ((298*C2 + 516*D1 +128)>>8>255 ? 255 : (298*C2 + 516*D1 +128)>>8); *(pRGBData+(height-i-1)*width*3+j*6+2) = R1<0 ? 0 : R1;*(pRGBData+(height-i-1)*width*3+j*6+1) = G1<0 ? 0 : G1;*(pRGBData+(height-i-1)*width*3+j*6) = B1<0 ? 0 : B1;*(pRGBData+(height-i-1)*width*3+j*6+5) = R2<0 ? 0 : R2;*(pRGBData+(height-i-1)*width*3+j*6+4) = G2<0 ? 0 : G2;*(pRGBData+(height-i-1)*width*3+j*6+3) = B2<0 ? 0 : B2;}} }}return 0;
}//
// RGB2YUV
// pRGB point to the RGB data
// pYUV point to the YUV data
// width width of the picture
// height height of the picture
// alphaYUV is there an alpha channel in YUV
// alphaRGB is there an alpha channel in RGB
//
int RGB2YUV(void* pRGB, void* pYUV, int width, int height, bool alphaYUV, bool alphaRGB)
{if (NULL == pRGB){return -1;}unsigned char* pRGBData = (unsigned char *)pRGB;unsigned char* pYUVData = (unsigned char *)pYUV;if (NULL == pYUVData){if (alphaYUV){pYUVData = new unsigned char[width*height*3];}elsepYUVData = new unsigned char[width*height*2];}int R1, G1, B1, R2, G2, B2, Y1, U1, Y2, V1;int alpha1, alpha2;if (alphaYUV){if (alphaRGB){for (int i=0; i<height; ++i){for (int j=0; j<width/2; ++j){B1 = *(pRGBData+(height-i-1)*width*4+j*8);G1 = *(pRGBData+(height-i-1)*width*4+j*8+1);R1 = *(pRGBData+(height-i-1)*width*4+j*8+2);alpha1 = *(pRGBData+(height-i-1)*width*4+j*8+3);B2 = *(pRGBData+(height-i-1)*width*4+j*8+4);G2 = *(pRGBData+(height-i-1)*width*4+j*8+5);R2 = *(pRGBData+(height-i-1)*width*4+j*8+6);alpha2 = *(pRGBData+(height-i-1)*width*4+j*8+7);Y1 = (((66*R1+129*G1+25*B1+128)>>8) + 16) > 255 ? 255 : (((66*R1+129*G1+25*B1+128)>>8) + 16);U1 = ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128)>255 ? 255 : ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128);Y2 = (((66*R2+129*G2+25*B2+128)>>8) + 16)>255 ? 255 : ((66*R2+129*G2+25*B2+128)>>8) + 16;V1 = ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128)>255 ? 255 : ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128);*(pYUVData+i*width*3+j*6) = Y1;*(pYUVData+i*width*3+j*6+1) = U1;*(pYUVData+i*width*3+j*6+2) = Y2;*(pYUVData+i*width*3+j*6+3) = V1;*(pYUVData+i*width*3+j*6+4) = alpha1;*(pYUVData+i*width*3+j*6+5) = alpha2;}} }else{unsigned char alpha = 255;for (int i=0; i<height; ++i){for (int j=0; j<width/2; ++j){B1 = *(pRGBData+(height-i-1)*width*3+j*6);G1 = *(pRGBData+(height-i-1)*width*3+j*6+1);R1 = *(pRGBData+(height-i-1)*width*3+j*6+2);B2 = *(pRGBData+(height-i-1)*width*3+j*6+3);G2 = *(pRGBData+(height-i-1)*width*3+j*6+4);R2 = *(pRGBData+(height-i-1)*width*3+j*6+5);Y1 = ((66*R1+129*G1+25*B1+128)>>8) + 16;U1 = ((-38*R1-74*G1+112*B1+128)>>8+(-38*R2-74*G2+112*B2+128)>>8)/2 + 128;Y2 = ((66*R2+129*G2+25*B2+128)>>8) + 16;V1 = ((112*R1-94*G1-18*B1+128)>>8 + (112*R2-94*G2-18*B2+128)>>8)/2 + 128;Y1 = (((66*R1+129*G1+25*B1+128)>>8) + 16) > 255 ? 255 : (((66*R1+129*G1+25*B1+128)>>8) + 16);U1 = ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128)>255 ? 255 : ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128);Y2 = (((66*R2+129*G2+25*B2+128)>>8) + 16)>255 ? 255 : ((66*R2+129*G2+25*B2+128)>>8) + 16;V1 = ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128)>255 ? 255 : ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128);*(pYUVData+i*width*3+j*6) = Y1;*(pYUVData+i*width*3+j*6+1) = U1;*(pYUVData+i*width*3+j*6+2) = Y2;*(pYUVData+i*width*3+j*6+3) = V1;*(pYUVData+i*width*3+j*6+4) = alpha;*(pYUVData+i*width*3+j*6+5) = alpha;}} }}else{if (alphaRGB){for (int i=0; i<height; ++i){for (int j=0; j<width/2; ++j){B1 = *(pRGBData+(height-i-1)*width*4+j*8);G1 = *(pRGBData+(height-i-1)*width*4+j*8+1);R1 = *(pRGBData+(height-i-1)*width*4+j*8+2);B2 = *(pRGBData+(height-i-1)*width*4+j*8+4);G2 = *(pRGBData+(height-i-1)*width*4+j*8+5);R2 = *(pRGBData+(height-i-1)*width*4+j*8+6);Y1 = (((66*R1+129*G1+25*B1+128)>>8) + 16) > 255 ? 255 : (((66*R1+129*G1+25*B1+128)>>8) + 16);U1 = ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128)>255 ? 255 : ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128);Y2 = (((66*R2+129*G2+25*B2+128)>>8) + 16)>255 ? 255 : ((66*R2+129*G2+25*B2+128)>>8) + 16;V1 = ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128)>255 ? 255 : ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128);*(pYUVData+i*width*2+j*4) = Y1;*(pYUVData+i*width*2+j*4+1) = U1;*(pYUVData+i*width*2+j*4+2) = Y2;*(pYUVData+i*width*2+j*4+3) = V1;}} }else{for (int i=0; i<height; ++i){for (int j=0; j<width/2; ++j){B1 = *(pRGBData+(height-i-1)*width*3+j*6);G1 = *(pRGBData+(height-i-1)*width*3+j*6+1);R1 = *(pRGBData+(height-i-1)*width*3+j*6+2);B2 = *(pRGBData+(height-i-1)*width*3+j*6+3);G2 = *(pRGBData+(height-i-1)*width*3+j*6+4);R2 = *(pRGBData+(height-i-1)*width*3+j*6+5);Y1 = (((66*R1+129*G1+25*B1+128)>>8) + 16) > 255 ? 255 : (((66*R1+129*G1+25*B1+128)>>8) + 16);U1 = ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128)>255 ? 255 : ((((-38*R1-74*G1+112*B1+128)>>8)+((-38*R2-74*G2+112*B2+128)>>8))/2 + 128);Y2 = (((66*R2+129*G2+25*B2+128)>>8) + 16)>255 ? 255 : ((66*R2+129*G2+25*B2+128)>>8) + 16;V1 = ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128)>255 ? 255 : ((((112*R1-94*G1-18*B1+128)>>8) + ((112*R2-94*G2-18*B2+128)>>8))/2 + 128);*(pYUVData+i*width*2+j*4) = Y1;*(pYUVData+i*width*2+j*4+1) = U1;*(pYUVData+i*width*2+j*4+2) = Y2;*(pYUVData+i*width*2+j*4+3) = V1;}} }}return 0;
}//
// pGBYUV point to the background YUV data
// pFGYUV point to the foreground YUV data
// width width of the picture
// height height of the picture
// alphaBG is there an alpha channel in background YUV data
// alphaFG is there an alpha channel in fourground YUV data
//
int YUVBlending(void* pBGYUV, void* pFGYUV, int width, int height, bool alphaBG, bool alphaFG)
{if (NULL == pBGYUV || NULL == pFGYUV){return -1;}unsigned char* pBGData = (unsigned char*)pBGYUV;unsigned char* pFGData = (unsigned char*)pFGYUV;if (!alphaFG){if (!alphaBG){memcpy(pBGData, pFGData, width*height*2);}else{for (int i=0; i<height; ++i){for (int j=0; j<width/2; ++j){*(pBGData+i*width*2+j*4) = *(pFGData+i*width*2+j*4);*(pBGData+i*width*2+j*4+1) = *(pFGData+i*width*2+j*4+1);*(pBGData+i*width*2+j*4+2) = *(pFGData+i*width*2+j*4+2);*(pBGData+i*width*2+j*4+3) = *(pFGData+i*width*2+j*4+3);}}}}int Y11, U11, V11, Y12, Y21, U21, V21, Y22;int alpha1, alpha2;if (!alphaBG){for (int i=0; i<height; ++i){for (int j=0; j<width/2; ++j){Y11 = *(pBGData+i*width*2+j*4);U11 = *(pBGData+i*width*2+j*4+1);Y12 = *(pBGData+i*width*2+j*4+2);V11 = *(pBGData+i*width*2+j*4+3);Y21 = *(pFGData+i*width*3+j*6);U21 = *(pFGData+i*width*3+j*6+1);Y22 = *(pFGData+i*width*3+j*6+2);V21 = *(pFGData+i*width*3+j*6+3);alpha1 = *(pFGData+i*width*3+j*6+4);alpha2 = *(pFGData+i*width*3+j*6+5);*(pBGData+i*width*2+j*4) = (Y21-16)*alpha1/255+(Y11-16)*(255-alpha1)/255+16;*(pBGData+i*width*2+j*4+1) = ((U21-128)*alpha1/255+(U11-128)*(255-alpha1)/255 + (U21-128)*alpha2/255+(U11-128)*(255-alpha2)/255)/2+128;*(pBGData+i*width*2+j*4+3) = ((V21-128)*alpha1/255+(V11-128)*(255-alpha1)/255 + (V21-128)*alpha2/255+(V11-128)*(255-alpha2)/255)/2+128;*(pBGData+i*width*2+j*4+2) = (Y22-16)*alpha2/255+(Y12-16)*(255-alpha2)/255+16;}}}else{for (int i=0; i<height; ++i){for (int j=0; j<width/2; ++j){Y11 = *(pBGData+i*width*3+j*6);U11 = *(pBGData+i*width*3+j*6+1);Y12 = *(pBGData+i*width*3+j*6+2);V11 = *(pBGData+i*width*3+j*6+3);Y21 = *(pFGData+i*width*3+j*6);U21 = *(pFGData+i*width*3+j*6+1);Y22 = *(pFGData+i*width*3+j*6+2);V21 = *(pFGData+i*width*3+j*6+3);alpha1 = *(pFGData+i*width*3+j*6+4);alpha2 = *(pFGData+i*width*3+j*6+5);*(pBGData+i*width*3+j*6) = (Y21-16)*alpha1/255+(Y11-16)*(255-alpha1)/255+16;*(pBGData+i*width*3+j*6+1) = ((U21-128)*alpha1/255+(U11-128)*(255-alpha1)/255 + (U21-128)*alpha2/255+(U11-128)*(255-alpha2)/255)/2+128;*(pBGData+i*width*3+j*6+3) = ((V21-128)*alpha1/255+(V11-128)*(255-alpha1)/255 + (V21-128)*alpha2/255+(V11-128)*(255-alpha2)/255)/2+128;*(pBGData+i*width*3+j*6+2) = (Y22-16)*alpha2/255+(Y12-16)*(255-alpha2)/255+16;}}}return 0;
}
YUY2(YUV) 与 RGB 格式图片的相互转换相关推荐
- YUY2(YUV) 与 RGB 格式图片的相互转换 以及 基于YUY2(YUV)的blending
这是一个项目里使用的,API里从pool里取出的格式都是YUY2,但是图像处理的API库中要求都是jepg格式. YUY2经常用于电视制式以及许多摄像头的输出格式.而我们在处理时经常需要将其转化为RG ...
- 【DSP开发】【VS开发】YUV与RGB格式转换
[视频处理]YUV与RGB格式转换 YUV格式具有亮度信息和色彩信息分离的特点,但大多数图像处理操作都是基于RGB格式. 因此当要对图像进行后期处理显示时,需要把YUV格式转换成RGB格式. RGB与 ...
- 数据压缩实验一:yuv转rgb格式实验报告
数据压缩实验一:yuv转rgb格式实验报告 一:实验基本原理 yuv转rgb格式转换公式: R=Y+1.4020*(V-128) G=Y-0.3441*(U-128)-0.7141*(V-128) B ...
- YUV与RGB格式的相互转换及误差
一.RGB转YUV 1.原理 a.YUV的计算公式: b.动态保护范围: 2.源代码 源代码为老师发的代码此处略 3.实验结果 a.原rgb: b.转换后yuv: 二.YUV转RGB 1.原理 a.R ...
- java+解析png+gif图片_Java 转换png jpg gif格式图片的相互转换的实现
利用JDK原生支持对png jpg gif格式图片做相互转换,结合脚本就可以达到批量处理的能力,比PS来的快啊!而且是JAVA代码 在Windows和Linux上都可以用. import java.a ...
- YUV与RGB格式详解
YUV 是一种颜色编码方法,和它等同的还有 RGB 颜色编码方法. RGB 颜色编码 RGB 三个字母分别代表了 红(Red).绿(Green).蓝(Blue),这三种颜色称为 三原色,将它们以不同的 ...
- YUV 格式与 RGB 格式的相互转换公式总结(C++版)
YUV 格式与 RGB 格式的相互转换公式 最近在用的一个工业相机,输出的图像格式是 YUY2 格式.而在电脑上显示时需要 RGB 格式,所以就花了些时间在网上查了些相关的资料.说实话,网上关于 YU ...
- 图片YUV格式与RGB格式的转换
YUV格式与RGB格式的转换 YUV格式介绍 YUV420.YUV422.YUV444 (1) YUV4:2:0 (2) YUV4:2:2 (3) YUV4:4:4 内存排列方式 YUV与RGB转换 ...
- YUV / RGB 格式及快速转换算法
1 前言 自然界的颜色千变万化,为了给颜色一个量化的衡量标准,就需要建立色彩空间模型来描述各种各样的颜色,由于人对色彩的感知是一个复杂的生理和心理联合作用 的过程,所以在不同的应用领域中为了更好更准确 ...
最新文章
- js base64编码解码 btoa atob 函数简介
- 使用eBPFbcc提取内核网络流量信息(二)
- 转载:QT图形视图框架(The Graphics View Framework)
- 向大家推荐一个.Net游戏引擎:Artificial Engines
- JavaScript/JS的学习
- 【每日SQL打卡】​​​​​​​​​​​​​​​DAY 10丨买下所有产品的客户【难度中等】
- Incorrect string value: '/xE7/xA8/x8B/xE5/xBA/x8F...' for column 'course' at row 1
- mvn -DskipTests和-Dmaven.test.skip=true区别
- Spring Security OAuth2.0_实现分布式认证授权_微服务解析令牌并鉴权_Spring Security OAuth2.0认证授权---springcloud工作笔记154
- CCCC-GPLT L1-038. 新世界 团体程序设计天梯赛
- html 页面缩放事件,浏览器缩放不触发window.onresize事件的BUG
- 最好用的 8 款 React Datepicker 时间日期选择器测评推荐
- windows10只显示图标不显示缩略图
- 自定义Dialog 实现 仿网易云音乐的隐私条款声明弹框
- 物理实验室改造前搬迁注意事项有哪些TENAISU
- AMOS分析技术:模型整体拟合度指标
- 转换并压缩视频的小技巧
- 泰迪杯数据挖掘第十届B题,时间序列预测
- java 图片签章(颜色像素)提取并优化
- 梁继璋给儿子的一封信