What is the Matrix? (An answer.)

glenn chan

Well-known member
In another thread, someone asked:

Noob question, what is a color matrix anyway? (in this particular context)

My answer:
A matrix is a math construct for representing an array/bunch of numbers. In this case, it's a way of representing a set of algebra equations.
The input is the raw info from the camera.
The matrix adds some color adjustments, so that the colors are 'better'.

Output R = something * R + something * G + something * B
Output G = something * R + something * G + something * B
Output B = something * R + something * G + something * B

All the 'somethings' are numbers that can be represented by a matrix. Mathematicians and engineers represent numbers in a matrix since matrices are easier to work with. They put the equations into an easier form to work with.

Ok.

The next step is to figure out what you want to numbers to be. Video systems are designed around the simplification that we see three colors. The light entering our eyes actually consist of a spectrum of many wavelengths... an ideal system would break up the spectrum into 25+ slices/bands of the spectrum. But that would be overengineered! So we simplify things into three colors- our eyes only have three types of cones which detect color.

Each of the types of cones have a specific response to each wavelength, stronger for some wavelengths than others. This is spectral response, and can be plotted on a graph. An ideal camera would have a spectral response that corresponds to the cones. The spectral response would correspond to the CIE color matching functions. The CIE CMFs are derived from measuring the spectral response of standard observers. XYZ color space is just a color space you can do the calculations in. See
http://hyperphysics.phy-astr.gsu.edu/hbase/vision/cieprim.html#c2
for a diagram of the CIE CMFs.

For practical reasons, the RED camera probably doesn't have a spectral response that looks like the CIE CMFs. One of the purposes of the color matrix is to 'fudge' the spectral response so that it's closer to the CIE CMFs. In multi-camera situations, the color matrix is typically used to fudge all the camera's colors so their spectral responses are more similar.

Ok not quite. :D We also need to consider the display device. The light emitted from a monitor has a particular spectral power distribution. This is just the flipside of spectral response of our vision. Spectral power distribution (SPD) is the intensities of wavelengths emitted across the visible spectrum. Since monitors will vary widely in their SPD, we can simplify things to the particular chromaticities (color) of red, green, and blue. Then, we standardize what red, green, and blue are (in chromaticity co-ordinates).

Over time, the standard colors have changed or they are different depending on the TV system. The standards sets of chromaticities are:
NTSC (obsolete; these are the original chromaticities when the NTSC standard was first defined.)
SMPTE C (used in NTSC land)
EBU (used in PAL land, and for Japanese NTSC)
Rec. 709

For HD formats, Rec. 709 chromaticities are the standard.

And here's where the matrix comes into play again.

The camera (effectively) has a color response that corresponds to the CIE CMFs. However, the monitor produces a color response (in the viewer) that corresponds to particular chromaticities. The two are in reference to different things. The CIE CMFs can be thought of as a different color/chromaticity than Rec. 709 red, green, and blue.
The CIE CMFs are theoretical 'colors' that cover the entire range of human vision... while the Rec. 709 are colors that practical monitors can be produce. Practical monitors cannot produce all the colors that we can see (i.e. they cannot reproduce the extremely saturated colors of lasers).

The color matrix is used again, this time to convert from the CIE CMFs into Rec. 709 colors.

To recap, the color matrix is used for two purposes:
A- To fudge the camera's spectral response to be closer to the CIE CMFs.
B- To convert from the CIE CMFs into Rec. 709 colors.

These tasks can be done in two matrices, although you should multiply the two matrices together into one so there's less processing.

Ok. And now for some finer points:

A- One limitation of the color matrix is that they can only fudge the camera's spectral response to be closer to the CIE CMFs. This is a source of metamerism. And basically, metamerism is the major source of color inaccuracies.
Maybe see http://en.wikipedia.org/wiki/Metamerism_(color) for an explanation of metamerism.

Color inaccuracy sounds like a bad thing, but our vision puts up with a lot of color inaccuracy in the real world anyways so this is not something we notice that much. The real world is color inaccurate! (Due to other forms of metamerism.)

B- Implementation-wise, there may be subtle differences in how the color matrix is implemented. In a bad implementation, gamma correction will be applied before the color matrix operations. This is bad, since the calculations should be done *before* gamma correction (this is also called "linear light processing"). The underlying phenomena occur in the linear light domain. Red will likely implement the color matrix in the correct order of operations (I've spoken with Graeme about this). I'm not sure if there are any cameras that do things with the incorrect order of operations (I just haven't done the testing).

C- The color matrix can be adjusted to affect saturation and to apply rudimentary secondary color correction.

I hope that made sense!
And hopefully there are no inaccuracies here, although the devil is in the details. I'm sure Graeme will chip in if there is anything wrong.
 
glenn chan said:
XYZ color space is just a color space you can do the calculations in. See
http://hyperphysics.phy-astr.gsu.edu/hbase/vision/cieprim.html#c2
for a diagram of the CIE CMFs. ...

The standards sets of chromaticities are:
NTSC (obsolete; these are the original chromaticities when the NTSC standard was first defined.)
SMPTE C (used in NTSC land)
EBU (used in PAL land, and for Japanese NTSC)
Rec. 709 ...

Wow... very nice summary and explanation, Glenn!

Two things:

1) Another great website if you want to get into deep color-geek land -- www.brucelindbloom.com. This has been one of my favorite reference sites for years. Go to "Calc" and click "Learn More" on any of the calculators. After all - Bruce is a scientist, not a web designer. :)

2) Another chromaticity that is increasingly important is P3 - the nominal color space for DCI.
 
Hi Lucas,
Thanks for the link to Bruce's site. I've seen it before, although didn't realize there were the "learn more" pages.

The following book is a good source for engineering information, if anyone here wants to know the really nitty gritty technical details on how all this stuff works:
http://poynton.com/DVAI/index.html
 
glenn chan said:
Hi Lucas,
Thanks for the link to Bruce's site. I've seen it before, although didn't realize there were the "learn more" pages.

The following book is a good source for engineering information, if anyone here wants to know the really nitty gritty technical details on how all this stuff works:
http://poynton.com/DVAI/index.html

I consider myself to be pretty savvy when it comes to understanding the finer points of digital video but I tried to read that book and its very hardcore. If your not an engineer, most chapters will be over your head. That said, there certainly is a ton of great info in there!
 
A minor note: The name "color matrix" implies that the transfer function is linear. But I have the suspicion that your color curves are, well, curved, so it is perhaps more of a "color function". Also, I suspect that the value might depend on a neighborhood of pixels and not just a single pixel as in the example.
 
Yes, the Poynton book is fairly hardcore... but it's a nice reference. You're probably better off Googling a subject first, and then reading the book (since the book is pretty accurate, whereas the Internet usually isn't).

A minor note: The name "color matrix" implies that the transfer function is linear. But I have the suspicion that your color curves are, well, curved, so it is perhaps more of a "color function".
What color curves are you talking about? There are graphs with curves in them, but those are graphs of spectral response or whatever. The color matrix can affect those graphs by adding/removing parts of any of the channels.

Also, I suspect that the value might depend on a neighborhood of pixels and not just a single pixel as in the example.
Are you saying that because Red is a Bayer pattern, that the color matrix would operate on different pixels / sensor elements?
 
Back
Top