Data representation - EduqasRepresentation of graphics

Binary data can represent numbers, graphics, sound and characters. It is then organised and manipulated differently. Data can also be stored in arrays, records or external files and go through validation or verification checks to ensure accuracy.

Part ofComputer ScienceUnderstanding Computer Science

Representation of graphics

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

There are two methods for storing images digitally:

Raster images

A bitmap image is a type of raster file.

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

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

A black and white image created using binary

Colour depth

Many images need to use colours. To add colour, more bits 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 - two bits per pixel - would allow four possible colours such as:

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

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

  • 1 bit per pixel (0 or 1) - 2 possible colours
  • 2 bits per pixel (00 to 11) - 4 possible colours
  • 3 bits per pixel (000 to 111) - 8 possible colours
  • 4 bits per pixel (0000 to 1111) - 16 possible colours
  • 8 bits per pixel (00000000 to 11111111) – 256 possible colours
  • 16 bits per pixel (0000000000000000 to 1111111111111111) - 65,536 possible colours

The more colours an image requires, the more bits per pixel are needed. Therefore, the more colour depth, the larger the image file will be. A colour depth of 256 colours will result in a file with one of storage for each pixel. A colour depth of 65,536 possible colours will result in a file with two bytes needed to store each pixel.

Image size

Bitmap 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 a bitmap 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

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 a bitmap image is a way of describing how tightly packed the pixels are.

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

Vector images

Vector images use calculations and shapes to create points, lines and curves that represent the images. This means they can be enlarged or shrunk without any loss of quality. Vector images use smaller file sizes than bitmap graphics but cannot be used for realistic photo quality images. They are largely used for cartoon style graphics or diagrams.

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 would not be correctly displayed.