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 W_{b}/W_{r} 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:

- rgbyuv8 to draw the corners of the RGB-cube and YUV-parallelepiped (3D Scatter)
- cube to draw the cube and parallelepiped to draw the parallelepiped (3D Lines)
- rgbyuv contains some 3000 generated RGB- and corresponding YUV values (3D Scatter)

All according to ITU BT.601 using W_{b} = 0.114 and W_{r} = 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 W_{b} or W_{r} or both, the volume was always W_{g}. 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 = −W_{r}(−W_{g}W_{b}+W_{g}W_{b}) − (1−W_{r})(−W_{g}W_{b}−(1−W_{b})W_{g}) + W_{r}(W_{g}W_{b}+W_{g}(1−W_{b}))

det = 0 − (1−W_{r})(−W_{g}) + W_{r}(W_{g})

det = W_{g} − W_{r}W_{g} + W_{r}W_{g}

**det = W _{g}**

We can now state that any YUV-type transformation of the RGB color space cube will result in a parallelepiped with volume of W_{g} = 1 − W_{b} − W_{r}.

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, W_{g} (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.

20180308

Fri Jun 21 11:17:52 UTC+0200 2019 © A. Tarpai