Convolutional Filters — the building blocks of CNNs

Design 3×3 kernels and see in real time how they transform images

Filter applied: Sobel-X — Vertical edges

What is a convolution?

AnalogyDefinition

Picture a stencil that you lay over every single pixel of an image. Whatever lies under the stencil gets weighted and summed — and that sum is the new pixel. Move the stencil over, do the same there, and repeat across the whole image.

Different stencils (kernels) yield different effects: a stencil with negative values on the left and positive values on the right finds vertical edges. A stencil with all equal positive values blurs the image. Convolutional Neural Networks (CNNs) are built on exactly this principle.

How convolution works

A convolution is a handful of simple steps repeated for every pixel of the image:

  1. Kernel — the stencilThe kernel is a small matrix (here 3×3 — that is, 9 cells). Why 3×3 and not 100×100? Because a tiny window around the target pixel is enough to detect local features like edges — and 9 values are fast to compute. In real CNNs, 3×3, 5×5 or 7×7 are standard. Each value weights a neighbour pixel: positive values boost, negative values subtract. The centre cell is the target pixel (anchor).
  2. Sliding — pixel by pixelSlide the kernel over every pixel of the image. At each position: multiply each kernel value by the pixel underneath it, sum all 9 products — that sum is the new pixel value. At the border the outermost pixel is replicated so nothing gets cut off.
  3. Divisor & offset — controlling brightnessAfter summing, the result is adjusted twice more: divided by the divisor (so a blur kernel with nine 1s doesn't make the image 9× as bright) and shifted by the offset (so e.g. the Emboss kernel slides up by 128 into the visible mid-grey range instead of clipping to black). The stats panel on the right shows both values live.
  4. CNNs learn the kernelsIn a CNN, humans don't fix the kernel values anymore — the network learns them automatically from training data. The first layer learns simple kernels like edges and corners. Later layers combine these into more complex features (textures, facial features, objects).

From this simple operation grows the whole art of image processing: Photoshop filters, edge detection in classical computer vision, and — most importantly — the foundation of modern AI image recognition. Same mathematics, whether you design a Sobel-X stencil by hand or a neural network trains millions of them automatically.

Convolution workshop

🖼️ Mission: Pick a source image, design a 3×3 stencil (kernel) — and watch edges, textures and patterns emerge live. Try a preset like Sobel or Blur.

What this demo shows

A filter is a tiny grid of nine numbers that travels across an image and redraws it bit by bit — depending on the numbers, the result turns soft, sharp-edged or embossed.

What you see
Two images side by side: on the left the original, on the right the filtered result, and between them a grid of nine numbers — the kernel. A glowing frame marks the small 3×3 window currently sitting on the image.
What happens
The window travels across the image pixel by pixel. Depending on the numbers in the kernel, the right image turns soft and blurred (blur), or the surfaces vanish and only bright outlines remain (edge filter, Sobel), or edges stand out harder (sharpen), or the motif looks pressed into stone in grey tones (emboss).
What you can do
Pick a motif on the left, tap one of the eight preset filters on the right, or type your own numbers into the grid. Press Play to let the window travel on its own; click the image to jump to any spot.
What to watch for
It is always the very same calculation — the nine numbers alone decide whether the image is blurred, broken into edges or embossed. Image AIs (CNNs) stack exactly these small filters on top of each other to learn how to see.

Pick a source image on the left, design a 3×3 stencil (kernel) in the middle — the result appears on the right. The default stencil is Sobel-X: it lights up vertical edges.

1 Source image

Pick a preset or upload your own image.

2 3×3 kernel

Each cell weights a neighbour pixel. Click in and edit values — result updates live.

+ positive (boosts) − negative (subtracts) • anchor (target pixel)

Presets

Advanced options
Normalize
Force the kernel sum to 1 — prevents brightness shifts.
Stack filters
Apply up to 3 filters in sequence — like a CNN layer stack.

3 Result

Live preview after applying the kernel.

Kernel sum 0
Divisor 1
Last compute0 ms

Live convolution — show me how it works

Click anywhere on the source image or start the animation. You'll see exactly how the kernel computes at one position: the 3×3 neighbours get multiplied by the kernel values, all 9 products are summed, divided by the divisor, and the offset added. That produces one single pixel in the output.

Speed: 4×
x=1, y=1

Tip: watch how Σ changes when the cursor passes an edge — for Sobel-X it jumps far positive or negative.

Image patch
000000000
Kernel
-101-202-101
Output pixel
Σ = 0 |Σ| / 1 + 0 → [0…255] 0

Play ideas — try these 5 challenges

  1. Set all 9 kernel values to +1 (all ones). That's Box-Sum, NOT Box-Blur. Observe: the image is massively over-bright. Now turn on "Normalize" in Advanced Options — boom, brightness back to normal. That's why we normalise.
  2. Sobel-X finds vertical edges, Sobel-Y finds horizontal. Which preset finds ALL edges at once — regardless of direction? (Hint: It's not Sobel-X+Sobel-Y, it's a different kernel.)
  3. Turn on "Stack filters". First add Gauss blur, then Sharpen. Compare against just-Sharpen. What do you see? Sharpening only brings back part of the detail the blur erased.
  4. Upload your own photo (or use the Portrait). Which preset looks best to you — and WHY? Pay attention to edges, textures, colour.
  5. In the Sobel-X kernel, change only the left column from -1, -2, -1 to -2, -4, -2. That's a stronger version. What happens? What does this teach us about scaling kernels?
TheoryPseudocodeStep by stepFlow diagram

What a convolution actually does

A convolution is a pointwise linear operation: for every output pixel you sum weighted contributions from a small neighbourhood of the source image. The weights live in a small matrix — the kernel.

Mathematically: out(x, y) = ΣᵢΣⱼ K(i, j) · I(x+i, y+j). For a 3×3 kernel, i and j range from −1 to +1. The resulting sum is optionally divided by a divisor (brightness preservation) and shifted by an offset (e.g. +128 for emboss, so negative differences remain visible).

Replicate padding at the border

At the image border, neighbour pixels are missing — the kernel hangs off the edge. Naive approach: insert zeros (zero-padding) → that produces black borders. Better: repeat the outermost pixel of the image (replicate). That's what this demo uses: no visible border artefact.

Complexity

  • Time: O(W · H · k²) per layer — a 3×3 kernel on a 192×192 image is roughly 330,000 multiply-adds. Under 10 ms on a modern CPU.
  • Memory: O(W · H) for the output buffer. Plus k² values for the kernel.
  • Parallelisable: every output position is independent — GPUs (and CNNs) process them all at once.

Classical applications

  • Edge detection: Sobel-X/Y, Laplacian — pre-processing for object recognition
  • Smoothing: box blur, Gaussian blur — reduce noise before other steps
  • Sharpening: unsharp masking
  • Embossing: relief-like effects
  • CNNs: the same operation, but the kernel values are learned — the foundation of modern computer vision

Try it in the demo! Set the kernel to Identity — the image stays unchanged. Click Sobel-X — suddenly vertical edges glow white on black. Edit individual cells — and see how tiny changes turn the result on its head.

Test your understanding

Question 1 / 4

What does an edge-detection kernel like Sobel-X fundamentally do?

Select one answer
Answer Key: 1) B · 2) C · 3) C · 4) C