Color Spaces

There are different methods for encoding the color of a pixel. Some of the more common ones are discussed here.

RGB

The RGB system is based off the fact that white light (and therefore its consituents) can be made up of just three primary colors -

  • Red
  • Green
  • Blue
    It is an additive color model, it works how light works in real life. Mixing red, green and blue light will yield white.
    So an image in RGB color space, will have 3 channels, one for each color. The range of a channel depends on the color depth, which is the number of bits used per channel.
    Example

    A more common usage of RGB color space, includes using unsigned char for the storage of a pixel per channel. An unsigned char is 1 byte (8 bit color depth), and allows for a range from 0 to 255.
    This allows for possible colors.

RGBA

Additionally, adding an alpha channel for transparency gives us the RGBA color space. Alpha 0 is transparent and alpha 1 is fully opaque. PNG supports both 24bit RGB and 32bit RGBA.

HSV/HSB and HSL/HLS

HSV is a human friendly color space. Only one of its three channels, hue(H) is used for representing the main base color. The other two channels are saturation(S) and value(V).

  • Hue ranges from 0 to 360. It is basically a circular color wheel with
    • Red at
    • Green at
    • Blue at
  • Saturation ranges from 0 to 100. 0 is white, 100 is highest saturation or "most colorful"
  • Value (or brightness) can be thought of as the intensity of a color. It ranges from 0 to 100. 0 indicates black, 100 indicates maximum brightness
    HSL (or HLS) is very similar to HSV, in the sense that two their channels - hue and saturation, have similar meaning. But it differs with the third channel, lightness(L).
  • Lightness ranges from 0 to 100. 0 is black, and 100 is white (unlike value)

CMYK

This is a subtractive color model unlike RGB. Pigments in real life, follow subtractive coloring. Mixing perfectly red, green and blue paints will yield black paint. CMYK is more realistic, with respect to pigments, and is therefore used with printers. The fourth channel, key(K) can be thought of as "darkness" or "inverted brigthness". 0% would mean no black pigment and 100% would mean it is fully black.

The simplest explanation I could come up with for CMYK, is that we start off with a white pigment. So CMYK(0, 0, 0, 0) is pure white.
Cyan at 1, would imply that we applied a cyan pigment, and therefore the constituents of cyan - blue and green are the only wavelengths reflected, and red is absorbed.

  • CMYK(1, 0, 0, 0) can be thought of as "subtract red light from white, resulting in blue + green = cyan"
  • CMYK(1, 1, 0, 0) for example, would mean "subtract red and green from white, resulting in blue"