Skip to main content
Home
plus.maths.org

Secondary menu

  • My list
  • About Plus
  • Sponsors
  • Subscribe
  • Contact Us
  • Log in
  • Main navigation

  • Home
  • Articles
  • Collections
  • Podcasts
  • Maths in a minute
  • Puzzles
  • Videos
  • Topics and tags
  • For

    • cat icon
      Curiosity
    • newspaper icon
      Media
    • graduation icon
      Education
    • briefcase icon
      Policy

    Popular topics and tags

    Shapes

    • Geometry
    • Vectors and matrices
    • Topology
    • Networks and graph theory
    • Fractals

    Numbers

    • Number theory
    • Arithmetic
    • Prime numbers
    • Fermat's last theorem
    • Cryptography

    Computing and information

    • Quantum computing
    • Complexity
    • Information theory
    • Artificial intelligence and machine learning
    • Algorithm

    Data and probability

    • Statistics
    • Probability and uncertainty
    • Randomness

    Abstract structures

    • Symmetry
    • Algebra and group theory
    • Vectors and matrices

    Physics

    • Fluid dynamics
    • Quantum physics
    • General relativity, gravity and black holes
    • Entropy and thermodynamics
    • String theory and quantum gravity

    Arts, humanities and sport

    • History and philosophy of mathematics
    • Art and Music
    • Language
    • Sport

    Logic, proof and strategy

    • Logic
    • Proof
    • Game theory

    Calculus and analysis

    • Differential equations
    • Calculus

    Towards applications

    • Mathematical modelling
    • Dynamical systems and Chaos

    Applications

    • Medicine and health
    • Epidemiology
    • Biology
    • Economics and finance
    • Engineering and architecture
    • Weather forecasting
    • Climate change

    Understanding of mathematics

    • Public understanding of mathematics
    • Education

    Get your maths quickly

    • Maths in a minute

    Main menu

  • Home
  • Articles
  • Collections
  • Podcasts
  • Maths in a minute
  • Puzzles
  • Videos
  • Topics and tags
  • Audiences

    • cat icon
      Curiosity
    • newspaper icon
      Media
    • graduation icon
      Education
    • briefcase icon
      Policy

    Secondary menu

  • My list
  • About Plus
  • Sponsors
  • Subscribe
  • Contact Us
  • Log in
  • Colouring by numbers

    by
    Josefi…na Alvarez and Claudia Gómez
    27 June, 2011
    Rainbow

    The concept of colour can be approached from many angles, including mathematics. Image: Wingchi Poon.

    How does a computer understand the colours to be displayed on the monitor's screen? As we will see, for a computer to understand colours, they must be turned into numbers written in a special way. So, before we can talk about colour, our first task will be to review a few things about numbers.

    Writing numbers in special ways

    The meaning of the symbol 222 is in the words we use to name it: two hundred, twenty (or two tens) and two. These words tell us that 222 means $2 \times 100+2 \times 10+2$ or $2 \times 10^2+2 \times 10^1+ 2\times 10^0.$ That is, 222 is written in a special way using what we call the decimal system, which has base 10 and the digits 0, 1, 2, 3, ..., 9. Our base ten system is a positional system, meaning that the value of a particular building block depends on the power of 10 that goes with it. In our example 222, we see that the symbol 2 repeats three times, with a different value in each occurrence. As familiar as this setting feels to us, there is really nothing special about it. We could reproduce the same process with a different base and appropriate digits. For instance, if we agree to work with base, say, 4 and digits 0, 1, 2, 3 the symbol 222 will now mean $$2 \times 4^2 + 2\times 4^1 + 2 \times 4^0.$$ Performing this calculation, we end up with the base ten number 42. So $$222_4=42_{10},$$ with the subscripts indicating the base. We could also find out what number in base 4 is equal to $222_{10}.$ In fact, $$222_{10} = 3 \times 4^3 + 4^2 + 3 \times 4^1 + 2 \times 4^0 = 3132_4.$$

    Many interesting questions can be explored in any given base: How do we recognise an even number? An odd number? What are the addition and multiplication tables? And so on. But we should not dwell too much on this number preamble, because our purpose, remember, is not to play with different number systems. Our purpose today is to look at colour as a computer understands it.

    What is colour?

    Etymologically, colour is akin to the Latin word celare, which means to conceal. As for its meaning, we say that "her story has the colour of truth", or that "colour is the daily bread of the eyes", we remark on "the colour of the cello" or we state that "a surprising number of animals can change colour to match their surroundings". In each of these sentences, the word colour has a different meaning. In fact, a dictionary will list no less than ten meanings of the word colour.

    For our purposes, colour will be what the dictionary defines as "a visual perception that enables us to differentiate otherwise identical objects". We could approach this concept of colour from several disciplines: physiology, psychology, philosophy, physics, chemistry, art and, yes, mathematics.

    How can we describe colour?

    Starry night

    Van Gogh's famous painting Starry night.

    Artists refer to colour using three attributes, hue, saturation (or intensity) and luminosity (or value). Hue answers questions such as "Is it red?". Saturation describes a colour as bright or dull, while luminosity points to whether it is light or dark.

    Colour is a very subjective perception. What is green or yellow or blue or purple very much depends on the observer. Even if two people looking at a wall agree that it is white, still neither one of them will ever know whether both see the same thing. And the red of Georgia O'Keffee's poppies or the blue of Van Gogh's Starry night speak to us also of the artist's emotional meaning. However, if colours are to be displayed on a computer monitor for instance, they have to be understood by a device far removed from any subjective sense of emotion, a device that is able to process data only by means of very specific commands. So, how does a computer deal with the colours we see on the monitor's screen?

    The RGB system

    There is more than one system that computers can use to describe colour, but the most popular one might be the RGB system. We can see it at work when selecting the appearance of the display in the control panel of a PC:

    Colour picker dialogue

    Figure 1: A colour dialogue box.

    The name RGB stands for Red, Green, Blue, meaning that this system produces a colour as a mixture of three colours: red, green and blue. The numbers from 0 to 255 are used to indicate how much of each of these three colours is in the mixture. For instance, 255 0 0 is pure red, while 0 255 0 is pure green and 0 0 255 is pure blue. You might not think of them as the most typical red, green or blue, but here they are:

    Red, green and blue

    Figure 2: Pure red, green and blue.

    From black, 0 0 0, to white, 255 255 255, the RGB system allows for 256 × 256 × 256 = 16,777,216 colours. This number is plenty, considering that the human eye can recognise about ten million different colours. Nature is capable of displaying many more colours.

    One thing to notice is that the computer not only gives us the colours in the RGB system, but it also produces a numerical correspondence between the quantities of red, green and blue, and the artist's attributes of hue, saturation and luminosity. To avoid the complication of putting these three attributes in a three dimensional display, the computer breaks them down into a plane for the hue and the saturation (the coloured square in figure 1) and a line for the luminosity (the vertical strip in figure 1).

    Orange

    Figure 3: The colour 210 70 4.

    Are we there yet? Not quite. The RGB system is just the beginning of how a computer deals with colour, because at the most basic level, the only commands a computer understands are the turning on and the turning off of an electric current. Ultimately, every piece of data and every instruction that is entered in a computer has to be written as a combination of these ON/OFF basic commands. A natural numerical model that represents these commands is $ ON \rightarrow 1,$ $OFF \rightarrow 0.$ That is to say, for computer consumption a colour such as 210 70 4 (shown in figure 3) must be given as a combination of ones and zeros. In other words, the numbers 210, 70 and 4 have to be written in the binary system (or in base 2): \begin{eqnarray}210 & = & 2^7 + 2^6 + 2^4 +2 = 11010010_2 \nonumber \\ 70 & = & 2^6+2^2 +2 = 1000110_2 \nonumber \\ 4 & = & 2^2 = 100_2. \nonumber \end{eqnarray} So, our rusty orange is ultimately the following sequence of ON/OFF commands: \begin{array}{cccccccc}ON & ON& OFF& ON& OFF& OFF& ON &OFF \\ ON & OFF& OFF& OFF& ON& ON& OFF& & \\ ON & OFF& OFF& & & & & & \end{array} You might have wondered why the RGB system uses the scale 0 to 255. Here is why: Observe that \begin{eqnarray} 255 &=& 2^7+2^6+2^5+2^4+2^3+2^2+2+1 \\ & = & 11111111_2.\end{eqnarray} This means that if we start with the necessary number of zeros, every number from 0 to 255 can be represented in the binary system by a string of eight zeros and ones. For instance, $$0=00000000_2$$ and $$1=00000001_2.$$ So, we write $$210 \;\;\; 70 \;\;\; 4=11010010\;\;\; 01000110\;\;\; 00000100.$$ Each one or zero is called a bit and each group of eight bits is called a byte. In computer science, a byte is a unit frequently used to give the size of data. This explains why the RGB system chooses the scale from 0 to 255 to represent each of red, green and blue: every colour in this system can be given as three bytes.

    A huge topic that we will not touch is the chemical mechanisms by which the colours actually appear on the monitor's screen.

    Now we can see that a computer, indeed, colour by numbers. Binary numbers, that is.

    A bit more

    Although we have answered the question we set to consider, two interesting points have crept up along our discussion: the meaning of number and the objectivity of a computer.

    Orange

    Figure 4: Paper clips.

    We have seen that $222_{10}$ and $3132_4$ are the same thing and we could check that this thing is also $11011110_2$. So, when we speak of a number, perhaps what we really mean is the collection of all its representations, which, by the way, do not need to be numerical, as proved by the 222 paper clips on the left.

    Of course, our familiarity with the decimal representation makes it, undoubtedly, the preferred one. But the question still remains: What is this abstraction that we call number?

    Once we think of numbers in terms of representations, another issue pops up: properties such as being even or being odd should be independent of the representation. This is indeed the case, as there are ways of recognising even numbers and odd numbers in any given base. For instance, in base ten, even numbers are those ending in 0, 2, 4, ... , 8, while odd numbers are those ending in 1, 3, 5, ... , 9. The rule is similar in base two: even numbers are those ending in 0, while odd numbers are those ending in 1. Can you formulate a rule that applies to all the bases 2, 4, 6, ... ? How about bases 3, 5, 7, ...? Of course, in any base, we can define a number to be even if it is divisible by 2.

    Going on to the objectivity of a computer, the French mathematician Émile Picard (1856-1941) had this to say about mathematics: "We must acknowledge that the complete objectivity of our science is a chimera. Created by us using our organs, mathematics is made to fit us."

    Could it be that the same can be said about the alleged objectivity of a computer?


    About the authors

    Josefina (Lolina) Alvarez

    Josefina Alvarez

    Josefina (Lolina) Alvarez was born in Spain. She earned a doctorate in mathematics from the University of Buenos Aires in Argentina, and is currently professor emeritus of mathematics at New Mexico State University in the United States. Her long time interest is to communicate mathematics to general audiences. She is on the editorial board of Matematicalia and writes the column What if...?. Lolina likes to hike, and with husband Larry and dogs Brandywine and Sofia, she has walked many kilometres along the beautiful trails of New Mexico and elsewhere.

    Claudia Gómez

    Claudia Gómez

    Claudia Gómez Wulschner was born in Mexico City. She studied mathematics at the UNAM (National University of Mexico), obtaining both her M.Sc. and Ph.D. in Mathematics at Washington State University. Since 2000 Claudia has been a full-time profesor at the Instituto Tecnológico Autónomo de México (ITAM). Claudia has had almost thirty years teaching experience. She belongs to the SNI (mexican national system of researchers). Her research articles are mainly in the area of functional analysis, but she has also written for a general audience. She has co-authored mathematics textbooks. Two for Elementary School, more than twelve for Middle and Junior School and some of them with additional material for teachers.

    • Log in or register to post comments

    Read more about...

    mathematics and art
    number system
    binary number
    RGB colours

    Our Podcast: Maths on the Move

    Our Maths on the Move podcast brings you the latest news from the world of maths, plus interviews and discussions with leading mathematicians and scientists about the maths that is changing our lives.

    Apple Podcasts
    Spotify
    Podbean

    Plus delivered to you

    Keep up to date with Plus by subscribing to our newsletter or following Plus on X or Bluesky.

    University of Cambridge logo

    Plus is part of the family of activities in the Millennium Mathematics Project.
    Copyright © 1997 - 2025. University of Cambridge. All rights reserved.

    Terms