Color Matrix

Consider the following matrix. This matrix is used as a transformation matrix, or color matrix, since this is used to change the colors of the given image.

[ a, b, c, d, e,
  f, g, h, i, j,
  k, l, m, n, o,
  p, q, r, s, t ]

If RGBA are the values of a pixel for a given image, then the resulting pixel R’G’B’A’ is given by the following formula.

R' = a*R + b*G + c*B + d*A + e;
G' = f*R + g*G + h*B + i*A + j;
B' = k*R + l*G + m*B + n*A + o;
A' = p*R + q*G + r*B + s*A + t;

In terms of matrix multiplication, the relation is given by

Please note that we provide the color matrix as a one dimensional matrix. In the above picture, we have given a 2D matrix only for understanding the transformation.

Uses of Color Matrix

Color matrix can be used to apply a filter, or transform, a given image.

For example, some of the operations that we can do on an image using color matrix are

  • Invert colors of an image
  • Display only red color channel of an image
  • Adjust brightness of an image
  • Adjust contrast of an image

Tutorials using Color Matrix

The following tutorials cover some of the scenarios where we use a color matrix to transform a given image.