CS03-01 Computer Science Watch
How an image is stored
In this lesson
In this video you'll learn about how an image is stored for GCSE Computer Science. Watch first: {{video:CS01-02}}
By the end: Explain how a bitmap image is stored as a grid of pixels in binary, define resolution and colour depth, relate colour depth to how many colours a pixel can hold in both directions, describe the effect of each on image quality and on file size, and say what metadata is and which board requires it.
What it covers
- What a PIXEL is - AQA's own words: the term pixel is short for picture element, and a pixel is a single point in an image
- An image is stored as a grid of pixels, and each pixel's colour is held as a binary code
- IMAGE SIZE / RESOLUTION: width in pixels by height in pixels, written width x height - and the UNITS ARE PIXELS, which Edexcel pays a separate mark for
- COLOUR DEPTH: the number of bits used to represent each pixel
- The relationship, BOTH WAYS: a colour depth of n bits gives 2 to the n different colours; and given a number of colours, the smallest colour depth that will hold them
- The effect of resolution and colour depth on the QUALITY of the image and on the SIZE of the image file - qualitatively, direction of change only
- That the two are INDEPENDENT: more bits per pixel does not add pixels, and more pixels does not add colours
- METADATA - additional information stored with the image such as height, width, colour depth, file size, or when and where it was taken. OCR REQUIRES IT; AQA and Edexcel print no metadata requirement at all
- The naming: all three boards say colour depth; OCR says resolution where AQA says image size
Key words
About this video
How an image is stored: pixels, resolution and colour depth
How an image is stored as pixels in binary, with resolution and colour depth, their effect on file size, and metadata.
AQA 8525, Edexcel 1CP2 and OCR J277 GCSE. Images and sound 1 of 7.
Full Images and sound playlist: https://www.youtube.com/playlist?list=PLAonf4a5MXts
More at https://scholafly.com
Watch first: Denary (Decimal) to Binary and Back - https://youtu.be/8BNbDYvaatg
Video code: CS03-01 (search "ScholaFly CS03-01")
Videos in this chapter:
CS03-00 Images, sound and compression - Intro: https://youtu.be/5_VNvpWBbVU
CS03-01 How an image is stored: https://youtu.be/HKb8YHkv23c
CS03-02 From binary to bitmap and back: https://youtu.be/D7AjvZoKT_M
CS03-03 How sound is stored: https://youtu.be/LOCcQaN-_fI
CS03-04 Working out image and sound file sizes: https://youtu.be/_CcijC_0L1U
CS03-05 Why we compress data: https://youtu.be/ylXSh7OO4dI
CS03-06 Huffman coding: https://youtu.be/ig0uHFLoc9U
CS03-07 Run length encoding
#GCSEComputerScience #ImagesAndSound #HowAnImageIsStored
For teachers
This GCSE Computer Science lesson teaches how an image is stored. By the end, students should be able to explain how a bitmap image is stored as a grid of pixels in binary, define resolution and colour depth, relate colour depth to how many colours a pixel can hold in both directions, describe the effect of each on image quality and on file size, and say what metadata is and which board requires it. It works through four worked examples and the mistakes examiners report, and suits Foundation and Higher tier students.
Exam board specification references:
AQA GCSE Computer Science (8525)
- 3.3.6 Representing images
Pearson Edexcel Level 1/Level 2 GCSE (9-1) in Computer Science
- 2.2.2 Explain how bitmap images are represented in binary, in terms of pixels, resolution and colour depth.
Cambridge OCR Level 1/Level 2 GCSE (9-1) in Computer Science
- 1.2.4 Data storage - Numbers
Read the transcript
Zoom far enough into a photograph on a phone and the photograph disappears. What is left is a grid of flat coloured squares, and your eye was putting them together all along. Now picture two copies of one photograph with exactly the same number of squares. One looks like the real scene. The other looks like a black and white stencil, and its file is far smaller. Same squares, a different picture and a different file size. By the end of this video you can explain why, using two numbers. The first number is about counting squares, which is where we start. Turning binary back into a picture is a separate video, From binary to bitmap and back.
Each of those squares is a pixel, which is short for picture element. A pixel is a single point in an image, the smallest point there is. An image is a grid of these points, and each point holds one colour. We draw a pixel as a square so that you can see it. The square is only the drawing; the point is the thing itself. Inside the computer, each pixel's colour is stored as a binary code, a short pattern of ones and zeros. The image is that grid of codes, kept in order. Three students write down what a pixel is. One writes, a coloured square in a picture. One writes, the smallest point in an image. One writes, a dot of light on a screen. Which of those three definitions is the precise one, and why not the square? The middle one. The first describes the drawing rather than the thing, and the last describes the display rather than the picture. One examiner's report puts it like this. Rather than the smallest point, or smallest addressable element of an image, many students defined a pixel as a square in an image. This was too vague to be awarded a mark. The habit that fixes it is to open with the smallest point in an image. Smallest addressable element says the same thing: the smallest part the computer can set on its own.
The first of the two numbers is how many pixels the image has. You give it as the width in pixels by the height in pixels. Most courses call this the resolution, and one calls it the image size. Both names mean the same width by height, so learn the one your own course prints. Take an image two hundred pixels wide and one hundred and fifty pixels high. Its resolution is two hundred by one hundred and fifty pixels. To count every pixel, times the width by the height. Two hundred times one hundred and fifty is thirty thousand, so the image holds thirty thousand pixels. One examiner's report records this. This question was generally well answered with approximately ninety per cent of students stating the correct number of pixels in the image. If counting pixels already feels comfortable, you are in good company, and most of this video goes on the second number instead. Two students give the resolution of that first image. One writes two hundred by one hundred and fifty. The other writes two hundred by one hundred and fifty pixels. Which of those two answers is complete, and what is the other one missing? Only the one ending in pixels. Without the unit, two hundred by one hundred and fifty could mean centimetres, or nothing at all. A different report notes the same gap. Many responses correctly identified height times width but failed to specify the units in pixels. The fix is a habit that needs one word: every resolution you write ends in pixels.
The second number is the colour depth. Colour depth is the number of bits used to store each pixel. A pixel's colour is a binary code, and the colour depth is how long that code is. Every extra bit doubles the number of patterns, because each old pattern can now end in a zero or a one. So the length of the code decides how many colours a pixel can be. So build the ladder from the bottom rung. One bit has two patterns, zero and one, so one bit gives two colours. If counting patterns in binary is rusty, the video Denary to binary and back covers it. Two bits give four patterns, so four colours. Three bits give eight colours, because each rung up doubles the one below. That is the rule for every rung of the ladder. A colour depth of n bits gives two to the power n colours. Now one rung higher. With a colour depth of four bits, how many colours can a pixel be? Sixteen colours. Four bits is one more than three, so twice eight, which is sixteen. Now go the other way, which takes more care. A designer needs two hundred and forty different colours for a poster. What is the smallest colour depth that gives at least two hundred and forty colours? Eight bits. Climb the ladder: five bits give thirty-two colours, six give sixty-four, and seven give one hundred and twenty-eight, which is still too few. Eight bits give two hundred and fifty-six, the first rung that passes two hundred and forty. Two hundred and forty is not a power of two, so you stop at the first rung big enough. Here is a different claim. A student says a picture with only black and white in it needs a colour depth of two bits. What is wrong with needing two bits for two colours? One bit is already enough: it has two patterns, zero and one, one for each, so two bits would give twice what is needed. One examiner's report names the slip. A common misconception was that a two-bit colour depth was required to store two colours. The fix is to climb from one bit every time, instead of matching the number of bits to the number of colours. Another slip lives on every rung, because each rung carries two numbers. Seven bits is a colour depth. One hundred and twenty-eight is a number of colours. They answer different questions. A different report puts it this way. Common errors included confusing the colour depth of seven with two to the power seven for the number of colours available. The habit that stops it is labelling both numbers whenever you write them: seven bits per pixel, one hundred and twenty-eight colours.
Those are the two numbers, and they work as two separate controls. One sets the number of pixels; the other sets the number of bits per pixel. Turn up the number of pixels and freeze the colour depth. Each pixel now covers a smaller patch of the scene, so the picture shows finer detail. With the colour depth frozen, does any pixel get new colours to choose from? No. They all keep the same palette, the same set of colours they started with. The gain is sharpness and nothing more. Now do the opposite: freeze the pixels and turn up the colour depth. Not one pixel is added, but each gets more colours to choose from, so shading looks smooth instead of stepping in bands. Either change makes the file bigger, for one reason. A file stores bits. More pixels means more codes to store, and more bits per pixel means every code is longer. So the chain has three links. More colours needs more bits per pixel, and more bits per pixel makes a bigger file. Colours are never stored on their own; bits are. One examiner's report describes the gap. The relationship between colour depth and file size did not appear to be understood well and many students stated that because more colours were being used the file size would increase for both images. Those students jumped from more colours straight to a bigger file, for both images. The fix is to say all three links every time, so the bits per pixel are always in the answer. Back to the two copies of one photograph from the start. They have the same resolution, but one copy uses a colour depth of one bit, and the other a colour depth of eight bits. Why does the eight-bit copy look real, and why is its file bigger? With one bit per pixel, each pixel is one of two colours, so the photo flattens into a stencil. With eight bits, each pixel has two hundred and fifty-six colours to choose from, and the shading returns. And the file is bigger because every pixel now takes eight bits instead of one, while the number of pixels stays put. Here is a different task. Four changes to a picture: doubling its width, going from sixteen colours to two hundred and fifty-six, cropping off its edges, and smoothing its shading. Which two of those four changes alter the bits per pixel? The second and the fourth changes. Both give every point more shades to pick from. The first and the third change how many points the grid holds. A different report draws the same line in its own words. A common misconception is that colour depth increases the resolution of the image. This would need to be an increase in the resolution, the number of pixels, as opposed to the number of bits per pixel. And another report names the answer it saw most often. The most common misconception was, more pixels. More pixels is right for some questions and wrong for others. The habit is to decide which number the question is about before you answer: the number of pixels, or the bits per pixel.
Metadata is extra information stored with an image, about the image. The height, the width, the colour depth, the file size, and when and where a photo was taken can all be metadata. Only one course asks for it by name, so if yours does not, treat this part as background. Think of a printed photo with a label stuck on the back. The picture is on the front; the label says things about the picture. A student says the metadata of a photo records the colour of each pixel. Why is the colour of each pixel not metadata? Because the pixel colours are the image itself. Metadata is information about the image, the label on the back, not the picture on the front. One examiner's report names that wrong answer. A common misconception was that metadata identifies the colour of each pixel in the image. The fix is a quick test. If it is part of the picture, it is not metadata; if it describes the picture, such as its width or the date it was taken, it is.
Time to see what has stuck. Four questions, and the answer arrives after each one. In one precise sentence, what is a pixel? A pixel is a single point in an image, the smallest one there is. The square is only how it gets drawn. Next, a number not used yet. What is the smallest colour depth for thirty colours? Five bits. Four bits give sixteen, which is too few, and five bits give thirty-two, the first rung past thirty. Now a camera setting. Resolution doubled, colour depth unchanged: do pixels gain colours? No. You get more pixels, each with the same choice of colours, and the file grows because there are more codes to store. One more, back to the two copies of the photograph. Which number made one a stencil? The colour depth. One bit per pixel allows only two colours, so the photograph flattened into a stencil, and eight bits brought the shading back.
If you could explain to a friend why one more bit doubles the colours, and why that grows the file, you could teach this one, so give it the thumbs up. If it has not settled yet, save the video, give it a day, and look again with fresh eyes.
Next in the chapter: From binary to bitmap and back.
For more, visit scholafly.com, or watch the next video.
Related terms
For: AQA GCSE 8525, Edexcel GCSE 1CP2, OCR GCSE J277
On the specification
For teachers
This GCSE Computer Science lesson teaches how an image is stored. By the end, students should be able to explain how a bitmap image is stored as a grid of pixels in binary, define resolution and colour depth, relate colour depth to how many colours a pixel can hold in both directions, describe the effect of each on image quality and on file size, and say what metadata is and which board requires it. It works through four worked examples and the mistakes examiners report, and suits Foundation and Higher tier students.