The core operation of every CNN

Convolution kernel lab

A kernel is nine numbers. Slide it over an image, multiply, add up — that is the whole operation, and it is the operation a convolutional network learns the numbers for. Edit the nine values below and watch what they detect. Then press step to walk the window across the image one position at a time and see the arithmetic.

The kernel
0

Input and feature map click the source to move the inspector
Input
Output

The output is drawn at the same scale as the input, so when padding or stride shrink it, it really does occupy less of the panel.

One position at a time
Pixels under the window
×
Kernel
=
Products
8/s

This is the equation from the notes, drawn out: Output(i,j) = Σm Σn km,n · pi+m−2, j+n−2. Nine multiplications and eight additions, repeated once per output pixel. A 300×225 feature map costs about 600,000 multiply-adds — for one filter, and a real layer has dozens.

Sum of weights
Learnable parameters
Multiply-adds for this map
Output range

The sum of the weights tells you what the filter does to brightness. If it sums to 1, average brightness survives — that is every blur and every sharpen. If it sums to 0, flat regions produce exactly zero and only changes survive: that is every edge detector, and it is why the Sobel and Laplacian presets return a mostly-black image with the outlines glowing. Nothing in a flat region differs from its neighbours, so there is nothing for a zero-sum kernel to report.

Try Sobel X on the brick scene, then Sobel Y. One finds the vertical mortar lines and is nearly blind to the horizontal ones; the other does the opposite. Neither was told what a brick is. This is the entire premise of a convolutional layer: a small stack of filters like these, applied everywhere, turns raw pixels into a map of where the interesting structure is — and because a network learns the nine numbers rather than being given them, it discovers whichever detectors the task actually rewards.

Nine numbers, reused everywhere. A fully connected layer reading a 300×225 image needs 67,500 weights per neuron. This kernel needs nine, and it applies them at every position. That reuse — weight sharing — is why CNNs made image processing tractable, and it is the answer to the parameter explosion the notes raise just before this section.