Skip main navigation

Colour spaces

A description of commonly used colour space and their applications

In this article we will introduce the idea of colour spaces, a way of visualising and defining a range of colours. This will start with the RGB colour definitions we’ve seen already, then look at how RGB colour may be converted to grayscale, before concluding by introducing another common type colour space, HSV and HSL colour.

RGB Colour Space

As we have already seen each pixel in a colour image consists of three numbers, between 0 and 255 (for 8-bit resolution), corresponding to the level of red, green and blue for that pixel. This means that any pixel can take 256 x 256 x 256 = 16,777,216 different unique colour values. This is known more generally as the RGB colour space. If you visualise this by thinking of the RGB values as co-ordinates in 3D space then the set of colours in RGB colour space can be thought of as a cube.

Each corner, or vertex of this cube represents one of the ‘pure’ colours produced when all or some of the three channels (red, green and blue) are at maximum (255) or minimum (0) intensity. In particular, the vertices at (255,0,0), (0,255,0) and (0,0,255) represent pure red, green and blue respectively. The vertices at (0,255,255), (255,0,255) and (255,255,0) are the colours produced by mixing two of the channels at full intensity, so cyan, magenta and yellow. Finally the vertices at (0,0,0) and (255,255,255) are black and white respectively. The faces of the cube, and all the points within the cube represent all the possible different colours produced by combining the three colour channels.

Grayscale

In grayscale images, rather than three numbers as in RGB colour, there is just one number, which represents only the intensity of light, giving no colour information. In RGB colour space, grayscale values are represented by the points where all three channels have exactly the same value. Going back to the cube visualisation, you can think of this as a straight line passing through the centre of the cube from black (0,0,0) to white (255,255,255). All the millions of other possible colours are points surrounding this line. How then are RGB colour images converted to grayscale? You’ve possibly done this already on this course using Fiji by setting the image type to 8-bit. Depending on the settings in Fiji however this can be done one of two ways. If you look in Edit -> Options -> Conversions you should see a menu like that below (at time of writing).
If ‘Weighted RGB conversions’ is left unchecked (as should be the default) then every pixel in the grayscale image just takes the average value of the three colour channels, i.e. Grey = (R+G+B)/3. Unless you have good reason to suggest otherwise this is probably the best conversion to use in most cases for scientific analysis as it avoids giving any particular weighting to any one channel. However, if the ‘Weighted RGB conversions’ is checked the calculation is Grey = 0.229 x R + 0.587 x G + 0.114 x B, so that most weight is given to intensity in the green channel, then red , with data from the blue channel given least weight. This mimics the sensitivity of the respective cones in the human eye and so converting from RGB to grayscale in this way helps preserve our perception of the relative brightness of the pixels in the image.
This technique is generally used when the aesthetic appearance of the converted image or images is important rather than use in scientific analysis. For example, colour to black and white digital photography or conversion of colour video to black and white will use one of several different slightly differing RGB weightings depending on the application.

HSV/HSL Colour Space

While RGB colour space is generally used to define digital images and by video display equipment, other colour spaces are also widely used to numerically define precise colours. One such alternative set of systems are the Hue, Saturation and Value (HSV) (sometimes known as HSB for Hue, Saturation and Brightness) and the Hue, Saturation and Lightness (HSL) systems. These systems are commonly used in design or artistic applications where a more intuitive method for selecting exact shades of colour is desirable (e.g. in photo editing software such as Photoshop). Though the RGB colour more closely matches the way humans actually detect colour, since it is based on mixing of colours it can be difficult to see exactly where in the RGB colour space a particular shade or colour lies. HSV/HSL colour was designed to make navigation of the colour space, and colour selection more intuitive. Rather than a cube with the amount of red, green and blue as the axes, the HSV/HSL colour space is defined as a circular cylinder with the hue as the angle around the cylinder (with red being 0°, green 120° and blue 240°) , the saturation the distance from the centre line of the cylinder and the value or lightness the height of the point from the base of the cylinder.

Hue can be thought of as the main colour property. As you look around the top of the colour wheel in the figure you will be able to see all the colours you can name such as red, orange, yellow, green, cyan, blue and magenta. Saturation can be thought of as the depth of colour, or how little grey there is in the colour (high saturation has strong colour, low values appear almost completely grey or washed out). Finally lightness/luminance (in HSL), or ‘value’ (in HSV) is a measure of the brightness of the colour, with low values appearing black and higher values appearing whiter. The difference between the HSV and HSL systems is that the HSL scale goes all the way to pure white, while HSV stops halfway along this scale.

Summary

  • Colour spaces are methods of precisely and numerically defining specific colours
  • The colour space used in digital images and in most image analysis is RGB colour, based on the intensity of red, green and blue light
  • The RGB colour space can be visualised as a cube in 3D space with the level of red, green and blue as the axes
  • Grayscale is purely a measure of brightness with no colour information.
  • Different methods or weighting are in use for the conversion of RGB colour data to grayscale depending on the application
  • HSV/HSL is an alternative colour space for creative applications using hue, saturation and lightness/brightness to define colour rather than red, green and blue
This article is from the free online

Introduction to Image Analysis for Plant Phenotyping

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now