Robot Eyes
Hi! You see a picture. I see lots and lots of numbers. Drag the square on the picture to peek through my magnifying glass!
Part 1 · Pictures are made of numbers
Part 2 · Magic glasses (filters)
Layer 1 finds lines · Layer 2 mixes them to find corners
Part 3 · How do the glasses work?
The glasses slide a little 3×3 window over the numbers. At each spot: multiply each pair, then add them all up. That's one new number!
Picture numbers
Multiply & add
New picture
How it works
Pixels
A picture is a grid of tiny squares. Each square is just 3 numbers: how much red, green and blue light.
Glasses
A filter is a tiny 3×3 recipe of numbers. It slides over the picture and makes a new one that shows just edges, or blur.
Stack them
Robots stack lots of glasses. First edges, then corners, then eyes and wheels, then whole cats and cars!
Learn the recipe
The cool part: real vision brains aren't told the recipes. They learn the best 9 numbers from millions of photos.
What just happened?
- You zoomed in until the picture turned into tiny squares, and each square into 3 numbers (red, green, blue).
- You tried on magic glasses: 9 numbers that slide over the picture and make a new one showing edges, blur or sharpness.
- You watched the 3×3 window multiply and add, one spot at a time — that's a convolution.
- Stacking glasses turned lines into corners. Real vision brains stack many layers and learn their own recipes.
For grown-ups: what's really going on
- An RGB image is a tensor of shape
H × W × 3with values 0–255. The "Numbers" count is literallyH·W·3. - Each pair of "glasses" is a convolution kernel (strictly a cross-correlation, as in deep-learning libraries):
out[y,x] = Σᵢⱼ K[i,j] · in[y+i, x+j], here with a 3×3 kernel, stride 1, and edge pixels clamped. - The edge kernels are Sobel operators. "All edges" is the gradient magnitude
√(Gx² + Gy²)computed on luminance0.299R + 0.587G + 0.114B. Blur is a 3×3 Gaussian approximation (÷16). - "Stack the glasses" mimics a two-layer CNN: layer 1 gives two feature maps (|Gx|, |Gy|); layer 2 blurs and multiplies them, which lights up where both directions are present — corners and diagonals. It resembles the structure tensor used in the Harris corner detector.
- In a real CNN the kernel weights are learned by gradient descent, there are dozens to hundreds of kernels per layer, each spanning all input channels, with a nonlinearity (ReLU) and pooling in between. Early layers famously end up looking like these hand-made edge detectors.
- Everything here runs on plain Canvas
getImageDataloops — no library. Further reading: CNN Explainer (Polo Club), Image Kernels explained visually.