RGB, YUV, and Color Spaces Part 2

In the last post, I touched upon the basics of YUV encoding. In this post, we will take a detailed look at YUV coding and some variants like YIQ, YPbPr (and its digital equivalent YCbCr). 
Given the (R, G, B) values of a pixel, the YUV values are computed as weighted sums as follows:
  • WR = 0.299, WG = 0.587, WB = 0.114 are the weights for R, G, B respectively
  • Umax = 0.436, Vmax = 0.615
  • Y = WR * R + WG * G + WB * B
  • U = Umax * (B – Y) / (1 – WB)
  • V = Vmax * (R – Y) / (1 – WR)

The RGB values can be computed from the YUV values as follows:

  • R = Y + V * (1 – WR) / Vmax
  • G = Y – U * WB * (1 – WB) / Umax * WG – V * WR (1 – WR) / Vmax * WG
  • B = Y + U * (1 – WB) / Umax

These transformations can be represented as matrix operations as follows:

Note that YUV encoding is used in PAL (Phase Alternating Line) and SECAM (Sequentiel Couleur a memoire, Sequential Color with Memory) analog TV encoding systems. PAL is used throughout most of Europe, Africa, Asia, Australia etc., while SECAM is used in France, Russia etc. The NTSC (National Television System Committee) standard used in North America uses a slightly different encoding called YIQ (I stands for In-phase, and Q stands for Quadrature; IQ are different axes, rotated 33o from the UV axes on the same plane). The Y calculation is the same, but IQ are computed as follows:
While YUV and YIQ are used in the context of composite video, YPbPr is used in the context of component video (YCbCr is the digital counterpart to YPbPr, and is obtained after applying scaling and offsets to YPbPr). YPbPr is obtained from RGB values as follows:

The values of KB and KR above are determined based on the RGB color space used (this is dependent on the TV circuitry rendering the colors). Note that RGB values are in the range [0, 1], and Y is in the range [0, 1], PBPare in the range [-0.5, 0.5]. For example, Standard Definition (SD) TV uses KB = 0.114 and KR = 0.299 (ITU-R BT.601 Standard), while High Definition (HD) TV uses KB = 0.0722 and KR = 0.2126 (ITU-R BT.709 Standard).

YCbCr is obtained from YPbPr as follows (Y is in the range [16, 235], CbCr are in the range [16, 240]):

So, why are the values scaled and offsets added to obtain YCbCr? Typically, the YCbCr encoding is used in DVDs, and needs to be converted into an analog signal to be fed into a TV. However, this signal processing can excurse beyond the levels acceptable to a TV, and will result in clipping artefacts.  On computers where analog signal processing is not an issue, YCbCr uses the full [0-255] range, for example, in the JPEG/JFIF standard.

References:

About annapureddy

Sidd is the VP of Engineering at Dyyno Inc. He received his Ph.D. and M.S. degrees from NYU, and Bachelor's from IIT Madras, all in Computer Science. http://www.scs.stanford.edu/~reddy/
This entry was posted in chroma sub-sampling, color space, encoding, gamma correction, hue, luminance, NTSC, PAL, RGB, saturation, SECAM, video coding, YCbCr, YIQ, YPbPr, YUV, YUV420. Bookmark the permalink.

Leave a comment