The YUV Color Space
Originally used for PAL (European "standard") analog video, YUV is based on the CIE Y primary, and also chrominance. Chrominance is the difference between a color and a reference white at the same luminance.
Y - Luminance Signal, "Lightness" U / V - Color Difference Signals S - Saturation H - Hue |
conversion from/to YUV
RGB -> YUV Y = 0.299*Red+0.587*Green+0.114*Blue U = -0.147*Red-0.289*Green+0.436*Blue V = 0.615*Red-0.515*Green-0.100*Blue |
YUV -> RGB Red = Y+0.000*U+1.140*V Green = Y-0.396*U-0.581*V Blue = Y+2.029*U+0.000*V |
relation between U-V and H-S
U = S * cos(H) V = S * sin(H) |
H = atan2(V,U) S = sqrt((U*U)+(V*V)) |
mixing colors
color-mixing works similar to RGB, just average each component separately:
Y' = (Y1+Y2)/2 U' = (U1+U2)/2 V' = (V1+V2)/2 |
H' = (H1+H2)/2 S' = (S1+S2)/2 |
computing color difference
again, similar to RGB, you may compute a color-difference value like this:
Y' = abs(Y1-Y2) U' = abs(U1-U2) V' = abs(V1-V2) YU' = (Y'*Y')+(U'*U') YV' = (Y'*Y')+(V'*V') UV' = (U'*U')+(V'*V') diff = YU' + YV' + UV' |