Quiz: RGB, gamma, linear maps and white balance

Short questions to test your understanding. Try each on paper first, then open the answer. Stored 8-bit sRGB codes are gamma-encoded; “linear” values are proportional to light. Code 128 is 21.6 % of white’s light, code 188 is 50.3 %.


Q1. An image is half black (0) and half white (255), in fine one-pixel stripes. You shrink it by averaging 2 × 2 blocks of the stored codes. What value do you get, and what should it be?

Average the light, not the codes.

Averaging codes gives 127.5, i.e. 128, which is only 21.6 % of white’s light. The light averages to 50 %, which is stored as code 188. The naive result is much too dark.


Q2. Why are images stored gamma-encoded at all, if every computation has to undo it?

Where does the eye need small steps?

Perceived lightness grows roughly like the cube root of light, so the eye notices small absolute changes in the darks and only large ones in the brights. Encoding spends the 256 codes evenly in perceived lightness: with linear codes the darks would show banding and many bright codes would be wasted.


Q3. Two neighbouring regions, pure red and pure green, are blurred on the stored codes. Why does a dark band appear between them?

What light does a code of 128 in one channel stand for?

At the border each channel is about half its code: (128, 128, 0) in codes, which is only about 22 % of full red light plus 22 % of full green light. Blurring the light gives (0.5, 0.5, 0) in light, i.e. codes (188, 188, 0): as bright as its surroundings. Averaging codes loses light wherever values are mixed.


Q4. What do the three columns of the sRGB → XYZ matrix mean, and what does its middle row mean?

Multiply the matrix by (1, 0, 0).

Column k is the XYZ of primary k at full drive (the matrix times a unit vector). The middle row gives Y, the luminance: 0.2126R + 0.7152G + 0.0722B on linear values, the brightness contributed by each primary.


Q5. A picture of red letters on a green background becomes a blank grey image when converted to luminance. Is the conversion broken?

What does greyscale keep, and what does it throw away?

No. The letters and the background have the same luminance, and luminance is a projection of the 3D colour onto one direction: everything else (here the red–green difference) is discarded. Another projection (the channel mean, or the R channel alone) keeps the letters. Choose the greyscale direction that keeps the contrast you need.


Q6. JPEG stores Cb and Cr at half resolution in both directions. Why is that hardly visible, while halving the resolution of Y′ would be obvious?

Where is the detail of a natural image, and how does the eye see colour detail?

Edges and texture are mostly changes of brightness, carried by Y′. The visual system resolves fine detail in brightness but only coarse detail in colour differences, so losing three quarters of the chroma samples costs little that we can see. It halves the data (1.5 instead of 3 values per pixel).


Q7. Grey world on a forest scene turns the green leaves grey-magenta. Why?

What does grey world assume about the scene?

Grey world assumes the average colour of the scene is grey, and scales the channels until it is. A forest is mostly green, so its average is green; the correction removes green from everything, and the leaves (and any truly grey objects) end up magenta-tinted.


Q8. Why should the white-balance gains be applied to linear values rather than to the stored codes?

A lamp multiplies light. What does that do to codes?

The lamp multiplies the light in each channel by a factor, so the right correction is a multiplication of linear values. Codes are a non-linear function of light: multiplying a code by a factor does not multiply the light by a factor, and different brightnesses get different, wrong corrections (the midtones go off while the white comes out right).


Q9. (math) Show that the middle row of the matrix M = (\mathbf p_R\;\mathbf p_G\;\mathbf p_B)\operatorname{diag}(\mathbf s) equals \mathbf s, where each \mathbf p_k = (x_k/y_k, 1, (1 - x_k - y_k)/y_k).

What is the middle entry of each \mathbf p_k?

M_{2k} = (\mathbf p_k)_2\,s_k = 1 \cdot s_k. So the luminance weights of the primaries are exactly the scales found from the white point; for sRGB they are 0.2126, 0.7152, 0.0722.