Learning LabExplorable explanations
← All artifacts
Computer Vision

Convolution: Kernels on an Image

Edge detection, blur, and sharpen are all the same nine-number trick. Slide a 3x3 kernel across an image and watch the multiply-and-sum behind each output pixel, the operation a CNN learns on its own.

convolutioncnnkernelscomputer-vision
LiveInteractive · drag, toggle, run it
Computer Vision · Convolutional Networks

Convolution: Kernels on an Image

A convolution slides a tiny grid of weights, the kernel, across an image. At each position it multiplies the kernel against the pixels underneath and sums them into one output pixel. That weighted local average is the whole operation. The surprise is how much falls out of just nine numbers: change the weights and the same machinery detects edges, blurs, or sharpens.

Kernel

Pick a kernel, or edit the weights

sum = 0
Left weights positive, right weights negative. The response is large where brightness changes horizontally, so it lights up vertical edges. Sums to 0.
Blur kernels sum to 1 (after normalizing) so the picture keeps its overall brightness, they only redistribute it. Edge kernels sum to 0 so flat regions cancel to zero and only changes survive. Negative weights are drawn in blue.
Sliding window

Input, kernel, output

position (11, 9)

Move your pointer over the input to place the window, or press Step to advance it one pixel at a time. The highlighted 3x3 patch on the left feeds the one outlined pixel on the right.

Input
24×24 grayscale
Output
signed: blue −, orange +
The one pixel

Multiply, then add

Output pixel (11, 9) is the sum of nine products: each kernel weight times the input pixel beneath it. Cells marked with a dot read a clamped border pixel.

input patch
0.90
0.90
0.90
0.90
0.90
0.90
0.90
0.90
0.90
×
kernel
1
0
-1
2
0
-2
1
0
-1
=
products
0.90
0.00
-0.90
1.80
0.00
-1.80
0.90
0.00
-0.90
sum of nine products
0.90 + 0.00 0.90 + 1.80 + 0.00 1.80 + 0.90 + 0.00 0.90
= 0.0000.000
Why a CNN cares. A convolutional network does not hand-write these nine numbers; it learns them from data by gradient descent. Early layers tend to converge on exactly these kinds of edge and blob detectors, then later layers convolve over those responses to find corners, textures, and eventually whole objects. The arithmetic on this card is one neuron firing, repeated across every position and every channel.
Borders. At the edge the 3x3 window hangs off the image. This uses edge clamping: out-of-bounds reads repeat the nearest valid pixel, so the output stays the same size as the input and the border does not go dark. Zero padding and reflection are the other common choices.