← All animations

🔳 Convolution & Edge Detection

Slide a tiny grid of weights — a kernel — across an image. At every position you multiply the kernel against the patch of pixels under it and add the products up: one number out. Do that everywhere and you get a new, filtered image. Change the weights and the same sliding operation blurs, sharpens, or lights up edges. This one trick is the heart of classical image processing — and of every convolutional neural network.

1. The sliding kernel — multiply, sum, repeat

On the left is a small grayscale image (brighter = larger pixel value). A 3×3 kernel slides over it; the highlighted patch under it is multiplied element-by-element with the kernel and summed into one output pixel on the right. Pick a kernel — or edit the nine weights yourself — and watch the filtered image rebuild.

Kernel (editable)
identity · sum of weights = 1
Output pixel = Σ kernel × patch. Slide it everywhere and the whole filtered image appears.

2. From one filter to a convolutional layer

A convolutional layer applies a bank of these kernels, each producing one feature map. Crucially, the network doesn't get the weights from us — it learns them by gradient descent. It turns out early layers reliably learn edge and blob detectors that look just like Sobel filters; deeper layers stack on top to detect textures, then shapes, then whole objects. Below, the same image is passed through two filters in a row — change either stage and watch the second map react.

edges → edges-of-edges
Stride, padding & pooling: stride is how many pixels the kernel jumps each step (stride 2 halves the map's size); padding adds a border of zeros so the output stays the same size; pooling shrinks a map by keeping, say, the max of every 2×2 block — making features robust to small shifts. Repeat conv → activation → pool and you have a CNN.

3. Why convolution is the right idea

Three ideas make this small operation extraordinarily powerful:

In short: convolution is a weighted sum over a local neighbourhood, slid across the whole image. Choose the weights by hand and you get blur or edge detection; let a network learn them and you get the first layer of computer vision.