The worksheetDownload the PDF
Answers

F8.7 Images

Data representation · GCSE · OCR J277 1.2.4, AQA 8525 3.3.6, Edexcel 1CP2 2.2.2 · about 15 min

BugBotLab

What this lesson is about

Pixels, resolution, colour depth, metadata and file size, from the robot's camera.

Questions 5 marks in all

  1. [1 mark]An image is 32 × 24 pixels with a colour depth of 8 bits. How many bits is it?

    Answer: 6144. 32 × 24 × 8.
  2. [1 mark]How many colours can a pixel with a colour depth of 4 bits have?

    Answer: 16. 2 to the power 4.
  3. [1 mark]Doubling both the width and height of an image does what to its file size?

    1. AMultiplies it by 4
    2. BDoubles it
    3. CLeaves it the same
    4. DHalves it
    Answer: A. There are twice as many pixels across and down: four times as many pixels.
  4. [1 mark]What is metadata in an image file?

    1. AData about the image, such as its width, height and colour depth
    2. BThe brightest pixels
    3. CThe compressed pixels
    4. DA copy of the image
    Answer: A. Without the width, the pixels could not be arranged back into rows.
  5. [1 mark]What is the effect of increasing colour depth?

    1. AMore colours and a larger file
    2. BFewer pixels
    3. CA smaller file
    4. DLower resolution
    Answer: A. More bits per pixel means more possible colours and more bits to store.

The task: camera pixels

Capture camera_image(32, 24). Print it as 24 lines of 32 characters, # for a pixel whose average of red, green and blue is below 128, . otherwise. Then print 1-bit size: <bits> and 24-bit size: <bits> for a 32 × 24 image, worked out with a calculation.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

img = camera_image(32, 24)

The hint students can ask for: For each row, for r, g, b in row: add '#' if (r + g + b) / 3 < 128 else '.'. Size in bits is width * height * depth.

A solution

from bugbot import *
connect()
img = camera_image(32, 24)
picture = []
for row in img:
    line = ""
    for r, g, b in row:
        line = line + ("#" if (r + g + b) / 3 < 128 else ".")
    picture.append(line)
for line in picture:
    print(line)
print('1-bit size:', 32 * 24 * 1, 'bits')
print('24-bit size:', 32 * 24 * 24, 'bits')

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.