Reputation: 9672
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.
Upvotes: 4
Views: 1083
Reputation: 366
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.
Upvotes: 3
Reputation: 20640
I believe you change all three color values equally so...
To scale RGB colors a matrix like this is used:
float mat[4][4] = {
rscale, 0.0, 0.0, 0.0,
0.0, gscale, 0.0, 0.0,
0.0, 0.0, bscale, 0.0,
0.0, 0.0, 0.0, 1.0,
};
From: http://www.graficaobscura.com/matrix/index.html
Upvotes: 0