Sat. Jan 21st, 2023

2D Image Representation – Rasters

All images displayed by a computer are ‘digital images’. There are, however, a great range of ways in which these images are created.

Any image can be defined as being either a raster image (or bitmap image), or a vector image. They are fundamentally different, and their uses are very different.

Raster Images

A raster image is one which is created using a grid of pixels (picture elements). Each of these pixels has information which encodes the colour. For example, photographs are composed of pixels.

2D Arrays

A 2-dimensional array is essentially a grid. It is a set of data which is organised using columns and rows – think x and y coordinates.


In order for a computer to make sense of the data, we need to know the dimensions of the array – remember, all digital information is simply a series of binary. Regardless of whether the data is text, a set of numeric values or an image, it is a stream of 0s and 1s.

Metadata is information about data – in the case of an image, it’s information like the size, the format and so on. The dimensions of an image relate to how many pixels wide and how many pixels tall the image is. Without this information, the image could not properly be displayed (you would have rows of the wrong length meaning they would not align correctly).

Colour modes

Colour is just colour, right?

As before, it is important to know the colour mode in order to correctly decode the information and display it. Some common colour modes are listed below :

  • Monochrome – only two colours are available. Each pixel must be one of these colours. Often, this means black and white, but it could equally mean red and black, or yellow and blue etc
  • Grayscale – a range of shades of grey are available. Each pixel must be one of these shades
  • Indexed colour – this is a compression technique that scans through each pixel of an image, and builds an index of the most common 256 colours. Each pixel of the original image is then scanned, and any that are not in the index are converted to the most similar one. This allows for smaller file sizes, as many similar colours are replaced with a single colour. Note: it is possible to create indexed images using fewer than 256 colours. Any power of 2 can be used (e.g. 16 colours)
  • RGB – each pixel is described using three numbers, which relate to the level of red, green and blue that make up the colour. Usually, this is 8 bits for each colour, meaning 24 bits or 3 bytes are required per pixel. This allows for 256*256*256 different colours to be represented, equivalent to 16.7million different shades.
  • ARGB – in addition to the levels for red, green and blue, an 8 bit alpha channel is also encoded. This allows each pixel to take one of 256 levels of transparency, although not all file formats support this. PNG is a common file format that does support this. Transparency is vital in images that do not have regular square edges. Without this, it is not possible to cleanly overlay images.
  • CMYK – high end software packages, such as InDesign or Photoshop also allow colours to be described using CMYK values. CMYK is a subtractive mixing scheme. RGB is an additive mixing scheme.

Colour modes – additive & subtractive

A computer screen is, by default, black. Colour is built up using the three primary colours, red, green and blue. On old monitors, this was created through the use of red, green and blue phosphors. On a modern screen, a white backlight shines through a filter with small red, green and blue filters in front of it, followed by a monochrome LCD. All colours can be represented by mixing red, green and blue:

In contrast, printed colour is subtractive. That is, you start with white paper, and print ink on to absorb light, rather than emit it.

In the diagram above, you can see that the three colours typically used in printers (cyan, magenta and yellow) are the three colours formed by combining two of the primary light colours. Imagine a white sheet of paper: this reflects red, green and blue light, and therefore looks white. If you print yellow onto this, you are still reflecting red and green, but absorbing blue light. If you print magenta, you are reflecting red and blue ink, but absorbing green light. If you therefore print yellow and magenta together, you will see red: one of the inks absorbs green light, and one absorbs blue light, leaving only red.

The K in CMYK stands for ‘key’ and is black. Technically, this is redundant if the three colours are ‘perfect’ as described above. However, it is more expensive to print three colours to create black when compared to straight black ink.

Due to the differences in pigments and screens, commercial printers often use CMYK instead of RGB for specifying colours.

Bit depth

As alluded to earlier, image quality can be affected by the number of bits used to describe the colour of each pixel. In general, the more bits per pixel, the greater the range of colours which can be described.


The resolution of an image can relate to two different things:

  • The dimensions of the image in pixels (width x height)
  • The number of pixels per inch (ppi) – for example, 300dpi is considered good print resolution (this means 300 pixels fit into a 1″ space on paper). Note that this is very different to dpi, a measurement used by printers, which may be 2880dpi – the dpi needs to be much higher than the ppi in order to allow the printer to mix the many shades required to accurately display a photograph or other image


This is a process similar to anti-aliasing when rendering graphics. It is a method which allows edges and details to be smoothed out when resizing images or converting from vectors to rasters.


Compression is categorised in two ways:

  • Lossless – the image is preserved exactly as created. This can lead to huge files, and is unsuitable for most uses. However, when images are being edited, or for large scale printing, the increased file size is often worthwhile. For instance, a 32MP image (average for a digital camera) at 30bpp (cameras use 10 bits for each of red, green and blue) would require 114MB. Clearly, images in excess of 100MB would not work on w website. However, compression introduces artefacts (imperfections) every time it is applied, and if you are loading and saving an image between multiple edits, you may not want this cumulative effect.
  • Lossy – common formats like JPEG are lossy. They remove detail that is considered unimportant; this could mean fewer shades of blue used in a sky, or some detail missing in a field of grass. The benefit is far smaller files. The 114MB image above could be saved in around 1MB and still have a sufficient level of detail for most purposes.

Further Reading

This website is an excellent resource, and gives a great explanation of pixels, voxels, projection, rasterisation and so much more. Read it!