Codiqo

Understanding AI · lesson 33 of 60 · about 5 minutes

Pictures as Grids of Numbers

A photo is a grid of pixels, and a colour pixel is three numbers. See exactly what AI is given when it looks at a picture.

What you'll learn

  • Describe a picture as a grid of pixels
  • Explain how three numbers make a colour
  • Work out how many numbers a picture contains

Red, green and blue

You've seen black and white pictures as one number per pixel. Colour pictures use three numbers per pixel: how much red, green and blue light, each from 0 to 255. Every colour on your screen is a mix of those three.

(255, 0, 0) is pure red. (255, 255, 0) is yellow. (0, 0, 0) is black and (255, 255, 255) is white.

A pixel as three numbers. Then how many numbers a small photo holds.

yellow = (255, 255, 0)
print(yellow[0], yellow[1], yellow[2])

width = 100
height = 100
print(width * height * 3)

Output

255 255 0
30000

Tip

Even a tiny 100 by 100 photo is 30000 numbers. A phone photo has tens of millions.

Now try it yourself

This lesson is free in Codiqo, with 6 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.