The ITU BT.601 YUV-space compared to the size of the RGB-cube. Made with plot.ly
After some YUV-RGB conversion equations and code I was wondering how the YUV color space might look like in 3D, how it can be visualised along with the RGB color space side by side. RGB is a 3-component additive color system, usually drawn as a cube: a specific color-vector is a 3-dimensional vector in the euclidian space and equals to R + G + B, where R, G and B are orthogonal vectors with a magnitude all ranging from 0 to 1. The 8 corners of the RGB cube corresponds to 8 extreme colors: K (black), R, G, B, C, M, Y and W (white).
But how does the YUV color space look like? What are the boundaries and volume (i.e. coverage) of the YUV color space object? Further on ITU BT.601 Wb/Wr constants were used to calculate the YUV values.
Y = Wr R + Wg G + Wb B U = B - Y = B (1 − Wb ) + Wg G + Wr R V = R - Y = R (1 − Wr ) + Wg G + Wb B BLACK RED GREEN BLUE CYAN MAGENTA YELLOW WHITE R 0 1 0 0 0 1 1 1 G 0 0 1 0 1 0 1 1 B 0 0 0 1 1 1 0 1 Y 0 0.299 0.587 0.114 0.701 0.413 0.886 1 U 0 -0.299 -0.587 0.886 0.299 0.587 -0.886 0 V 0 0.701 -0.587 -0.114 -0.701 0.587 0.114 0
RGB to YUV according to the equations is a linear transformation. Wise men say that the linear transformation of a cube is a parallelepiped. So the YUV space - when taking YUV as x,y,z coordinates - should look like a parallelepiped in 3D. But how? And what is the volume of the YUV parallelepiped, i.e. are there more or less YUV colors compared the RGB?
First I plotted U/V on a Descartian. I have chosen U/V for x,y during all these visualisations, because U/V range is between ±<1, while Y (the luminance of the color) has only positive values from 0 to 1. This will be our z-coordinate, the height of the dots on the 3D scatter plots, from black to all way up to white. Note that white and black on top of each other here, both has zero U/V chroma components.
K (black), R, G, B, C, M, Y and W (white)
Nice and symmetric, white and black at origin, complementer colors mirrored on origin. The grey color of the dots corresponds to the Y value, the luminance (I would color them with real colors, but this is not possible in plot.ly).
Now, lets include Y as z-coordinate and make 3D scatter plots. The grey color of Y might help to feel the height of the dot, the magnitude of the z-coordinate. With the size of the dots I tried to illustrate how far they are as we look at the graph from the point we look at. If it's still a little difficult to see the shape of this object, I also connected the corners of this supposedly parallelepiped:
Here are some other views of the object:
Now lets fill up the YUV space. Added a plot of around 3000 YUV values:
Actually, the best is to see all this in action and freely rotated. Here are the datasets I used with plot.ly to create all these images:
All according to ITU BT.601 using Wb = 0.114 and Wr = 0.299.
Wise men say that the volume of a parallelepiped is the scalar triple product of 3 vectors. From black (K= 0,0,0) you can see 3 vectors to the new RGB-points, which defines our ITU BT.601 YUV parallelepiped. The simplest way for calculating the volume is the compute the determinant of the 3 vectors. The result is a little surprising:
x (U) y (V) z (Y) R -0,299 0,701 0,299 G -0,587 -0,587 0,587 det = 0.587 B 0,886 -0,114 0,114
I was expecting something similar to the volume of the RGB-cube, which is 1. I had to doubleckeck this... Changing Wb or Wr or both, the volume was always Wg. Math is astonishing. The proof is clear when we compute the determinant of this 3 × 3 matrix below by hand:
x (U) y (V) z (Y) R -Wr 1-Wr Wr G -Wg -Wg Wg det = Wg B 1-Wb -Wb Wb
det = −Wr(−WgWb+WgWb) − (1−Wr)(−WgWb−(1−Wb)Wg) + Wr(WgWb+Wg(1−Wb))
det = 0 − (1−Wr)(−Wg) + Wr(Wg)
det = Wg − WrWg + WrWg
det = Wg
We can now state that any YUV-type transformation of the RGB color space cube will result in a parallelepiped with volume of Wg = 1 − Wb − Wr.
This is an illustration of integer digital YUV values according to the two types of standard. The full-range digital YUV (say "PbPr") quantises YUV values between 0..255 on 8-bits. These are the red dots, which space is a little bigger than the ranged digital YUV (say "CbCr"). For CbCr Y' is between 16..235, while the two digital chroma between 16..240. These transform the original RGB cube into slightly different parallelepipeds:
In the real number or analugue realm every RGB-triplet has its distinct counterpart in the YUV-space. The volume of the RGB-cube is 1, i.e. the RGB-space covers one cubic. The parallelepiped YUV-space is smaller and equals to the green weight, Wg (see the scalar triple product above). Therefore, when it comes to quantisation of the YUV-space as used in different digital YUV standards, not every RGB color will result in different digital YUV values. Restoring RGB values from digital YUV will certainly miss come RGB colors.