Storing Images
How a picture becomes binary, what resolution and colour depth actually control, and the file size calculation with metadata included.
Bitmap images
A bitmap image is made of a grid of tiny squares called pixels, short for picture elements.
Each pixel is a single colour, and each colour is stored as a binary number. Put enough small pixels together and the eye stops seeing squares and starts seeing a photograph.
A bitmap image is stored as a grid of pixels, where the colour of each pixel is represented by a binary value.
Resolution
Resolution is the number of pixels in the image, usually written as width by height, for example 1920 x 1080.
Higher resolution means:
- More detail, because there are more pixels to describe the picture
- A larger file size, because there is more data to store
Below a certain resolution the individual squares become visible, which is why an image looks blocky or pixelated when enlarged too far.
Colour depth
Colour depth is the number of bits used to store the colour of each pixel.
| Colour depth | Number of colours | Where you see it |
|---|---|---|
| 1 bit | 2 (black and white) | Fax, simple line art |
| 4 bit | 16 | Very old graphics |
| 8 bit | 256 | GIF images, older games |
| 24 bit | 16,777,216 | Standard photographs, called true colour |
The rule is simple: n bits gives 2n colours.
24 bit colour uses 8 bits for red, 8 for green and 8 for blue, which is why colours are written as three values, and why hexadecimal colour codes like #FF8800 have six digits, two per channel.
A colour depth of 4 does not mean four colours. It means four bits, which is sixteen colours.
- A bitmap is a grid of pixels. This one is 8 by 8, so 64 of them.
- Pick one pixel. Its colour is three numbers: red, green and blue.
- Each number is 8 bits, so one pixel costs 24 bits, which is 3 bytes.
- File size = width × height × colour depth. That is the whole formula.
Metadata
Metadata is data about the data. In an image file it is the information stored alongside the pixels that tells software how to interpret and display them.
Typical image metadata includes:
- Width and height in pixels
- Colour depth
- File format
- Date and time created
- Camera make, model and settings
- Sometimes GPS location
Why metadata is essential
Without the width, the computer would have a long list of colour values and no idea how to arrange them. Is it 200 pixels wide by 300 tall, or 300 by 200? The picture would be scrambled.
Metadata is needed so the image can be displayed correctly, because the software needs the dimensions and colour depth in order to reconstruct the grid of pixels from the stored data.
Metadata also increases the file size slightly, and this appears in calculation questions.
- The picture is a grid of pixels, stored as one long stream of bits.
- Metadata that must be stored: width, height and colour depth. Without them the bits cannot be turned back into the picture.
- Extra metadata such as date, device and GPS location is useful, but sharing it can be a privacy risk.
Calculating image file size
file size (bits) = colour depth x image width x image height
Add metadata afterwards if the question gives you a value for it.
Worked example
An image is 500 pixels wide and 400 pixels high with a colour depth of 8 bits. The metadata is 1 KB. Calculate the total file size in kilobytes.
Pixel data: 8 x 500 x 400 = 1,600,000 bits 1,600,000 / 8 = 200,000 bytes 200,000 / 1000 = 200 KB Plus metadata = 200 + 1 = 201 KB
Effect of changing settings
| Change | Effect on quality | Effect on file size |
|---|---|---|
| Double the resolution | More detail | Roughly four times larger, since both width and height double |
| Halve the colour depth | Fewer available colours, possible banding | Half the size |
| Increase colour depth from 8 to 24 | Far more colours, smoother gradients | Three times larger |
If both width and height double, the number of pixels goes up by a factor of four, not two. This catches students out constantly.
File size calculator
Work out the size of an image, a sound file or a block of text, one conversion at a time. This tool needs JavaScript, so turn it on to use it. Everything you need to answer the exam question is explained in the text above.
- Image: width × height × colour depth. Every pixel costs the colour depth in bits.
- Sound: sample rate × bit depth × seconds, and × 2 for stereo.
- Text: number of characters × bits per character. ASCII uses 8.
- Divide by 8 to turn bits into bytes, then by 1,000 for each step up.
Key terms you must be able to define
- Pixel
- Picture element. The smallest single point in a bitmap image, holding one colour value.
- Bitmap
- An image stored as a grid of pixels, each with a binary colour value.
- Resolution
- The number of pixels in an image, usually given as width by height.
- Colour depth
- The number of bits used to store the colour of each pixel.
- Metadata
- Data stored with a file describing it, such as dimensions, colour depth and date created.
- Pixelated
- The blocky appearance produced when an image with too few pixels is displayed at a large size.
Flashcards
Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.
Reach the top grade on this topic
The knowledge here is straightforward. The marks come from explaining consequences precisely.
Do not say 'better quality'. Say what improves and why. Higher resolution means more pixels are used to represent the same area, so finer detail is captured and the image looks sharper when enlarged.
Always mention the cost. Every quality increase costs file size. Every file size reduction costs quality. Examiners are looking for you to state both sides.
Get the arithmetic relationship right. Doubling colour depth doubles file size. Doubling both dimensions quadruples it. Students routinely lose a mark by saying doubling resolution doubles the file.
Metadata is worth a mark on its own. Learn one clear reason it is necessary: without dimensions the software cannot rebuild the grid of pixels.
- Calculate an image file size including metadata, in the unit requested
- Explain the effect on quality and size of changing resolution or colour depth
- Give three examples of image metadata and say why one of them is essential
Mistakes that cost marks here
- Saying colour depth is the number of colours. It is the number of bits, and n bits gives 2 to the power n colours.
- Forgetting to add metadata when the question supplies it.
- Saying doubling the resolution doubles the file size, when both dimensions doubling means four times as many pixels.
- Describing resolution as 'how good the image looks'. Resolution is a count of pixels.
- Leaving the final answer in bits when the question asked for kilobytes.
The very first digital image was made in 1957 by Russell Kirsch, who scanned a photograph of his baby son at 176 by 176 pixels. He said decades later that he regretted choosing square pixels, because he had inflicted them on the whole world.
Knowledge check
Exam-style questions
Five written questions in the style of the real paper. Write a full answer, then let the marker check it against the mark scheme.
- LThe image is made up of a grid of pixels
- LEach pixel is assigned a colour, stored as a binary value
- LThe number of bits used for each pixel is the colour depth, and n bits gives 2 to the power n colours
A bitmap image is made up of a grid of very small squares called pixels. Each pixel holds a single colour, and that colour is stored as a binary number. The number of bits used to store each pixel's colour is called the colour depth, and a colour depth of n bits allows 2 to the power n different colours, so 8 bits gives 256 colours and 24 bits gives over 16 million.
- LMultiplies 8 x 640 x 480
- LObtains 2,457,600 bits
- LConverts to 307,200 bytes which is 307.2 KB
- LAdds metadata to give 309.2 KB
The pixel data is colour depth multiplied by width multiplied by height, which is 8 x 640 x 480 = 2,457,600 bits. Dividing by 8 gives 307,200 bytes, and dividing by 1000 gives 307.2 kilobytes. Adding the 2 KB of metadata gives a total file size of 309.2 kilobytes.
- LMetadata is data about the file, stored alongside the image data
- LFirst valid example such as width, height, resolution or colour depth
- LSecond valid example such as date created, file format, camera model or GPS location
Metadata is data about the data, meaning information stored alongside the actual image content that describes the file and tells software how to interpret it. Two examples of image metadata are the width and height of the image in pixels, which the software needs in order to arrange the stored pixel values into the correct grid, and the date and time the photograph was taken, which is recorded automatically by most cameras.
- LThe number of available colours rises from 256 to over 16 million
- LImage quality improves with smoother colour gradients and more realistic images
- LThe file size triples because three times as many bits are used per pixel
- LThis requires more storage space and more bandwidth to transmit
Increasing colour depth from 8 bits to 24 bits raises the number of colours available for each pixel from 256 to over 16 million. This significantly improves quality, because gradual changes in colour such as a sky or a skin tone can be reproduced smoothly instead of showing visible banding where the limited palette has to jump between shades. The cost is file size: three times as many bits are now stored for every pixel, so the image file becomes three times larger. That means it takes up three times the storage space and takes about three times as long to transmit over a network.
- LReduce the resolution by decreasing the number of pixels
- LEffect: less detail and the image may look pixelated if enlarged
- LReduce the colour depth so fewer bits are used per pixel
- LEffect: fewer colours available which may cause visible banding in gradients
The first change is to reduce the resolution, lowering the number of pixels in the width and the height. Because file size is directly proportional to the number of pixels, halving both dimensions cuts the file to roughly a quarter of its original size, but less detail is captured so the photograph will look softer and will appear pixelated if a viewer enlarges it. The second change is to reduce the colour depth, for example from 24 bits to 8 bits per pixel, which cuts the pixel data to a third of its size. The drawback is that only 256 colours are then available, so smooth gradients such as a sky may show visible banding where the image has to jump between the nearest available shades.