Both RGB and YUV are color spaces that represent colors that can be converted to each other.
Similar to our familiar RGB, YUV is also a color coding method, it will be the brightness information (Y) and color information (UV) separation, no UV information can display the full image, but black and white, such a design to solve the color TV and black and white compatibility problem. In addition, YUV does not require three independent video signals to be transmitted simultaneously as RGB, so it uses a very small bandwidth in YUV mode.
The storage format of YUV stream is closely related to the sampling method, there are three kinds of main sampling methods, yuv4:4:4,yuv4:2:2,yuv4:2:0
Difference between the conversion formula of one and RGB
Yuv<-->rgb
Y "= 0.299*r" + 0.587*g "+ 0.114*b"
U ' = -0.147*r '-0.289*g ' + 0.436*b ' = 0.492* (B '-Y ')
V "= 0.615*r"-0.515*g "-0.100*b" = 0.877* (R '-Y ")
R ' = Y ' + 1.140*v '
G "= Y"-0.394*u "-0.581*v"
B ' = Y ' + 2.032*u '
Ycbcr<-->rgb
Y ' = 0.257*r ' + 0.504*g ' + 0.098*b ' + 16
Cb ' = -0.148*r '-0.291*g ' + 0.439*b ' + 128
Cr ' = 0.439*r '-0.368*g '-0.071*b ' + 128
R ' = 1.164* (Y ' -16) + 1.596* (Cr '-128)
G ' = 1.164* (Y ' -16)-0.813* (Cr ' -128)-0.392* (CB '-128)
B ' = 1.164* (Y ' -16) + 2.017* (Cb '-128)
Note: Each symbol above has an apostrophe, indicating that the symbol is gamma correction based on the original value
Ii. Differences in sources
The YUV color model is derived from the RGB model,
The model is characterized by the separation of luminance and chroma, which is suitable for the field of image processing.
The first formula is used when YUV converts RGB (range 0-255), and the second formula is used when YUV (601) becomes the YCbCr conversion RGB (range 0-255).
1.Y = 0.299R + 0.587G + 0.114B
U = -0.147r-0.289g + 0.436B
V = 0.615r-0.515g-0.100b
R = Y + 1.14V
G = y-0.39u-0.58v
B = Y + 2.03U
2.b= 1.164 * (Y-16) + 2.018 * (U-128)
g= 1.164 * (Y-16)-0.38 * (U-128)-0.813 * (V-128)
R= 1.164 * (Y-16) + 1.159 * (V-128)