1.2.6 Images
In this lesson, you will learn how computers represent digital images using pixels and binary codes. You will explore how colour depth and resolution affect image quality and file size, understand the purpose of image metadata, and calculate the storage required for bitmap images.
Representing Images
A digital image is made up of a grid of tiny picture elements called pixels. Each pixel represents one small part of the image and is assigned a particular colour.
Because computers store data in binary, the colour of each pixel must be represented using a binary code. When all of the pixels are displayed together in the correct positions and colours, they form the complete image.
In a simple black-and-white image, one bit can be used for each pixel. For example, 0 could represent white and 1 could represent black. The computer stores the binary code for each pixel together with information about where that pixel belongs in the image.
Each row of this 8 × 8 image contains eight pixels, so if one bit is used for each pixel, each row requires eight bits (one byte) of storage. If more colours are needed, more bits must be used for each pixel so that more unique binary codes can be created. For example, 1 bit gives only two possible codes (0 and 1), while 2 bits give four possible codes (00, 01, 10 and 11).
The computer also needs additional information about the image so that the stored pixel data can be interpreted correctly. This information is stored as metadata.
Metadata
Metadata is additional information stored about an image. It is separate from the binary colour values of the pixels themselves and describes important properties of the image.
Some metadata is needed so that software can interpret and display the image correctly. For example, the image width and height tell the computer how the pixel data should be arranged, while information such as colour depth and resolution helps describe how the image is represented.
Metadata can also store descriptive or organisational information, such as the date the image was created, the camera or device used, and details about the author or copyright owner. This can help users and software organise, search for, identify and manage image files.
Metadata may therefore include:
- image width and height;
- colour depth;
- resolution;
- creation date and time;
- camera or device information;
- author or copyright information.
Colour Depth
Colour depth is the number of bits used to represent the colour of each pixel. Each additional bit increases the number of different binary codes that are available and therefore increases the number of colours that can be represented. The number of possible colours can be calculated using:
For example, using 2 bits for each pixel gives four possible binary codes: 00, 01, 10 and 11. Each code can be assigned to a different colour, so a 2-bit colour depth can represent four colours.
| Bits per Pixel | Number of Possible Colours |
|---|---|
| 1 | |
| 2 | |
| 4 | |
| 8 |
A greater colour depth allows a wider range of colours and shades to be represented, which can make an image appear more accurate and realistic.
Increasing the colour depth usually improves image quality because more colours and shades can be represented. This can produce smoother colour changes and a more accurate representation of the original image.
However, a higher colour depth also increases the amount of data required. If each pixel requires more bits, the entire image requires more storage.
Resolution
Resolution describes the level of detail in an image and is related to the number of pixels used to represent it. A digital image may be described by its pixel dimensions, such as 1920 × 1080, meaning it is 1920 pixels wide and 1080 pixels high.
Using more pixels allows finer details to be represented. A higher-resolution image can therefore appear sharper and retain more detail when enlarged, whereas an image represented using fewer pixels may appear pixelated, meaning the individual pixels become visible.
Increasing the resolution also increases file size because more pixels have to be stored. Reducing the resolution means fewer pixels are stored, reducing file size but also reducing the amount of detail available.
The Effect of Colour Depth and Resolution
Colour depth and resolution both affect image quality and file size, but they do so in different ways. Colour depth changes the number of colours available for each pixel, while resolution changes the number of pixels used to represent the image. Increasing either can improve image quality, but also increases the amount of data that must be stored.
| Change | Effect on Image Quality | Effect on File Size |
|---|---|---|
| Increase colour depth | More colours/shades can be represented, giving more accurate colour reproduction | Increases because more bits are stored for each pixel |
| Decrease colour depth | Fewer colours/shades can be represented, so colour detail may be lost | Decreases because fewer bits are stored for each pixel |
| Increase resolution | More pixels represent the image, allowing greater detail and reducing pixelation | Increases because more pixels must be stored |
| Decrease resolution | Fewer pixels represent the image, reducing detail and increasing the chance of pixelation | Decreases because fewer pixels must be stored |
There is therefore a trade-off between image quality and storage. Higher colour depth and resolution can produce a better-quality image, but they require more data to be stored. Lower values reduce storage requirements but may reduce image quality.
Calculating Image File Size
The size of the uncompressed pixel data in a bitmap image depends on the number of pixels and the colour depth. The total number of pixels is found by multiplying the image width by its height. This total is then multiplied by the number of bits used for each pixel.
Suppose an image is 800 pixels wide, 600 pixels high, and uses a 16-bit colour depth. First calculate the number of pixels:
Each pixel requires 16 bits:
Therefore, the image requires 7,680,000 bits for its pixel data. To convert this into bytes, divide by 8 (since there are 8 bits in a byte):
Then, using the 1000-based units from Lesson 1.2.3 Units:
Therefore, the uncompressed pixel data requires 960 KB.
The formula also shows directly why colour depth and image dimensions affect file size. Increasing the colour depth increases the number of bits stored for every pixel, while increasing the width or height increases the total number of pixels that must be stored.
