The Convolution Operator
Every filter you have applied on Instagram or Snapchat is this one operation. It is also how a CNN pulls features out of a picture, so it is worth doing slowly.
1Image features
Imagine a security camera image, and six small patches cut out of it. Your job is to find where each patch came from. Some are far easier than others:
- Flat patches — a stretch of plain wall or sky. Almost impossible: wherever you slide the patch it looks the same, so it could have come from anywhere in that area.
- Edges — the side of a building. Better: you can find roughly where it belongs, but not exactly, because the pattern is identical all the way along the edge.
- Corners — where two edges meet. Easiest: move the patch in any direction at all and it looks different, so its position is unique.
Finding a jigsaw piece's place
2Convolution
Computers store images as numbers. If you change those numbers, the image changes — that is the basis of all image editing. Convolution is the operation that changes them in an organised way.
3Watch it happen
The kernel sits over a small patch, the overlapping numbers are multiplied pair by pair, the products are added up, and that single result is written into the output. Then the kernel moves one step and does it again.
The small grid is the kernel. Watch the feature map build up underneath as it travels across the image.
Edge detect. The flat areas come out near black and the outlines light up. This is what 'extracting features' means — the sky is thrown away and the edges are kept. Notice the feature map is 14 × 14 where the input was 16 × 16: a 3 × 3 kernel cannot hang off the edge, so the output comes out smaller.
To keep them the same size you extend the edge values out by one before convolving — and while extending, the added pixel values are considered zero.
4What it is for
- Convolution is a common tool used for image editing.
- It is an element-wise multiplication of an image and a kernel to get the desired output.
- In computer vision applications it is used inside a Convolutional Neural Network to extract image features.
5Practice
▶Show the answer
A kernel is a matrix that is slid across the image and multiplied with the input so that the output is enhanced in some desirable way; different kernel values give different effects.
Convolution is the element-wise multiplication of the image array with that kernel, followed by a sum — producing a third array. In computer vision it is used to extract features from images.
▶Show the answer
A corner. Wherever you move a patch containing a corner, it looks different, so its location in the image is unique and easy to pin down. A patch containing only an edge looks the same all the way along that edge, so you can find its approximate position but not its exact one. Flat areas are worst of all, because they look identical everywhere.
6Check yourself
Which makes the best feature to extract from an image?
What is a convolution?
Why is the output of a convolution smaller than the input?