semmixcolor and perception

The RGB model

RGB describes a color as a mixture of three lights: red, green and blue. Every screen, camera and image sensor works this way, which makes RGB the starting point of almost every color computation.

Additive mixing

In RGB, colors are made by adding light. No light is black; all three at full power is white. Pairs give the secondary colors:

red + green = yellow (1, 1, 0) green + blue = cyan (0, 1, 1) blue + red = magenta (1, 0, 1) red + green + blue = white (1, 1, 1)

Why these three? Because the eye has three kinds of cones, most sensitive to short, medium and long wavelengths (see the model of the eye). Three well-chosen lights stimulate them in proportions the eye reads as a great many different colors. Mixing lights follows Grassmann's laws, covered under color mixing.

The RGB cube

Every RGB color is a point (R, G, B) in a cube with side 1. Black (0, 0, 0) sits at one corner, white (1, 1, 1) at the opposite one. The diagonal between them holds the grays, where R = G = B. The other six corners are red, green, blue, cyan, magenta and yellow.

The HSV and HLS models are derived from this cube: they look along the gray diagonal and measure the angle around it.

8-bit and hexadecimal notation

In practice each component usually has 8 bits, values 0..255. That gives 256³ = 16,777,216 combinations. HEX notation joins the three bytes into one hexadecimal string:

#c85028 → c8 = 200, 50 = 80, 28 = 40 → RGB (200, 80, 40) for computation, divide by 255: R = 200 / 255 = 0.7843 G = 0.3137 B = 0.1569

HDR photos and video use 10, 12 or 16 bits per component. More bits do not widen the range of colors; they split it into finer steps, which removes banding in gradients.

RGB is a model, not a color space

The triple (200, 80, 40) looks different on every screen until you know the primaries, the white point and the gamma curve. A specific RGB color space defines all three:

SpaceYearWhiteUse
sRGB1996D65the web, most monitors and phones, default for untagged files
Adobe RGB (1998)1998D65photography for print, wider gamut in greens and cyans
Display P32015D65Apple displays and newer phones, wider in reds and greens
Rec. 20202012D65UHD and HDR television, very wide gamut

On the CIE chromaticity diagram each RGB space is a triangle with its primaries at the corners. Colors outside the triangle cannot be reached in that space. The exact conversion of sRGB to device-independent color is on the CIE XYZ and RGB page.

RGB values in files are gamma-encoded, so they are not proportional to light. 128 is about 22% of the light, not half. Linearize them before blending or resizing; see gamma correction.