Understanding Chroma Subsampling
Chroma Subsampling animation
How RGB ↔ YUV Conversion Works
Step 1: RGB → YUV
For each pixel (r, g, b)
:
Y = 0.299r + 0.587g + 0.114b U = -0.169r - 0.331g + 0.500b + 128 V = 0.500r - 0.419g - 0.081b + 128
So every pixel gets its own Y, U, and V values.
Step 2: YUV 4:4:4
Here, all pixels keep their individual Y, U, V values. When converting back, you get the same RGB values — no quality loss.
Step 3: YUV 4:2:2 (horizontal subsampling)
Instead of storing U and V for every pixel, we share them between two horizontal neighbors.
U₄₂₂ = (U₀ + U₁) / 2 V₄₂₂ = (V₀ + V₁) / 2
Each pixel still has its own Y, but both share the same U, V values → horizontal chroma detail is reduced.
Step 4: YUV 4:2:0 (horizontal + vertical subsampling)
Now we average U and V across a 2×2 block of pixels:
U₄₂₀ = (U₀₀ + U₀₁ + U₁₀ + U₁₁) / 4 V₄₂₀ = (V₀₀ + V₀₁ + V₁₀ + V₁₁) / 4
Each pixel in the block keeps its own Y, but they all share the same U, V → both horizontal and vertical chroma detail are reduced.
Step 5: YUV → RGB
When reconstructing, we combine each pixel’s Y with the shared U, V:
R = Y + 1.402 (V - 128) G = Y - 0.344136 (U - 128) - 0.714136 (V - 128) B = Y + 1.772 (U - 128)
This gives the final RGB value used to draw the pixel.