Lite / Discovering How the World Works / Week 14
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?
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.
Predict
A black-and-white picture is 8 pixels wide and 8 pixels tall, one bit per pixel. How many bits is it?
- 16
- 64
- 256
Guess first, then reveal
64. That's 8 × 8 = 64 pixels, each one bit: 64 bits, or 8 bytes. A real phone photo has millions of pixels and 24 bits each.
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?
What the interactive shows (text version)
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.
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
Intuitive
It's like a paint-by-numbers mosaic: a grid of squares, each with a number that says which colour tile to use.
Technical
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).
Mathematical
A 640 × 480 image at 8 bits: 640 × 480 = 307,200 pixels × 8 = 2,457,600 bits = 307,200 bytes, about 0.3 MB.
Applied
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.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
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.
Reflect
If a robot's camera image is just numbers, what makes it hard for the robot to recognise an object?
Write your answer on paper or in your own notes. Lite never stores what you write.