Lite / Intelligent Robotic Systems / Week 25
Edge detection with Sobel
Outlines are where brightness changes fastest. How do you measure 'change' in a grid of numbers?
Why should I care?
Edges outline objects, mark lane lines and show where a part ends. Edge detectors are some of the oldest and most reliable tools in robot vision, and they are a direct use of a derivative on sampled data.
- Explain an edge as a large brightness gradient and how Sobel kernels estimate it.
- Combine x and y responses into a gradient magnitude.
- Explain why blurring before edge detection helps with noise.
Predict
Sobel x is applied to a perfectly flat grey region. What is the output?
- 0
- 255
- The grey value
Guess first, then reveal
Sobel's weights add to zero, so a flat region gives exactly 0. It only responds where the brightness changes from left to right.
Discover
Choose Kernel then Sobel x on the Bright square: which edges light up? Switch to Sobel y. Then try both on the Gradient and on the Noisy bar. Click a pixel on an edge and one inside the square and compare the sums.
What the interactive shows (text version)
With Sobel x on the Bright square, the output is large at the square's left and right sides (positive on the left edge, where brightness rises to the right, and negative on the right edge) and 0 inside and outside. Sobel y responds to the top and bottom edges instead. On the Gradient, Sobel x gives a constant 240 (8 × the slope of 30 per column) except at the borders.
Watch (optional)
Watch for: Watch how the two Sobel results are combined into one edge strength, and why the result is noisy without a blur first.
Shows how two small kernels measure brightness change across and down an image, and how they combine into an edge map.
“Finding the Edges (Sobel Operator) - Computerphile” by Computerphile (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
Edges are gradients
Along a row, a sharp jump in brightness is a large difference between neighbouring pixels: a discrete derivative. Sobel x [[−1, 0, 1], [−2, 0, 2], [−1, 0, 1]] subtracts the left column from the right, giving extra weight to the middle row. Large positive or negative values mark vertical edges; Sobel y does the same for horizontal edges.
Strength and direction
Combine the two responses into the gradient magnitude √(Gx² + Gy²): how strong the edge is, whatever its direction. The angle atan2(Gy, Gx) gives the direction brightness increases. Threshold the magnitude to get an edge map.
Noise is the enemy
Differences amplify noise: two noisy neighbours differ even on a flat surface. Sobel's three-row design already averages a little; blurring first (often with a Gaussian) helps more. It is the image version of the warning that differentiating noisy data makes it noisier.
Explain it another way
Intuitive
Run your finger across a page in the dark: edges are where the height suddenly changes. Sobel feels for sudden brightness changes.
Technical
Sobel = (smoothing [1, 2, 1]ᵀ) ⊗ (central difference [−1, 0, 1]). Gradient magnitude |∇I| ≈ √(Gx² + Gy²); the Canny detector adds blur, thinning and two-level thresholding on top.
Mathematical
For a linear ramp I(x) = a·x, Sobel x gives (1 + 2 + 1) × (a·(x + 1) − a·(x − 1)) = 8a: proportional to the slope a.
Applied
Lane-keeping assistants have used edge detection on road images to find painted lines; rain, glare and worn paint are exactly the noise and contrast problems this lesson describes.
Worked example 1
At a pixel, Gx = 120 and Gy = −50. Find the edge strength.
√(120² + 50²) = √(14400 + 2500) = √16900 = 130.
Common mix-ups
Edge detectors find objects.
✓ They find brightness changes: shadows, reflections and texture produce edges too. Deciding which edges belong to objects is a later step.A negative Sobel value means no edge.
✓ The sign gives the direction of the change; the size gives its strength.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Run Sobel x and y on a photo of a doorway, compute the magnitude, threshold it at three values and report how many edge pixels each leaves. Repeat after a 3×3 blur and explain the difference.
Reflect
Where in a real scene would strong edges appear that do not belong to any object?
Write your answer on paper or in your own notes. Lite never stores what you write.