A picture is numbers
A pixel is one tiny square of a picture. Many pixels side by side make the whole picture. A computer cannot send a colour, so it gives each colour a number. A black and white pixel needs 1 bit. A colour pixel on a phone usually needs 24 bits (3 bytes): one byte each for red, green and blue.
A still image is one picture that does not move. Photos, scanned pages and fax pages are still images. To send one, we send its numbers along a wire or by radio, and the receiver draws the squares again.
Size of a picture = width × height × bits per pixel. A 1920 × 1080 photo with 24 bits per pixel has 2,073,600 pixels, so 6,220,800 bytes, about 6.2 MB.
How a television shows a moving picture
A moving picture is many still pictures shown quickly. Each still picture is a frame. If 25 to 30 frames are shown in one second, your eyes see smooth motion.
The TV does not send a whole frame at once. It sends the picture one line at a time, from the top to the bottom. This is called scanning. A camera scans the scene into lines, the signal travels, and the screen draws the lines again in the same order. Colour TV does this for three colours: red, green and blue, and mixes them on the screen.
Older TVs sent a signal made of waves (analogue). Today most TV is digital: the lines are numbers, and the numbers are compressed to save space.
Compression: make the list shorter
Compression means storing the same picture in fewer numbers, so it is quick to send and uses less space.
Lossless compression loses nothing. After you open it, you get exactly the same picture. Example, run-length coding: 20 white pixels in a row become "white, 20". ZIP and PNG are lossless.
Lossy compression throws away small details your eyes hardly notice. The file is much smaller, but you cannot get the lost detail back. JPEG is lossy. Too much lossy compression makes the picture blocky.
Encryption: lock it with a key
A wire or radio wave can be listened to by anyone. Encryption changes the numbers using a secret key, so a stranger sees only noise. Decryption changes them back with the key.
In the 3D, the key adds a number to every pixel value. With the wrong key, the colours come out wrong. Real systems use much harder maths, but the idea is the same: same key opens the lock (this is called a symmetric key), a wrong key gives rubbish.
Order matters: compress first, then encrypt. Encrypted data looks random, and random data cannot be squashed.
Try it
In the 3D, jump to the last step. Set the sender key to 2 and the receiver key to 3 and press "Send again". Is the picture clear? Now make both keys equal and send again. Predict first, then check. At home, draw a 6 × 6 grid on paper, colour a smiley, and write the numbers row by row. Give the list to a friend and see if they can draw your picture.
Key formulas and definitions
- Image size (bits) = width × height × bits per pixel
- Image size (bytes) = bits ÷ 8
- Compression ratio = original size ÷ compressed size
- Run-length coding: AAAABB → (A,4)(B,2)
- Send order: compress → encrypt; receive order: decrypt → decompress
Worked examples
1. How many pixels are in a picture 8 pixels wide and 8 tall?
8 × 8 = 64 pixels.
2. A black and white picture is 100 × 50 pixels, 1 bit per pixel. How many bytes?
Bits = 100 × 50 × 1 = 5000. Bytes = 5000 ÷ 8 = 625 bytes.
3. A photo is 1000 × 800 pixels with 24 bits per pixel. Find its size in MB (1 MB = 1,000,000 bytes).
Pixels = 800,000. Bytes = 800,000 × 3 = 2,400,000. Size = 2.4 MB.
4. Write the run-length code for WWWWBBWWW.
Four W, two B, three W: (W,4)(B,2)(W,3).
5. A 2.4 MB photo is compressed to 0.3 MB. Find the compression ratio.
Ratio = 2.4 ÷ 0.3 = 8. The file is 8 times smaller.
6. A TV shows 25 frames per second. How many frames in 2 minutes?
2 minutes = 120 s. Frames = 25 × 120 = 3000.
Common mistakes
- Thinking a pixel is a number of megapixels. A pixel is one square; megapixel means one million pixels.
- Mixing bits and bytes. 8 bits = 1 byte. Divide by 8 to go from bits to bytes.
- Believing all compression keeps the picture perfect. Lossy compression throws detail away for ever.
- Encrypting first and compressing after. Encrypted data looks random, so it will not shrink.