Question

This is a color matrix in ARGB:

[

R,0,0,0,0,

0,G,0,0,0,

0,0,B,0,0,

0,0,0,A,0,

0,0,0,0,1

]

And I know its hue color matrix below: ( refers to gskinner's source code: http://gskinner.com/blog/archives/2007/12/colormatrix_cla.html )

define lr=0.213
define lg=0.715
define lb=0.072
define a=0.143
define b=0.140
define c=-0.283
define hueangle
define cos=cos(hueangle)
define sin=sin(hueangle)

[

lr+cos*(1-lr)+sin*(-lr),lg+cos*(-lg) +sin*(-lg),lb+cos(-lb) +sin*(1-lb),0,0,

lr+cos*(-lr)+ sin*(a),lg+cos*(1-lg)+sin*(b),lb+cos(-lb) +sin*(c),0,0,

lr+cos*(-lr)+ sin*(-(1-lr)),lg+cos*(-lg) +sin*(lg) ,lb+cos(1-lb)+sin*(lb),0,0,

0,0,0,1,0,

0,0,0,0,1

]

(Thanks son_of_fire for pointing out the inexplicitness of the questions in the last edition.)

Question

  • What formulas led to this hue matrix especially the numbers a,b and c in it?
Was it helpful?

Solution

lr, lg, and lb are the luminance constants. If you compute the dot product of <R, G, B> with <lr, lg, lb> you'll get the luminance of the color. This is useful if you want to change the hue and/or saturation without changing the luminance of the color.

I don't recognize a, b, and c off the top of my head. They're probably chrominance (saturation)-related.

The hueangle is the angle you want to rotate your color. It rotates around the R=G=B axis. If you rotate 180° red becomes cyan, green becomes magenta, yellow becomes blue, etc.

You might find the Gamma FAQ useful, as it describes a lot of these concepts. And this page describes the math behind rotating around an arbitrary axis.

Also, you generally want a 4x4 matrix for color conversion, not 5x5.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top