Filter: identify edges in images
Be able to apply a simple filter to an image and understand how edges emerge.
Prerequisites
- ADigital images and pixelsrequired
Everyday explanation
An edge in an image is a place where brightness changes rapidly — from dark to light.
Here is how you identify them: compare each pixel with its neighbour. Is the difference large? Then there is an edge. Is the difference zero? Then the surface is uniform.
A filter performs this comparison automatically across the entire image. The filter [−1, 1] means: “take the value on the right minus the value on the left”.
Interactive
Calculate by hand. A row of pixels (0 = black, 9 = white):
0 0 0 9 9 9
The filter [−1, 1] slides across and calculates right minus left:
0−0=0 0−0=0 9−0=9 9−9=0 9−9=0
Result: 0 0 9 0 0. Only one spot has a high value — exactly where the edge is.
Try it yourself with the row 0 9 0 9 0 9 (stripes). What do you get? 9 −9 9 −9 9 — everything is an edge. And with 5 5 5 5 5 (uniform grey)? Only zeros — no edge anywhere.
This is exactly what the first layer in a CNN does, except in two dimensions and with weights that the network has learned itself.
Mastery means
- Applies a small filter to a grid of values
- Explains why edges appear in the result
Sign in to do the exercises and build your mastery up.
Sources
- CS Unplugged (CC BY-SA 4.0) — CC BY-SA 4.0
- CS231n — Convolutional Networks — free to read