Fundamentals of data representation - AQARepresenting images

All data is represented as binary digits, whether it is numbers, text, images or sound. Calculations are also made in binary.

Part ofComputer ScienceComputational thinking and problem solving

Representing images

Computers work in . All must be converted into binary in order for a computer to process it. Images are no exception.

How computers process and represent images

How images are displayed using pixels

Image quality is affected by the of the image.

Image resolution is the number of pixels in a specific area of an image. It is expressed as dots per inch (dpi), or pixels per inch (ppi), eg:

  • 72dpi = 72 dots per inch
  • 200 ppi = 200 pixels per inch

In a low-resolution image, the pixels are larger and therefore, fewer are needed to fill the space. This results in images that look blocky or pixelated. An image with a high resolution has more pixels, so it looks a lot better when it is enlarged or stretched. The higher the resolution of an image, the larger its file size will be.

A computer screen showing a high resolution image and low resolution image side by side
Figure caption,
The image on the left has a higher resolution as it has more pixels

Factors affecting image file size

The file size of a bitmap image is calculated using the number of pixels in the image, and its colour depth. The formula is:

Width × Height × Colour depth

To work out the file size in bytes instead of bits, simply divide by 8.

Example 1:

An image has pixels in a grid that is 3 columns wide and 4 rows high. The colour depth is 2 bits:

W(3) × H(4) × CD(2) = 24 bits, or 3 bytes.

Example 2:

An image has pixels in a gride that is 4 columns wide and 8 rows high. The colour depth is 3 bits:

W(4) × H(8) × CD(3) = 96 bits, or 12 bytes.

Metadata

Files contain extra data called . Metadata includes data about the file itself, such as:

  • file type
  • date created
  • author

An image file also includes metadata about the image data itself, such as:

  • the height and width of the image - this defines how many rows and columns the pixels are to be arranged in
  • the resolution
  • the colour depth

Without this metadata, the image data would not be correctly interpreted, meaning the image could not be correctly displayed.

One type of digital image is a bitmapped image. These are made up of , a small square of solid colour. In many images, the pixels are too small for the human eye to see, so the colours appear to merge together.

Consider a simple black and white image. If black is represented as 0, and white as 1, then a simple black and white picture can be created using binary.

To create the picture, a grid can be set out and the squares, known as pixels, coloured (0 - black and 1 - white):

A black and white image created using binary

Colour depth

Many images need to use colours. To add colour, more are required for each pixel. The number of bits determines the range of colours. This is known as an image's .

For example, using a colour depth of two, ie two bits per pixel, would allow four possible colours, such as:

  • 00 - black
  • 01 - dark grey
  • 10 - light grey
  • 11 - white
An image containing four colours created using binary

Each extra bit doubles the range of colours that are available:

  • one bit per pixel (0 or 1) - two possible colours
  • two bits per pixel (00 to 11) - four possible colours
  • three bits per pixel (000 to 111) - eight possible colours
  • four bits per pixel (0000 to 1111) - 16 possible colours
  • 16 bits per pixel (0000 0000 0000 0000 to 1111 1111 1111 1111) - over 65,000 possible colours

The more colours an image requires, the more bits per pixel are needed. Therefore, the more the colour depth, the larger the image file will be.