Binary and data representation - EdexcelImages

All data in a computer is represented in binary, whether it is numbers, text, images or sound. The computer software processes the data according to its content.

Part ofComputer SciencePrinciples of computer science

Images

Computers can only recognise . 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 bitmap images are represented in binary

Consider a simple black-and-white image. If 0 is black (or on) and 1 is white (or off), then a simple black-and-white picture can be created using binary.

To create the picture, a grid can be laid out and displayed on a screen. The squares on the screen, known as , are coloured (0 - black and 1 - white). The following image is a representation of how this picture would be displayed on a screen.

A black and white image created using binary

Colour depth

Many images need to use colours. To add colour, more are required for each . 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, allows for 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) - 65,536 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.

Image size

Image size is simply the number of pixels that an image contains. It is expressed as height and width. For example:

  • 256 × 256
  • 640 × 480
  • 1024 × 764

Image file size

The size of an image file can be estimated using:

  • the image height in pixels
  • the image width in pixels
  • the colour depth per pixel

Example: an image of height 200, width 400, colour depth 16 bits

200 × 400 = 80,000 bits

80,000 × 16 = 1,280,000 bits

1,280,000 bits ÷ 8 = 160,000 bytes

160,000 ÷ 1000 = 160 kilobytes

Result: 160KB

Resolution

Image quality is affected by the of the image. The ‘resolution’ of an image is the word used to describe how tightly packed the pixels are.

The resolution of an image file is the number of pixels in an image and can be calculated using:

  • the image height in pixels
  • the image width in pixels

Example: an image of height 1536, width 2018

1536 × 2018 = 3,099,648 pixels

3,099,648 ÷ 1,000,000 = 3.1 megapixels

Result: 3.1MP

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.

A computer screen showing a high resolution image and low resolution image side by side

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, which means the image could not be correctly displayed.