Understanding AI · lesson 34 of 60 · about 6 minutes
Spotting Edges
The first thing picture AI learns to find is edges. See how comparing neighbouring pixels reveals them.
What you'll learn
- Explain what an edge is in pixel numbers
- Find an edge by comparing neighbouring pixels
- Explain why edges are a useful first step
Edges are big jumps
An edge is where the picture changes suddenly, like the outline of a black cat against a white wall. In numbers, that's where neighbouring pixels are very different.
To find edges, take each pixel's difference from its neighbour. Small differences mean smooth areas; big differences mean an edge.
One row of pixels: dark on the left, bright on the right. The big difference shows where the edge is.
row = [10, 12, 11, 200, 205, 203]
for i in range(len(row) - 1):
print(abs(row[i + 1] - row[i]))Output
2
1
189
5
2The network's first trick
Picture networks learn to do this by themselves in their first layer: small sets of weights that respond strongly to sudden changes. Outlines of things are mostly edges, so it's the perfect starting point for recognising anything.
Tip
A big jump between neighbours is an edge. A small jump is a smooth area.
Now try it yourself
This lesson is free in Codiqo, with 5 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.