Introduction

YUV is a color encoding system used as part of a color image pipeline. It encodes a color image or video taking human perception into account, allowing reduced bandwidth for chrominance components. Y’UV model defines a color space in terms of one luma (Y’) and two chrominance (UV) components. Y′ stands for the luma component (the brightness) and U and V are the chrominance (color) components. Luminance is denoted by Y and luma by Y′. Prime symbols (‘) denote gamma compression, with Luminance meaning physical linear-space brightness, while Luma is (nonlinear) perceptual brightness.

YPbPr color model used in analog component video and its digital version YCbCr used in digital video.Y′ stands for the luma component (the brightness) and U and V are the chrominance (color) components. Luminance is denoted by Y and luma by Y′. Prime symbols (‘) denote gamma compression, with Luminance meaning physical linear-space brightness, while Luma is (nonlinear) perceptual brightness.

Conversion Coefficients

Luminance is defined as a weighted sum of the color components, usually weighted according to the relative ability of red, green and blue to cause perceived brightness changes in an image. Weighted values of R, G, and B are summed to produce Y′, a measure of overall brightness or luminance. U and V are computed as scaled differences between Y′ and the B and R values.

CoefficientsRec. 601Rec. 709
Kr (Red Channel Coefficient)0.2990.2126
Kg (Green Channel Coefficient)0.5870.7152
Kb (Blue Channel Coefficient)0.1140.0722
Color Coefficient in Rec. 601 and Rec. 709

RGB <-> YUV conversion is given below with (0.0 <= [Y,R,G,B] <= 1.0) ; (-1.0 <= [U,V] <= 1.0).

Kg = 1- Kr - Kb

Y = Kr*R + Kg*G + Kb*B
V = (R-Y)/(1-Kr) = R - G * Kg/(1-Kr) - B * Kb/(1-Kr)
U = (B-Y)/(1-Kb) = - R * Kr/(1-Kb) - G * Kg/(1-Kb) + B

R = Y + V*(1-Kr)
G = Y - U*(1-Kb)*Kb/Kg - V*(1-Kr)*Kr/Kg
B = Y + U*(1-Kb)

BT.601 Conversion Matrix

Substituting values for the constants and expressing them as matrices gives these formulas:

BT 601 RGB to YUV and RGB to YUV conversion matrix
Equation 0: BT 601 Conversion Matrix

First row of top equation (R’G’B’ to Y’PbPr conversion matrix) comprises the luma coefficients; these sum to unity. The second and third rows each sum to zero, a necessity for color difference components.. R’G’B’ and Y’PbPr is ranging from 0 to 1. R’G’B’ reference black is zero and reference white is unity. It can also be represented as

Y =  0.299R + 0.587G' + 0.114B'
U = -0.168R - 0.331G' + 0.5B'
V =  0.5R - 0.418G' - 0.081B'

R = Y + 0U + 1.402V
G = Y - 0.344U - 0.714V
B = Y + 1.772U + 0V

RGB To YCbCr Conversion

Y′ values are conventionally shifted and scaled to the range [16, 235] (referred to as studio swing or TV levels or SDI range) rather than using the full range of [0, 255] (referred to as full swing or PC levels). To provide footroom to accommodate luma signals that go slightly negative, an offset is added to luma. For 8-bit, an offset of +16 is added; this places black at code 16 and white at code 235. In CbCr an offset of +128 is added. In studio Y’CbCr, chroma reference levels are 16 and 240. BT.709 nominal ranges are the same as those defined in BT.601.

For arithmetic operations such as gain adjustment, Y’, Cb, and Cr must be zero for black. For 8-bit luma arithmetic, reference black is at code 0 and reference white at code 219. To obtain 8-bit Y’CbCr from R’G’B’ ranging from 0 to 1, scale the rows in above matrix by the factors 219, 224, and 224, corresponding to the excursions of each of Y’, Cb, and Cr respectively.

BT. 601 RGB to YUV 8bit
Equation 1: RGB to YUV 8 Bit

Summing the top row of above matrix (Equation 1) yields 219, the luma excursion. The lower two rows sum to zero. The two entries of 112 reflect the positive Cb and Cr extrema, at the blue and red primaries.

Studio RGB To YCbCr

In studio equipment, 8-bit R’G’B’ components have the same 219 excursion as the luma component of Y’CbCr. To encode 8-bit Y’CbCr from R’G’B’ in the range [0…219], scale the above matrix by (256/219).

Studio RGB 8 Bit To YCbCr 8 Bit Conversion
Studio RGB 8 Bit To YCbCr 8 Bit Conversion

Computer RGB To YCbCr

Black is at code 0 and white is at 255 if 8-bit R’G’B’ components has no headroom and no footroom. To encode 8-bit Y’CbCr from R’G’B’ in this range [0….255], scale the matrix of Equation1 by (256/255) i.e.

Full RGB 8 Bit To YCbCr 8 Bit Conversion
Full RGB 8 Bit To YCbCr 8 Bit Conversion

RGB To Full Swing YCbCr

The Y’CBCR coding used in JPEG/JFIF uses full-swing coding with no footroom and no headroom. Luma (Y’) is scaled to an excursion of 255 when represented in 8 bits. To obtain 8-bit Y’CbCr, with luma in the range [0…255] and CB and CR each ranging ±128 from R’G’B’ ranging from [0…255], scale the rows in Equation 0 by the factor 256, corresponding to the excursions of each of Y’, Cb, and Cr respectively.

RGB to Full Swing YCbCr Conversion
RGB to Full Swing YCbCr Conversion

Reference

YUV Color System