Digital Representation of Multimedia
Digital Image Encoding
Every photo on your phone and every icon on a web page is stored as a long list of binary numbers. Image encoding is the set of rules that turns a picture into those numbers. The picture is split into tiny squares, each square gets one colour, and each colour is stored as a fixed number of bits. Once you know these rules, you can predict how much storage an image needs and explain why some images look smooth while others look blocky.
Pixels and resolution
The images in this lesson are stored as a bitmap: a rectangular grid of pixels, where each pixel is the smallest element of the image and holds exactly one colour. The size of the grid is the image's resolution, written as width × height in pixels. A photo that is 4000 pixels wide and 3000 pixels tall contains 4000 × 3000 = 12,000,000 pixels, which cameras advertise as 12 megapixels.
More pixels capture finer detail because each square covers a smaller part of the scene. With too few pixels, each square is large enough to see and curved edges look like staircases. This effect is called pixelation.
Colour depth and RGB
Colour depth is the number of bits stored for each pixel. With n bits there are 2n different bit patterns, so a pixel can take one of
colours. Each extra bit doubles the number of colours, because every existing pattern can now end in either 0 or 1.
Colour depth | Colours available | Typical use |
|---|---|---|
1-bit | 2 | Black-and-white scans |
8-bit | 256 | Greyscale photos, simple graphics with a palette |
16-bit | 65,536 | Older displays and games |
24-bit | 16,777,216 | Full-colour photos |
Most colour images use the RGB model. Each pixel stores three channels, red, green and blue, and each channel uses 8 bits for an intensity from 0 to 255. That makes 24 bits per pixel. The orange pixel in the figure has red 255, green 102 and blue 0, which web designers write as #FF6600 in hexadecimal, two digits per channel. Using fewer bits saves space, but neighbouring shades merge and smooth gradients such as a sunset sky break into visible bands.
Uncompressed file size
Because every pixel uses the same number of bits, the size of the raw pixel data is a simple product:
Divide by 8 to convert bits to bytes. This formula counts pixel data only: a real file also has a small header recording details such as the dimensions, and most formats compress the data, which reduces the stored size further.
Example: A 640 × 480 image in 24-bit colour has 640 × 480 = 307,200 pixels. Its raw size is 307,200 × 24 = 7,372,800 bits. Dividing by 8 gives 921,600 bytes, or about 922 KB.
Since size is a product, scaling works predictably. Doubling both the width and the height multiplies the pixel count, and so the size, by 4. Doubling the colour depth from 8 to 16 bits doubles the size, yet the number of colours jumps from 256 to 65,536. Size grows in proportion to bits per pixel, but the number of colours grows exponentially.
What to remember
- A bitmap is a grid of pixels; its resolution is width × height in pixels.
- With n bits per pixel, a pixel can show 2n colours; 24-bit RGB uses 8 bits for each of three channels.
- Raw size in bits = width × height × colour depth; divide by 8 for bytes.
- Doubling both dimensions quadruples the size; doubling colour depth doubles the size but squares the number of colours.
Example: Storing camera snapshots
A security camera saves each snapshot as an uncompressed 1920 × 1080 bitmap in 24-bit RGB colour. Ignore file headers, and use 1 MB = 1,000,000 bytes and 1 GB = 1,000,000,000 bytes.
a) Find the raw size of one snapshot in bits.
First count the pixels: 1920 × 1080 = ________.
Each pixel stores 24 bits, so the total is
One snapshot needs 49,766,400 bits of pixel data.
b) Express that size in megabytes.
There are 8 bits in a byte, so 49,766,400 ÷ 8 = ________.
Dividing by 1,000,000 bytes per megabyte:
Each snapshot takes about 6.22 MB.
c) To save space, the camera is switched to 8-bit greyscale, which offers 256 shades of grey. Find the new raw size of one snapshot in MB.
The pixel count does not change. The colour depth falls from 24 bits to 8 bits, a factor of ________, so the size falls by the same factor.
Each pixel now uses 8 bits, which is exactly 1 byte, so the snapshot uses ________:
The greyscale snapshot takes about 2.07 MB, one third of the colour version (6.2208 ÷ 3 = 2.0736).
d) The camera stores 24-bit colour snapshots on a 32 GB memory card. How many complete snapshots fit on the card?
Convert the card capacity to bytes: 32 × 1,000,000,000 = ________.
Divide by the size of one colour snapshot from part b: 32,000,000,000 ÷ 6,220,800 ≈ ________.
Only complete snapshots can be stored, so round down to 5144 snapshots. Check: 5144 × 6,220,800 = 31,999,795,200 bytes, which fits, while 5145 snapshots would need 32,006,016,000 bytes, which is more than the card holds.
A graphics format stores exactly 12 bits for each pixel's colour. How many different colours can a single pixel in this format represent?
A flatbed scanner turns a printed photograph into a bitmap file. Put the stages of this digitizing process in the order the scanner carries them out, from the first stage to the last.
1.
Save the bits as a file together with metadata giving the width, height and colour depth.
2.
Divide the photograph into a grid of pixels at the chosen resolution.
3.
Write each pixel's colour as a binary code of n bits, row by row.
4.
Measure the colour of the light coming from each pixel's area.
5.
Round each measured colour to the nearest colour the chosen colour depth can represent.