Skip to content
Tactiverge

School/○ Innovator/Week 24

Images are arrays of numbers

To a robot, your face is a grid of about two million numbers. Which number is your nose?

About 35 min · 3 goals · Checked by automated tests

1.Why should I care?

Every vision algorithm, from a barcode reader to a self-driving car, starts by treating a picture as a table of numbers. Once you see it that way, image processing becomes arithmetic on arrays: the same skills you used on sensor logs.

  • ◇ Represent a greyscale image as a 2D array of brightness values and a colour image as three channels.
  • ◇ Index a pixel by row and column and compute an image's memory size.
  • ◇ Connect pixel values to sensor sampling and quantisation.

2.Watch

→ Watch for how a colour image is stored as separate red, green and blue values per pixel, and how many bits each one gets.

How a camera image becomes rows of numbers, including how colour is stored, before any vision algorithm touches it.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

The video is optional: everything you need is also in the lesson text and the interactive.

3.Predict

How many bytes does one uncompressed 640 × 480 colour image take with 8 bits per channel?

Guess first. Being wrong here is how the surprise works.

4.Discover

Choose the Bright square, then the Gradient. Click pixels to read their values: where is (row 1, column 1)? Which way do column numbers grow? Find the darkest and brightest pixel in the Noisy bar and explain why its 'flat' regions aren't flat.

Loading the interactive…

Can't use the interactive? Read a description instead

The pixel diagram shows an 8 × 8 image as a grid of numbered squares. The Bright square image has value 200 in the central 4 × 4 block and 40 elsewhere; the Gradient rises by 30 per column from 20 to 230; the Noisy bar has a brighter band in columns 4 and 5 with random variation of up to ±45 and one bright speck.

5.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

How many bytes is a 100 × 80 greyscale image at 8 bits per pixel?

bytes

6.Understand

A grid of samples

A camera sensor is an array of light-measuring cells. Each one integrates light during the exposure and is converted to a number: the image is sampled in space (pixels) and quantised in brightness (usually 8 bits, 0–255). A greyscale image is a 2D array img[row][col]; row 0 is at the top.

Colour is three arrays

A colour image stores three channels, red, green and blue, so each pixel is a triple like (230, 40, 35) for a red-ish part. Many cameras actually measure one colour per cell through a mosaic of filters and fill in the other two by interpolation.

Size and cost

Memory = width × height × channels × bytes per channel. Processing time grows the same way, so robots often shrink images (downsample), convert to greyscale, or process only a region of interest. Downsampling an image is sampling again, so fine stripes can alias into false patterns, called moiré.

Same lessons as sensors

Each pixel is a sensor reading with noise, bias (a dark offset), limited range (saturated white areas lose detail) and resolution. Everything from weeks 19–23 applies, now in two dimensions.

Explain it another way

An image is like a mosaic of tiny tiles, each painted one shade from black to white. Write the shade number on every tile and you have what the computer sees.

Worked example 1

A greyscale camera is 1280 × 720 at 8 bits, 60 fps. What is the raw data rate?

1280 × 720 = 921,600 bytes per frame; × 60 = 55.3 MB/s. That is why the robot crops to the 200 × 200 region it actually needs (2.4 MB/s).

Common mix-ups

  • A camera records what the eye sees.
    ✓ It records numbers: sampled, quantised, noisy and clipped, through a lens and a colour filter. Vision algorithms see only those numbers.
  • Coordinates in images work like maths graphs, with y going up.
    ✓ Image rows usually count down from the top; mixing the conventions flips results.

7.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2

How many bytes is a 320 × 240 RGB image at 8 bits per channel?

bytes

Practice 3

In img[row][col] with row 0 at the top, which pixel is img[2][5]?

Practice 4

A bright window shows as a block of pixels all exactly 255. What does that tell you?

Practice 5 · a fresh version every time

A 16-bit converter spans 0 to 5 V. Taking one step as range ÷ 2^n, how big is one step, in millivolts?

mV

8.Apply it

Load a small greyscale photo in Python as a 2D list or array. Print its size, the brightest and darkest values and their positions, then crop the central quarter and save its mean brightness. Explain in one sentence what that mean would tell a robot.

9.Reflect

Concepts: Images as arrays of numbers · Analog-to-digital conversion