How Convolution Kernels Transform Images: A Visual Guide to Filters

An in-depth walkthrough of the 2D convolution operation that underlies every classical image filter and every convolutional neural network, from blur and sharpen kernels to feature maps.

What a Convolution Kernel Actually Does

Every digital photograph is, underneath its visual surface, a grid of numbers. A grayscale image is a single matrix where each cell holds a brightness value between 0 (black) and 255 (white); a colour image is three such matrices stacked together, one per red, green and blue channel. Convolution is the operation that lets you transform this grid systematically by sliding a small matrix — the kernel or filter — across every position in the image and combining the values underneath it into a single output number.

A typical kernel is tiny compared to the image, often just 3×3 or 5×5 cells. At each position, you multiply every kernel value by the pixel value it overlaps and sum the results — this is the same operation as a dot product between two flattened vectors. That sum becomes one pixel in a new image called a feature map. Move the kernel one step to the right, repeat the calculation, and you get the next output pixel. Do this across the whole image and you have transformed it according to whatever pattern the kernel encodes.

What makes this so powerful is that a handful of numbers arranged in the right pattern can detect meaningful structure. A kernel that is negative on the left and positive on the right reacts strongly wherever brightness jumps from dark to light — in other words, it finds vertical edges. A kernel of uniform positive values averages out a neighbourhood, blurring the image. The mathematical operation never changes; only the numbers inside the kernel change, and that is enough to produce wildly different effects.

Reading a Kernel by Hand: Edge Detectors and Blurs

Consider the classic vertical-edge kernel used in early machine vision work:

[-1  0  1]
[-1  0  1]
[-1  0  1]

Each row subtracts the pixel to the left of a position from the pixel to the right. In a flat region where neighbouring pixels are nearly identical, this sum is close to zero, so the output stays dark. But where the image jumps from a dark region to a bright one — say, from a 0 to a 255 — the sum spikes, producing a bright pixel in the output. The result is a map that lights up exactly where vertical edges occur and stays dark everywhere else.

The Sobel operator, one of the most widely used edge kernels, refines this idea by weighting the centre row or column more heavily:

Sobel X:            Sobel Y:
[-1  0  1]           [-1 -2 -1]
[-2  0  2]           [ 0  0  0]
[-1  0  1]           [ 1  2  1]

Running Sobel X and Sobel Y separately and then combining the results with magnitude = sqrt(Gx² + Gy²) gives an edge strength that is sensitive to gradients in any direction, not just purely horizontal or vertical ones.

Blurring kernels work on the opposite principle: instead of amplifying differences, they average them away. A 3×3 box blur kernel is simply nine cells each holding 1/9, so the output pixel becomes the mean of its neighbourhood. A Gaussian blur kernel weights the centre most heavily and tapers off toward the edges following a bell curve, which produces a smoother, more natural-looking blur with fewer harsh artefacts than a plain box average. A sharpening kernel does the reverse of blurring: it boosts the centre pixel relative to its neighbours, for example [[-1,-1,-1],[-1,9,-1],[-1,-1,-1]], which exaggerates local contrast and makes edges look crisper.

Stride, Padding and Output Size

Three parameters control exactly how a kernel moves across an image and what size the resulting feature map will be.

Stride is the step size the kernel takes between calculations. A stride of 1 slides the kernel one pixel at a time, producing an output nearly as large as the input. A stride of 2 skips every other position, halving the output resolution in each dimension — this is a simple and common way to downsample an image while still applying a filtering operation.

Padding addresses what happens at the borders. A 5×5 image convolved with a 3×3 kernel and no padding ("valid" padding) can only be centred at 3×3 positions, so the output shrinks to 3×3. If you want the output to stay the same size as the input ("same" padding), you pad the border with extra rows and columns — typically filled with zeros — before sliding the kernel, so that every original pixel can serve as a kernel centre.

These two parameters combine in a single formula that predicts the output dimensions precisely:

output_size = floor((input_size + 2 × padding − kernel_size) / stride) + 1

This formula matters in practice because it determines how many convolutional layers you can stack before an image shrinks to nothing, and how much padding you need to preserve spatial resolution through a deep network. It is also exactly the kind of relationship that becomes intuitive only once you can drag sliders for kernel size, stride and padding and watch the output grid resize in real time — which is why a convolution visualizer, showing the sliding window and the resulting feature map simultaneously, is one of the most effective ways to internalise the concept.

From Hand-Designed Filters to Learned Kernels

