Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a color matrix for adjusting luminance?

Searching around there is lots of information on converting an image to luminance (B&W) or adjusting saturation w/out changing luminance. But how can you modify luminance itself? For instance, how can I increase the red channel luminance using a 5x5 matrix? Ultimately this will be used in C but the same math should work w/java or flash.

like image 560
Shizam Avatar asked Sep 07 '25 21:09

Shizam


1 Answers

For anyone who came here from google, here is the matrix to scale luminance:

rl×l + gl + bl    gl×l - gl         bl×l - bl         0
rl×l - rl         gl×l + rl + bl    bl×l - bl         0
rl×l - rl         gl×l - gl         bl×l + rl + gl    0
0                 0                 0                 1

where

  • l — luminance multiplier,
  • rl — red luminance (0.213 for sRGB),
  • gl — green luminance (0.715 for sRGB),
  • bl — blue luminance (0.072 for sRGB).

Please note: this matrix may easily produce out of gamut colors, so don’t use it when you expect accurate results. For example, for the 1, 0, 0, 1 vector and l=2 it will produce the 1.213, 0.213, 0.213, 1 result. Technically, this vector has the expected luminance (0.426), but the displayed color will be ≈0.381.

like image 146
Marina Miyaoka Avatar answered Sep 10 '25 12:09

Marina Miyaoka