http://halicery.com/3Video Decoders/YUV investigations.html

YUV conversion investigations

YUV

YUV comes from analogue TV.

First there was a B/W-system with one brightness signal (luminance, Y):

          B/W sender                      B/W receiver    
      +-----------------+                 +---------+
R --> | Wr -->          |                 |         | 
G --> | Wg -->    Y     | ~~~~~ Y ~~~~~~> |    Y    |  
B --> | Wb -->          |                 |         |
      +-----------------+                 +---------+

Y = Wr R + Wg G + Wb B

The overall brightness (luminance) is a weighted sum of the 3 RGB color components computed by the sender. Constants may vary, but Wr + Wb + Wg = 1, so full RGB (white) makes full luma brightness. Also Wg = 1 - Wb - Wr so giving only Wb and Wr can specify the conversion.

Colour television system added two 2 chrominance signals, without changing Y, as red- and blue difference.

         Colour sender                   Colour receiver
      +-----------------+                 +----------+
R --> | Wr -->    R-Y   | ~~~~~ V ~~~~~~> | Wr --> R |   
G --> | Wg -->    Y     | ~~~~~ Y ~~~~~~> | Wg --> G |   
B --> | Wb -->    B-Y   | ~~~~~ U ~~~~~~> | Wb --> B |   
      +-----------------+                 +----------+

Y = Wr R + Wg G + Wb B
U = B - Y
V = R - Y

The colour receiver recovers the original RGB levels by using:

B = Y + U
R = Y + V
G = Y - Wb/Wg U - Wr/Wg V

Note, that colour receivers should use the same Wb/Wr constants as the sender.

But why color difference and not simply R/B? The answer is compatibility between senders and receivers.

The B/W TV could still receive coloured signal sending and display as B/W by simply not using the chroma signals:

+--------+                  +--------+
|        | ~~~~~ V          |        |
| colour | ~~~~~ Y ~~~~~~~> |  B/W   |
|        | ~~~~~ U          |        |
+--------+                  +--------+

And a colour TV could still receive and display a B/W sending having chrominance set to zero:

+--------+                  +--------+    
|        |           0 ~~~> |        |    
|  B/W   | ~~~~~ Y ~~~~~~~> | color  |    
|        |           0 ~~~> |        |    
+--------+                  +--------+    

This really works, all RGB will be the same, the color TV shows the B/W picture:

B = Y + 0 = Y
R = Y + 0 = Y
G = Y - Wb/Wg U - Wr/Wg V = Y

Explaning G = Y - Wb/Wg U - Wr/Wg V = Y:

G = ( Y - Wb B - Wr R ) / Wg
G = ( Y - Wb(Y+U) - Wr(Y+V) ) / Wg
G = ( Y - WbY - WbU - WrY - WrV ) / (1-Wb-Wr)
G = Y( 1 - Wb - Wr )/(1-Wb-Wr) - ( Wb U - Wr V ) / (1-Wb-Wr)
G = Y - Wb/Wg U - Wr/Wg V

YUV levels

Lets say analogue RGB levels are of [0..1]. Then Y is also [0..1]. U/V are Wb/Wr-dependent.

This may looks like this:

1  ----- ~~~~~~~~~~~~~~~~~ ---------------------------------------------------------------------------------  1
         ~~~~~~~~~~~~~~~~~            ~~~~~~~~~~~~~~~~~ +Umax      
         ~~~~~~  Y  ~~~~~~            ~~~~~~~~~~~~~~~~~              ~~~~~~~~~~~~~~~~~ +Vmax       
         ~~~~~~~~~~~~~~~~~            ~~~~~~~~~~~~~~~~~              ~~~~~~~~~~~~~~~~~  
         ~~~~~~~~~~~~~~~~~            ~~~~~~~~~~~~~~~~~              ~~~~~~~~~~~~~~~~~
         ~~~~~~~~~~~~~~~~~            ~~~~~~  U  ~~~~~~              ~~~~~~  V  ~~~~~~
0  ----- ~~~~~~~~~~~~~~~~~ ---------- ~~~~~~~~~~~~~~~~~ ------------ ~~~~~~~~~~~~~~~~~ ---------------------  0
                                      ~~~~~~~~~~~~~~~~~              ~~~~~~~~~~~~~~~~~
                                      ~~~~~~~~~~~~~~~~~              ~~~~~~~~~~~~~~~~~        
                                      ~~~~~~~~~~~~~~~~~              ~~~~~~~~~~~~~~~~~ -Vmax
                                      ~~~~~~~~~~~~~~~~~ -Umax       
-1 --------------------------------------------------------------------------------------------------------- -1

Using ITU BT601 constants:

Wb = 0.114
Wr = 0.299

U = B - Y
V = R - Y

Computing +/-Umax and +/-Vmax:

R=G=0, B=1
U = B - Wb B = 1 - Wb = 0.886 (Umax)

B=G=0, R=1
V = R - Wr R = 1 - Wr = 0.701 (Vmax)

R=G=1, B=0:
U = 0 - Wr - 1 + Wr + Wb = -1 + Wb = -0.886 (-Umax)

B=G=1, R=0:
V = 0 - 1 + Wr + Wb - Wb = -1 + Wr = -0.701 (-Vmax)

Note, that U/V range is bigger than 1:

2Umax= 1.772
2Vmax= 1.402


Sun Jun 17 22:40:56 UTC+0200 2018 © A. Tarpai