Everything described so far uses kernels that a human designed by hand — the values in a Sobel or Gaussian kernel were derived mathematically decades ago and never change. Convolutional neural networks (CNNs) take the same sliding-window mechanism but treat the kernel values as trainable parameters instead of fixed constants. A convolutional layer starts with kernels initialised to small random numbers, and gradient descent adjusts those numbers, layer by layer, so that the resulting feature maps become useful for whatever task the network is being trained on — classifying digits, detecting faces, segmenting tumours.

Early layers in a trained CNN tend to rediscover filters that look remarkably like the hand-designed ones: edge detectors, colour-opponent blobs, oriented gratings. This is a striking validation of the classical filter-design intuition — the network converges on similar solutions because they are genuinely useful for extracting structure from natural images. Deeper layers combine these low-level feature maps into detectors for increasingly abstract patterns: textures, object parts, and eventually whole object categories.

A convolutional layer generalises the single-kernel idea by applying many kernels in parallel to the same input, each producing its own feature map, all stacked together into a 3D output volume. If a layer applies 16 filters of size 3×3 to a 3-channel RGB image, its weight tensor has shape (3, 3, 3, 16) — three input channels per filter, sixteen independent filters. The number of learnable parameters in that single layer is 3×3×3×16 = 432 weights, plus 16 bias terms, which is dramatically fewer parameters than a fully-connected layer would need to process the same image, because the kernel is reused (with the same weights) at every spatial position. This weight-sharing is precisely why CNNs scale to large images without an explosion in parameter count.

Receptive Field: How Stacking Convolutions Sees Further

A single 3×3 kernel only "sees" a 3×3 patch of the input at a time — its receptive field is 3×3 pixels. But stack a second 3×3 convolutional layer on top of the first, and a neuron in that second layer sees a 3×3 patch of the first layer's output, and each of those cells was itself computed from a 3×3 patch of the original image. The effective receptive field on the original image grows to 5×5. Add a third layer and it grows to 7×7, following the pattern that each additional 3×3 layer (with stride 1) adds two pixels to the receptive field in each dimension.

This compounding effect is why deep networks can recognise large-scale structure — a whole face, a car, a building — despite every individual kernel being tiny. It also explains a key design trade-off: two stacked 3×3 convolutions achieve the same 5×5 receptive field as a single 5×5 convolution, but with fewer total parameters (2×9=18 versus 25 per input-output channel pair) and an extra non-linearity in between, which is part of why modern architectures favour many small kernels over few large ones.

Pooling: Shrinking Feature Maps Without Losing the Signal

Convolution is usually paired with a second downsampling operation called pooling, which reduces the spatial size of feature maps without adding trainable parameters. Max pooling slides a small window (commonly 2×2) across a feature map and keeps only the largest value in each window, discarding the rest. This shrinks a feature map's width and height by half while keeping the strongest activations — effectively asking "was this pattern present anywhere in this small region?" rather than "exactly where was it?"

That loss of precise location is deliberate: it gives the network a degree of translation invariance, so a feature detected slightly off-centre in one image still triggers the same response as if it had been perfectly centred. Average pooling, which takes the mean instead of the maximum, is used less often for intermediate layers but remains common at the very end of a network (global average pooling), where it collapses each entire feature map down to a single number before a final classification layer.

Frequently Asked Questions

What is the difference between convolution and cross-correlation?

Mathematically, true convolution flips the kernel both horizontally and vertically before sliding it across the image, while cross-correlation does not flip it. In practice, nearly every deep learning framework and image-processing library implements what is technically cross-correlation but calls it 'convolution' — since the kernel values are either hand-designed or learned, the flip makes no practical difference to the result.

Why do CNNs use small kernels like 3x3 instead of larger ones?

Stacking several small kernels reaches the same receptive field as one large kernel while using fewer parameters and adding more non-linear activation steps in between, which tends to improve the network's representational power without increasing computational cost as steeply.

Does a bigger kernel always capture more useful information?

Not necessarily. A larger kernel does see a wider area in one step, but it also has more parameters to learn, is more prone to overfitting on limited data, and blurs fine detail more aggressively. Most modern architectures prefer depth (many small-kernel layers) over width (few large-kernel layers).

What happens to the border pixels during convolution?

Without padding, the kernel cannot centre itself on the outermost rows and columns, so those pixels either get discarded (valid padding, producing a smaller output) or the image is artificially extended, often with zeros, so the kernel can still be applied at every original pixel position (same padding, producing an output the same size as the input).

How can I visualize what a convolution kernel is doing?

The clearest way is to animate the sliding window: show the kernel's current position on the input grid, the multiply-and-sum calculation for that position, and the corresponding pixel lighting up in the output feature map, then step through positions one at a time or play it continuously to see the finished feature map emerge.