Pictures as numbers: pixels
A robot's camera doesn't 'see' a cat. It sees a grid of numbers. How many numbers make one photo?
About 25 min · 3 goals · Checked by automated tests; not yet reviewed by an educator
1.Why should I care?
Self-driving cars, sorting machines and phone cameras all work on images. Before a machine can recognise anything, an engineer has to know how the image is stored, how big it is, and how much detail it can hold.
- ◇ Explain that a digital image is a grid of pixels, each stored as a number.
- ◇ Calculate how many bits a simple image needs from its size and bits per pixel.
- ◇ Describe how more bits per pixel allow more shades or colours.
2.Predict
A black-and-white picture is 8 pixels wide and 8 pixels tall, one bit per pixel. How many bits is it?
Guess first. Being wrong here is how the surprise works.
3.Discover
Load the smiley and read the row numbers. Now draw your own 8 × 8 icon. Then press Invert: what happens to each row's bits? Could a friend redraw your picture from just the eight numbers?
Pixel picture
A screen is a grid of tiny squares called pixels. In a black-and-white picture each pixel is one bit: 1 = ink, 0 = paper. Click (or use arrows and Space) to draw, and watch each row turn into numbers.
| row 1 | 00111100 | 60 |
|---|---|---|
| row 2 | 01000010 | 66 |
| row 3 | 10100101 | 165 |
| row 4 | 10000001 | 129 |
| row 5 | 10100101 | 165 |
| row 6 | 10011001 | 153 |
| row 7 | 01000010 | 66 |
| row 8 | 00111100 | 60 |
26 of 64 pixels are ink. The whole picture is 64 bits = 8 bytes.
Can't use the interactive? Read a description instead
The pixel picture diagram shows an 8 by 8 grid of squares, each ink (1) or paper (0), with a table giving each row as 8 bits and as a number. The smiley's first row is 00111100, which is 60. Pressing Invert flips every bit, so 00111100 becomes 11000011 (195). The grid can be navigated with arrow keys and Space toggles a pixel.
4.Understand
A picture is a grid
Zoom in on any screen and you find tiny squares called pixels (picture elements). A digital image is just a grid of pixels, and each pixel is stored as a number. To a machine, a photo is a big table of numbers.
Bits per pixel = how many shades
With 1 bit per pixel, each pixel is black or white. With 2 bits, 4 shades. With 8 bits, 256 shades of grey. Colour photos usually use 8 bits each for red, green and blue: 24 bits per pixel, over 16 million colours.
How big is a picture?
bits = width × height × bits per pixel. An 8 × 8 icon at 1 bit is 64 bits. A 100 × 100 greyscale image at 8 bits is 100 × 100 × 8 = 80,000 bits = 10,000 bytes. Bigger, more detailed images need much more storage and take longer for a robot to process.
Explain it another way
It's like a paint-by-numbers mosaic: a grid of squares, each with a number that says which colour tile to use.
A raster image is a 2D array of samples. Each sample is quantised to 2ᵇ levels, where b is the bit depth. Size in bits = W × H × b (before compression).
A 640 × 480 image at 8 bits: 640 × 480 = 307,200 pixels × 8 = 2,457,600 bits = 307,200 bytes, about 0.3 MB.
The sorting machine's camera turns each part into a small grid of colour numbers. Code then averages the 'redness' numbers and compares the average with a threshold.
Worked example 1
A 16 × 16 game sprite uses 4 bits per pixel. How many colours can it use, and how many bits is it?
4 bits give 2⁴ = 16 colours. Size = 16 × 16 × 4 = 1,024 bits (128 bytes).
Common mix-ups
- A camera stores what it sees, like a tiny copy of the scene.
✓ A camera stores only numbers for each pixel. Making sense of them (cat or dog?) is a separate, hard job.
5.Practice
Practice, not a test. Wrong answers get a hint and another try.
Practice 1 · a fresh version every time
A tiny robot-eye camera takes pictures 10 pixels wide and 4 pixels tall. Each pixel uses 2 bits (4 possible shades). How many bits is one picture?
Practice 2
A tiny sensor image is 12 pixels wide and 10 pixels tall. How many pixels does it have?
Practice 3
How many different shades can a pixel show if it uses 3 bits?
Practice 4
You invert a black-and-white image (black ↔ white). What happens to each pixel's bit?
6.Apply it
Design an 8 × 8 icon for a machine's display (for example, a warning sign or a battery). Write it as eight row numbers. Swap numbers with a friend and redraw each other's icons.
7.Reflect
Concepts: Images as arrays of numbers · Binary, hexadecimal and digital signals