Understanding YUV data formats

来源:互联网 发布:sleep java。5分钟 编辑:程序博客网 时间:2024/06/04 22:56
SUMMARY:
This article explains the basics of YUV image data structure and transmission.

APPLICABLE PRODUCTS :All IEEE-1394 Camera Products • 
ANSWER:

Many Point Grey color camera models support the transmission of images in a YUV color encoding scheme. This scheme assigns both brightness and color values to each pixel. In ‘YUV,’ ‘Y’ represents the brightness, or ‘luma’ value, and ‘UV’ represents the color, or ‘chroma’ values. In contrast, the values of the RGB encoding scheme represent the intensities of red, green and blue channels in each pixel.

Each unique Y, U and V value comprises 8 bits, or one byte, of data. Where supported, Point Grey color camera models allow YUV transmission in 24, 16, and 12 bit per pixel (bpp) format. In 16 and 12 bpp formats, the U and V color values are shared between pixels, which frees bandwidth and may increase frame rate. Known as “chroma subsampling,” this technique takes into account the human eye’s greater sensitivity to variations in brightness than in color.

一般的camera模组输出的是YUV数据(也有输出RAW-RGB数据的,如5M OV5647)。每个Y,U,V都包含8个bit。摄像头模组输出的每个像素点的大小可以根据传送YUV数据格式来决定,可以是24bit(每个像素都传送YUV),16bit(每两个像素才传送一个V和一个U,第二个像素共享第一个像素的UV),12bit(每四个像素才传送一个V和一个U)

这样的采样方式可以减少camera接口传送数据的带宽,增加frame rate。并且这样的采样色彩的方式不会影响人眼的灵敏度。

在camera数据传送到处理器里面之后,也有输出RAW-RGB数据的数据就在内存里面根据之前的采样方式进行回复。SW based on V4L2.



Point Grey cameras support the YUV444, YUV422 and YUV411 data formats.

YUV444 Data Format

The YUV444 data format transmits 24 bits per pixel. Each pixel is assigned unique Y, U and V values—1 byte for each value, making it the most straightforward format to understand.

The bytes are ordered in the image in the following manner, where Y, U, V represent a single byte of color or brightness value, and 0, 1, 2… represent the pixel numbers associated with those values:

U0 Y0 V0 U1 Y1 V1 U2 Y2 V2…

This order results in the following data structure for each pixel:

Pixel Number

Pixel Values

0

U0Y0V0

1

U1Y1V1

2

U2Y2V2

YUV422 Data Format

The YUV422 data format shares U and V values between two pixels. As a result, these values are transmitted to the PC image buffer only once for every two pixels, resulting in an average transmission rate of 16 bits per pixel.

The bytes are ordered in the image in the following manner:

在这里可以清晰看到YUV422的方式,每第二个像素共享第一个像素的UV。即传送U0 Y0 V0 Y1即可表示两个像素。那么这时候bpp=(U0+Y0+V0+Y1)/2=16bit.第三个像素和第四个像素一样分析。

另外注意:

1、像素时钟采样的是:第一个像素采样时钟采样U0+Y0,第二个像素采样时钟采样V0+Y1。即每个像素用2个bytes16bit表示。两个像素组成一个宏像素??


2、注意4:2:2是以每两个像素做基础的。即第四次采样的U/V是第三次的U/V。


3、总之就是每个宏像素,即 每两个像素共享这组数据的第二像素的UV,即:比如:

第一组宏像素的用来表达第二个像素的color是基于他前面一个像素的:V0 下标是0.

同理第二组宏像素的用来表达此组第二个像素的color是基于前面像素的:V2.!!所以也叫共享。

U0 Y0 V0 Y1 U2 Y2 V2 Y3 U4 Y4 V4…

This order results in the following data structure for each pixel:


看看(4:2:2方式):在数据传送到处理器的时候,我们做恢复的时候每第二个像素的color UV 是采用上每第一个的。


Pixel Number

PixelValues

0

U0Y0V0

1

U0Y1V0

2

U2Y2V2

3

U2Y3V2

4

U4Y4V4

YUV411 Data Format

同理每四个像素共享第一个像素的color U/V。注意顺序!为什么不是U0 Y0 V0 Y1 Y2 Y3,而是下面的呢

The YUV411 format shares U and V values between four pixels, resulting in anaverage transmission rate of 12 bits per pixel.(4+2)*8/4=12bit.

The image bytes are ordered in the following manner:

U0 Y0 Y1 V0Y2 Y3 U4 Y4 Y5 V4 Y6 Y7…

This order results in the following data structure for each pixel:

Pixel Number

Pixel Value

0

U0Y0V0

1

U0Y1V0

2

U0Y2V0

3

U0Y3V0

4

U4Y4V4

5

U4Y5V4

6

U4Y6V4

7

U4Y7V4



YUV420 Data Format:如下解释:水平像素时钟第一行采样U,第二行采样V。bpp应该多少呢?我认为还是跟4:1:1的一样:如下奇场 偶场,每四个像素用6个bytes表述。bpp=12

码流:

Yo0 Uo0 Yo1 Yo2 Uo2 Yo3 Ye0 Ve0 Ye1 Ye2 Ve2 Ye3

将被映射为下面的两行各四个像素:

[Yo0 Uo0 Ve0] [Yo1 Uo0 Ve0] [Yo2 Uo2 Ve2] [Yo3 Uo2 Ve2][Ye0 Uo0 Ve0] [Ye1 Uo0 Ve0] [Ye2 Uo2 Ve2] [Ye3 Uo2 Ve2]

参考https://zh.wikipedia.org/wiki/%E8%89%B2%E5%BA%A6%E6%8A%BD%E6%A0%B7