Data representation · GCSE · OCR J277 1.2.4, AQA 8525 3.3.6, Edexcel 1CP2 2.2.2 · about 15 min
Pixels, resolution, colour depth, metadata and file size, from the robot's camera.
[1 mark]An image is 32 × 24 pixels with a colour depth of 8 bits. How many bits is it?
[1 mark]How many colours can a pixel with a colour depth of 4 bits have?
[1 mark]Doubling both the width and height of an image does what to its file size?
[1 mark]What is metadata in an image file?
[1 mark]What is the effect of increasing colour depth?
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.
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.