Gradient LabStart the lesson

Lessons › Chapter 9: Computer vision

Images as numbers

To a computer, an image is a grid of tiny squares called pixels. This one is just 6 × 6, a little smiley face.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

ID photos at sign-up

New customers upload a photo of their ID card. First, Leo needs to understand what a photo looks like to a computer.

Concept

A picture is a grid

To a computer, an image is a grid of tiny squares called pixels. This one is just 6 × 6, a little smiley face.

Build

Brightness becomes a number

Each pixel stores how bright it is, from 0 (black) to 1 (white). Here bright pixels stand tall. The picture is now just a table of numbers.

Build

Color means three layers

A color image stores three numbers per pixel: how much red, green and blue. That’s three grids stacked on top of each other, called channels.

Key idea

A stack of numbers: a tensor

A grid of numbers with several layers is called a tensor. This one has shape 6 × 6 × 3. A phone photo is about 3000 × 4000 × 3: around 36 million numbers, all going into the network.

Real life

In real life: every photo you take

A 12-megapixel phone photo is about 36 million numbers: red, green and blue for every pixel. Face unlock, photo search and night mode all start by treating your picture as this giant grid of numbers.

Quick check: How many numbers describe a 10 × 10 color image?

10 × 10 pixels × 3 color channels = 300 numbers.

Pseudocode

image = a grid of pixels, 6 × 6
each pixel = brightness from 0 (black) to 1 (white)
a color image = 3 grids stacked: red, green, blue
shape = (height, width, channels) = (6, 6, 3)
a phone photo: (3000, 4000, 3) = 36 million numbers

Key terms

pixel
One tiny square of an image, stored as a number (or three numbers for color).
channel
One layer of an image, like the red, green or blue values.
tensor
A grid of numbers with any number of dimensions: a list, a table, a stack of tables…

Build it: A neural network that reads handwriting (35 min, runs in your browser)

See the project