Edge Detection, pixel by pixel


Image
Filter
Show the output as
Slide the filter
Input — what the filter sees: one brightness per pixel, 0 (black) to 255 (white).
Output — the feature map. One number per position of the filter.
3×3 patch of the image
×
the filter (edit any number)
=
nine products
→
add them up

The whole idea.
A filter is a small grid of numbers — here 3×3, so nine weights. Lay it over a 3×3 patch of the image, multiply each pixel by the weight on top of it, and add the nine products. That one number is one pixel of the output. Slide one pixel to the right and do it again, with the same nine weights, until the filter has visited every position.

Look at Vertical edges: the left column is negative, the right column positive, the middle zero, and the nine weights add up to 0. On a patch of one flat brightness the negatives and positives cancel and the sum is exactly 0. Only where the right side is brighter or darker than the left does anything survive. That is an edge detector.

Where the CNN comes in.
A convolutional layer is exactly this, with one difference: nobody types the nine numbers in. They start out random and training adjusts them, and a layer runs many filters side by side, each producing its own feature map. The first layer of a trained image network typically ends up with filters that look a lot like the ones on this page — nobody told it to look for edges.

(Strictly, sliding a filter without flipping it is cross-correlation; the textbook convolution flips the kernel first. Deep-learning libraries do it this way and call it convolution anyway.)

Things worth trying:
1. House, Vertical edges, Whole image at once. The walls, the door and the sides of the windows light up; the long horizontal lines — the ground, the eaves, the window sills — disappear. Switch to Horizontal edges and they trade places. The roof is slanted, so it shows up in both.

2. Still on the House, click anywhere in the plain sky. The patch is nine identical numbers, and the sum comes out exactly 0.

3. Vertical edges again, shown Signed. The two sides of the door come out in opposite colors: reading left to right, light-to-dark is negative and dark-to-light positive. Now pick ReLU, which is what a CNN applies after every filter — half of the edges vanish. To see both, a network needs a second filter with the signs flipped.

4. Pick Do nothing and type a different number somewhere in the grid. Every filter is just nine numbers; there is nothing else to it. Then try Your own image — it stays in your browser and is never uploaded anywhere.