Gradient LabStart the lesson

Lessons › Chapter 9: Computer vision

Convolution

This image is dark on the left and bright on the right. A filter is a small 3 × 3 grid of weights. This one is built to light up wherever dark changes to bright: a vertical edge.

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

Finding edges

To find the edges of the ID card in each photo, Leo slides small filters across the image.

Concept

A small filter

This image is dark on the left and bright on the right. A filter is a small 3 × 3 grid of weights. This one is built to light up wherever dark changes to bright: a vertical edge.

Key idea

Multiply and add

Lay the filter over the top-left corner. Multiply each pixel by the weight above it and add the nine products. All dark here, so the answer is 0. Write it into the first cell of the output.

Build

Slide across the image

Slide one step and repeat. Where the window straddles the dark-to-bright edge, the sum is big and the output cell lights up.

Build

A map of where the pattern is

Do it at every position and you get a feature map: a new grid that is tall exactly where the image has a vertical edge. That whole process is a convolution.

Real life

In real life: photo-app effects

Blur, sharpen and “find edges” effects in photo apps are convolutions with filters that someone designed by hand. A convolutional network does the same sliding, but learns thousands of its own filters from data.

Quick check: What does a convolution filter do at each position?

Each output number is a weighted sum of the pixels under the filter.

Pseudocode

filter = a small 3 × 3 grid of weights
for each position in the image:
    lay the filter on top
    multiply the overlapping numbers and add them up
    write the result into the output map
slide one step to the right (then down) and repeat

Key terms

filter
A small grid of weights that responds to one kind of pattern, like a vertical edge.
feature map
The output of one filter: a grid showing where its pattern appears.
convolution
Sliding a small filter across an image, multiplying and adding at every position.

In the news

Recent models and papers that build on this idea: