Skip to content

Instantly share code, notes, and snippets.

@TyrealGray
Last active September 13, 2018 15:55
Show Gist options
  • Save TyrealGray/6d8cfd4d4052f314ac9725779c11be12 to your computer and use it in GitHub Desktop.
Save TyrealGray/6d8cfd4d4052f314ac9725779c11be12 to your computer and use it in GitHub Desktop.
How color matrix works

Normally a color matrix is a 5x5 matrix. Here are 5x5 color matrix as a example:

Brightness Matrix    Contrast Matrix  
 
     R G B A W           R G B A W    
 
 R  [1 0 0 0 b]      R  [c 0 0 0 t]   
 G  [0 1 0 0 b]      G  [0 c 0 0 t]   
 B  [0 0 1 0 b]      B  [0 0 c 0 t]   
 A  [0 0 0 1 0]      A  [0 0 0 1 0]   
 W  [0 0 0 0 1]      W  [0 0 0 0 1] 
 
 b = brightness      c = contrast
                     t = (1.0 - c) / 2.0

This is the formula when color matrix transforms a RGBA color vector: colormatrix

The last color vector W [0 0 0 0 1] does not matter, so it could be ignored in the formula.

@TyrealGray
Copy link
Author

colormatrix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment