[Audio and video basics] RGB and YUV

Digital Image Coding Method

It refers to what encoding method is used to represent each pixel in the image in the computer.

RGB

The basic three primary colors: red (Red), green (Green), blue (Blue). Identify colors based on the wavelengths of visible light.

RGB16:RGB565、RGB555

RGB565

16 bits per pixel, 2 bytes. The RGB components use 5 bits, 6 bits, and 5 bits, respectively.

![[../_resources/RGB_与_YUV.resources/unknown_filename.3.png]]

RGB555

16 bits per pixel, 2 bytes. The RGB components use 5 bits, 5 bits, and 5 bits respectively (the highest bit is not used).

![[../_resources/RGB_与_YUV.resources/unknown_filename.4.png]]

RGB24

24 bits per pixel, 3 bytes. The RGB components use 8 bits each.

Note: The arrangement order of RGB components in the memory is: BGR BGR BGR …

![[../_resources/RGB_与_YUV.resources/unknown_filename.5.png]]

RGB32

32 bits per pixel, 4 bytes. The RGB components use 8 bits respectively, and 8 bytes are reserved at the end.

Note: The arrangement order of RGB components in the memory is: BGRA BGRA BGRA …

ARGB32

The essence is RGB24 with an alpha channel. The difference from RGB32 is that the reserved 8 bits are used to represent transparency, which is the value of alpha.
Note: The arrangement order of RGB components in the memory is: BGRA BGRA BGRA …

insert image description here


YUV

"Y" means brightness (Luminance), "U" and "V" are chroma and concentration (Chrominance, Chroma).

advantage:

  1. The three components of R, G, and B are strongly correlated, and there is redundancy, and data compression can be performed after using YUV
  2. The human eye is more sensitive to luminance signals and less sensitive to chrominance signals, and can perform data compression with less UV components
  3. Color signal can be well compatible with black and white TV, black and white video only has Y component
YUV、YCbCr

YUV: for analog signals.
YCbCr: For digital signals, it is a version of YUV compression and offset.
Commonly known as YUV mostly refers to YCbCr. The following is the three components of a YCbCr image, where Y refers to the brightness component, Cb refers to the blue chroma component, and Cr refers to the red chroma component.

insert image description here

YUV sampling
  • YUV 4:4:4 sampling, each Y corresponds to a set of UV components. 24 Bits per Pixel.

  • YUV 4:2:2 sampling, every two Y share a set of UV components. 16 Bits per Pixel.

  • YUV 4:2:0 sampling, every four Y shares a set of UV components. 12 Bits per Pixel.

  • Total size: width * height * 3 / 2

![[../_resources/RGB_与_YUV.resources/unknown_filename.1.png]]

The black dot in the figure above indicates the Y component of the pixel, and the hollow circle indicates the UV component of the pixel.

YUV storage format

There are two types of YUV storage formats:

  • Packed formats : Store the Y, U, and V values ​​into an array of Macro Pixels, which is similar to the way RGB is stored. For the YUV4:4:4 format, it is most suitable to use the compressed format. The approximate format is: YUVYUVYUVYUV
  • Planar formats : Store the three components of Y, U, and V in different matrices. The approximate format is: YYYYUV.
YUV common representation method

According to different sampling methods and storage formats, there are a variety of YUV formats. These formats are mainly based on YUV 4:2:2 and YUV 4:2:0 sampling.

The common ones are almost all based on YUV4:2:0:

  • YU12 . Store the Y component first, and then store the U and V components. For example: YYYYYYYYUUVV.
  • YV12 , also known as I420 format. Its storage format is to reverse V and U. For example: YYYYYYYYVVUU.
  • NV12 . The Y component is stored first, but then instead of storing all the U or V components, the UV components are stored alternately and continuously. For example: YYYYYYYYUVUV. NV12 is used more in hardware codec.

As shown in the figure below, it is the storage format of YUV420, and each 4 Y corresponds to a group of UVs:

insert image description here

Guess you like

Origin blog.csdn.net/qq_41214278/article/details/128161168