LESSON

Mixing Colors

Transcript

We all started mixing colors when we were very young, and we learned how to combine different colors of paint to produce colors that we wanted. For light the rules are a little bit different. If I shine a red light and a blue light, where those two lights intersect I’m going to have a sort of purply color. Where the red light intersects a green light, where the red and green lights mix, I’m going to form the color yellow. And where the green light and the blue light overlap I’m going to form a color we might call aqua. Where all three colors overlap we have white.

If we consider these red, green and blue lights as our primary light sources then by mixing them in different combinations we can form different colors. Here we’ve looked at just a few simple combinations.

Let’s look at some more sophisticated combinations of our red, green and blue primary colors.
This table shows how we can create a number of named colors from certain amounts of the red, green and blue primaries. The numbers that are represented here are our unsigned 8-bit integer numbers that we’ve encountered previously, so they range between 0 and 255. So, for instance, if we wanted to create the color called cadmium red deep, we’d need a red amount of 227. So that’s a fair amount of red, given that the maximum value is 255; only 23 of green and 13 of blue. So this is a color that’s made up dominantly of red.

Let’s have a look at another color here that’s perhaps a bit more balanced … let’s look at hot pink. It contains the maximum possible amount of red, and a fair amount of green and a fair amount of blue. So this is a palette. We can mix an arbitrary color from an arbitrary amount of red, green and blue, and frequently we’d like to give that color a human friendly name.
We can demonstrate color name lookup using the toolbox function colorname.

Let’s look up the definition of the color maroon, and here we see the amount of red, green and blue required to create the color maroon. These numbers here are what we call normalised tri-stimulus values. That is, they lie between 0 and 1. So in this case, 0.4 in the red channel means there’s 40% red, there’s only 2 % green, and perhaps 28 % blue. This function can perform the inverse function as well. For instance, if I had a color that had 0.1 of red, 0.2 of green and 0.3 of blue, it’s a fairly dark color and a bit bluish. It’s looking up and it’s telling me it’s the color called midnight blue. This function has got a database file that contains eight to nine hundred different colors.

We could also use this mechanism to create a color image, and to do that we need to pull a little bit of a trick. So I’m going to create a single pixel image. Use the MATLAB function ones. I’m going to create an image with one row and one column, and three planes. And it looks something like this. To set the pixel, I’m going to set row 1, column 1, and all planes to the color of maroon. So there it is, I’ve created a single pixel image, and if I display that now, I have my single pixel image, a big solid block of maroon.

A very common way of visualising the way we mix red, green and blue primaries is what we call the color cube. So imagine that we have a three dimensional coordinate system. Three axes: a red axis, a green axis and a blue axis.

We’re going to introduce here the color cube, and what we see here in this corner is when we have the maximum amount of red but no blue or no green, and we see, as you would expect, red. Up here, where we have the maximum amount of blue but no red or no green, we have the color blue. This corner we have maximum green, no red, no blue. We see the color green. There is a file in the toolbox that allows us to display the color cube: the function is called rgbcube. And here it is.

Now this is a three dimensional structure so we want to do a rotation with a mouse. I’m going to move up here and select the 3d rotate button, and I grab it with my mouse and I can rotate it. So it is a three dimensional coordinate system, and down here is the origin. This is where the amounts of red, green and blue are all 0. So we can see this dark corner here, that’s where there is 0 amount of red, green and blue.

On the diagonally opposite corner we can see where there is a maximum amount of red, green, and blue, and that’s the white corner. If we look at the different faces of this cube, we can see that this face here is basically looking at mixtures of red and blue. This face here is looking at mixtures of blue and green. Of course, this is just the surface of the cube. If we were able to look inside the cube we would find an infinite number of colors in there as well; colors that we can’t see from the outside.

Code

There is no code in this lesson.

We can create most colors by a suitable mixture of three primary colored light sources, typically red, green and blue. Let’s look at how color mixing works.

Professor Peter Corke

Professor of Robotic Vision at QUT and Director of the Australian Centre for Robotic Vision (ACRV). Peter is also a Fellow of the IEEE, a senior Fellow of the Higher Education Academy, and on the editorial board of several robotics research journals.

Skill level

This content assumes an understanding of high school level mathematics; for example, trigonometry, algebra, calculus, physics (optics) and experience with MATLAB command line and programming, for example workspace, variables, arrays, types, functions and classes.

More information...

Rate this lesson

Average

Check your understanding

Leave a comment