Cheatsheets

Personal collection of cheatsheets.

Color

Index

Introduction

Colorimetry is the science that quantifies and describes physically the human color perception and color theory, in visual arts, is a body of practical guidance to color mixing.

During the 20th century two important color systems were created. The Munsell Color System and the Natural Color System (NCS). Both were based on human perception and derived from experiments.

Color Space

A color space is the set of colors and luminance values which can be captured, stored or displayed in a medium.

CIE

The CIE 1931 color spaces are the first defined quantitative links between distributions of wavelengths in the electromagnetic visible spectrum, and physiologically perceived colors in human color vision. They were created by the International Commission on Illumination (CIE) in 1931 from a series of experiments that were combined into the specification of the CIE RGB color space, from which the CIE XYZ color space was derived.

CIE Chromaticity Diagram

The diagram gives a common frame to define color spaces in xyY coordinates where xy is chrominance and Y is luminance.

Each color space has a gamut, a subset of colors that can be represented, and is defined by:

Color Spaces

Color space conversion is done with lineal values and depends on the primary colors and white points. There are several lists of matrices to convert RGB/XYZ and XYZ/RGB.

RGB(709)/RGB(2020)

XYZ = RGB709_TO_XYZ_MAT * RGB(709)
RGB(2020) = XYZ_TO_RGB2020_MAT * XYZ

Conversion assuming same white points.

XYZ(D50)/XYZ(D65)

LMS(D50) = XYZ_TO_LMS_MAT * XYZ(D50)
LMS(D65) = D50_TO_D65_CAT * LMS(D50)
XYZ(D65) = LMS_TO_XYZ_MAT * LMS(D65)

White points conversion matrices are called Chromatic Adaptation Transform (CAT) and are equivalent to apply a white balance.

XYZ/xyY

x = X / (X + Y + Z)
y = Y / (X + Y + Z)
Y = Y

For black, X=Y=Z=0, set x and y to the chromaticity coordinates of the reference white.

ACES

Academy Color Encoding System ACES is a color image encoding system created by industry professionals of Academy of Motion Picture Arts and Sciences.

ACES Pipeline

ACES has several color spaces, defined by:

ACES Color Spaces

ACES working color spaces are:

Color Model

A color model is a method to represent colors, typically as tuples of three or four values or components. An image can be represented in memory (with a stride) component-wise or planar-wise.

[X1Y1Z1...XnYnZn]
[X1...Xn] [Y1...Yn] [Z1...Zn]
[X1...Xn] [Y1Z1...YnZn]
[X1Y1X2Z1 X3Y2X4Z2...Xn-1YmXnZm]

RGB

RGB is an additive color model with a separation of red, green and blue additive primary colors.

Additive Color Mixing

When the red, green and blue components have the same range of values the geometric representation has the shape of a cube otherwise it has the shape of a rectangular prism or cuboid.

RGB Color Range

There are multitude RGB pixel formats, the most common formats are:

RGB888/RGB555

short pixel = ((R >> 3) << 11) | ((G >> 2) << 5) | (B >> 3)

CMY

CMY is a subtractive color model with a separation of cyan, magenta and yellow subtractive primary colors.

Subtractive Color Mixing

HSL/HSV

HSL is a color model with hue, saturation and level components.

HSL Color Range

HSV is a color model with hue, saturation and value components (also known as HSB, hue, saturation and brightness).

HSV Color Range

Both color ranges shapes are cylindrical.

YUV

YUV is a color model with luma and chrominance components. Sometimes YUV is also named YCrCb, where Cr is the red projection plane and Cb is the blue projection plane. It was invented when engineers wanted color television in a black-and-white infrastructure.

There are several YUV pixel formats, the recommended formats for video rendering are:

RGB/YUV

Y =  (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128
V =  (0.439 * R) - (0.368 * G) - (0.071 * B) + 128

YUV/RGB

R = 1.164(Y - 16)                  + 1.596(V - 128)
G = 1.164(Y - 16) - 0.391(U - 128) - 0.813(V - 128)
B = 1.164(Y - 16) + 2.018(U - 128)

Blend Modes

Blend modes are used to determine how two color layers are blended with each other.

Blend Modes

Normal
Mixes two layers by applying alpha blending.

α0 = αa + αb(1 - αa)
C0 = (Caαa + Cbαb(1 - αa)) / α0

Dissolve
Mixes two layer by taking random pixels from both layers using a diffusion dither pattern based on alpha.
No anti-aliasing is used so the result looks grainy.

Multiply
Mixes two layers by multiplying the values.
Since color values are in the range [0,1], the result will be less than each initial value.
Multiplying a color by black produces black. Multiplying a color by white produces the same color.
If a layer contains homogeneous value, multiply is equivalent to using normal with the value as opacity and a black bottom layer.

C0 = CaCb

Screen
Mixes two layers by inverting, multiplying and inverting again the values.
Screen is the opposite of multiply.
If a layer contains a homogeneous value, screen is equivalent to using normal with the value as opacity and a white top layer.

C0 = 1 - (1 - Ca)(1 - Cb)

Overlay
Combines multiply and screen.
If the base layer is light the result is lighter. If the base layer is dark the result is darker.
An overlay with the same picture looks like an S-curve.

       2CaCb                  if a < 0.5
C0 =
       1 - 2(1 - Ca)(1 - Cb)  otherwise

References