Light and colour

Martin McBride, 2021-04-25
Tags colour rgb light
Categories computer science colour

In this section we will look at light and colour, and how our eyes perceive colour. It is useful to have some understanding of this, because it affects the way computers represent colour.

Visible light

Light is a form of electromagnetic radiation. Electromagnetic radiation exists on a spectrum, and takes different forms depending on the wavelength.

This diagram shows some well known types of electromagnetic radiation, listed in order of decreasing wavelength:

Visible light occupies a very small range of the spectrum, between infrared and ultraviolet, with wavelengths between about 400nm and 700nm. nm stands for nanometre, and 1nm is equal a millionth of a millimetre.

Colours of the spectrum

A rainbow is created when sunlight diffracts through droplets of rain, splitting it into its separate component colours:

Each colour is created by light of a particular wavelength. Light with a wavelength of 700nm appears red, light with a wavelength of 610nm appears orange, and so on.

You might be more familiar with the rainbow colours being red, orange, yellow, green, blue, indigo, violet, originally listed by Newton. It is believed that "blue" might have meant a colour that was closer to cyan, and he used "indigo" to described a deeper blue.

In fact, there are far more than 7 colours in the spectrum, so dividing the spectrum into 6, or 7, or even 12 colours is quite arbitrary.

If we look at the spectrum more closely, we see the colour varies continuously, so for example there are many shades between red and orange:

The number of different shades in the spectrum is essentially infinite.

None spectral colours

The spectrum only contains colours created by light of a single wavelength. But in fact, most light we see is a mixture of lots of different wavelengths. Our eye still interprets that light as being a particular colour. These colours aren't part of the rainbow spectrum. Here are a few examples (there are millions of them):

For each of these colours, there is no single wavelength of light that would appear to be that exact colour. These colours can only occur when several different wavelengths, with different intensities, are mixed together. But we still see them as a single colour.

How we see colour

If you think about the infinite number of colours in the spectrum, and then think about the number of ways you could mix every combination of those colours in different amounts, it might seem like an impossible problem to replicate that on a computer screen.

Fortunately the way we perceive colour a little simpler than that.

The human eye contains three types of colour detecting cells, called cones, that measure the intensity of light across different, broad parts of the spectrum:

  • L-cones detect light towards the yellow/orange/red end of the spectrum.
  • M-cones detect light in mid-range green/yellow area of the spectrum.
  • S-cones detect light at the blue/violet end of the spectrum.

Each type of cone measures the average amount of light in the part of the spectrum it can detect. These detection bands overlap, and by measuring the relative amount of light in each of these bands, our brain can recreate every colour that we see.

The important fact here is that colour as humans perceive it is a 3-dimensional quantity - the amount of light detected by the three types of cones. These cones do not exactly correspond to red, green and blue, however if we mix different amounts of red, green and blue light we can simulate many of colours we see.

The eye also contains a second type of cell, called rod cells. Rods sense light and dark, but they don't see colour. They are more sensitive than cones, so they provide your ability to see in dark conditions (that is why you don't see colours when it is dark). The eye contains more rods than cones, so they can detect finer detail than cones. Some image compression schemes take account of this to improve the perceived quality of the final image.

If you found this article useful, you might be interested in the book Computer Graphics in Python or other books by the same author.


Popular tags

2d arrays abstract data type alignment and angle animation arc array arrays bar chart bar style behavioural pattern bezier curve built-in function callable object chain circle classes clipping close closure cmyk colour combinations comparison operator comprehension context context manager conversion count creational pattern data science data types decorator design pattern device space dictionary drawing duck typing efficiency ellipse else encryption enumerate fill filter font font style for loop function function composition function plot functools game development generativepy tutorial generator geometry gif global variable gradient greyscale higher order function hsl html image image processing imagesurface immutable object in operator index inner function input installing iter iterable iterator itertools join l system lambda function len lerp line line plot line style linear gradient linspace list list comprehension logical operator lru_cache magic method mandelbrot mandelbrot set map marker style matplotlib monad mutability named parameter numeric python numpy object open operator optimisation optional parameter or pandas partial application path pattern permutations pie chart polygon positional parameter print pure function python standard library radial gradient range recipes rectangle recursion reduce regular polygon repeat rgb rotation roundrect scaling scatter plot scipy sector segment sequence setup shape singleton slice slicing sound spirograph sprite square str stream string stroke structural pattern subpath symmetric encryption template text text metrics tinkerbell fractal transform translation transparency triangle truthy value tuple turtle unpacking user space vectorisation webserver website while loop zip