Multimedia & Machine Learning Algorithms · Multimedia Algorithms
Edge Detection in Images — Gradient and the Sobel Operator
Explanation
Intuition: What is an Edge?
An edge in an image is a location where brightness changes abruptly — such as the border between a bright object and a dark background.
Mathematically, an abrupt change = a large derivative.
Core idea: An image is a function returning an intensity value (0–255) at each pixel .
An edge = a location where the gradient is large.
Image Gradient
For an image we define the gradient:
- — rate of change in the horizontal direction (detects vertical edges)
- — rate of change in the vertical direction (detects horizontal edges)
Edge strength (gradient magnitude):
Gradient direction (perpendicular to edge):
( instead of handles all quadrants correctly; the edge direction itself is )
The Sobel Operator — Numerical Derivative Approximation
A discrete image has no continuous derivative; we use finite differences.
The Sobel operator computes a weighted approximation via cross-correlation:
For a pixel whose neighborhood is :
Why the weights 1, 2, 1? The middle row gets double weight () as a Gaussian smoothing perpendicular to the derivative direction — this reduces sensitivity to noise.
Non-Maximum Suppression (NMS)
After computing at every pixel, keep only those that are a local maximum along the gradient direction.
This produces thin edges (one pixel wide).
Canny Algorithm — Four Steps
1. Gaussian smoothing: to reduce noise.
2. Sobel: compute , , , at every pixel.
3. NMS: retain only local maxima along the gradient direction.
4. Hysteresis thresholding: two thresholds :
- strong edge (confirmed)
- weak edge (confirmed only if connected to a strong edge)
- suppressed
Interactive Visualization
Loading visualization
Worked Examples
Practice
Exercise 1 of 6
1
Compute for the following neighborhood using the Sobel kernel:
★Quiz
Test your knowledge from this lesson
A mix of questions from the lesson — each attempt varies slightly
Answer at least 4 out of 5 questions correctly to pass (70%)