Edge detector
An edge is an image location where intensity changes sharply in one direction. Edge detection is a fundamental image-processing operation, and its core ingredient — the image gradient — underlies corner detection, optical flow, and direct SLAM methods alike.
Grayscale and smoothing first
Edge detection (like most SLAM front-end processing) operates on grayscale images: gradients only need intensity, one channel is 3x faster to process than three, and color is inconsistent across lighting. The standard conversion is the luminance formula .
Since differentiation amplifies noise, images are smoothed before gradient computation with a Gaussian blur — convolution with the kernel
The choice of sets the scale of edges you detect: small preserves fine detail (and noise), large keeps only coarse structure.
Sobel operator
The Sobel operator computes image gradients via convolution with two kernels:
The gradient magnitude is , and the gradient direction is . Sobel combines differentiation (the pattern) with smoothing perpendicular to it (the weights), making it more noise-tolerant than naive finite differences.
Canny edge detector
The Canny detector is a multi-stage algorithm that turns raw gradients into thin, well-localized edge curves:
- Gaussian smoothing to suppress noise.
- Sobel gradient computation (magnitude and direction).
- Non-maximum suppression along the gradient direction, thinning ridges to single-pixel width: a pixel survives only if its magnitude exceeds both neighbours along the gradient.
- Hysteresis thresholding with a high and a low threshold: strong edges (above high) are kept, and weak edges (between low and high) are kept only if connected to strong ones. This preserves continuous contours while rejecting isolated noise responses.
import cv2
edges = cv2.Canny(gray, threshold1=50, threshold2=150) # low, high
Both detectors are one-liners in OpenCV (cv::Sobel, cv::Canny) and are worth implementing once from scratch to internalize how convolution and gradients work.
Common pitfalls
- Skipping the blur: Canny on a noisy raw image produces speckled, fragmented edges; tune (or the built-in aperture) together with the thresholds.
- Single-threshold thinking: the two Canny thresholds are the point of the algorithm — a lone threshold either fragments contours or admits noise; the low threshold should be a fraction of the high one.
- Edges are not features: an edge point can slide along its contour (the aperture problem), so it constrains geometry in only one direction — this is exactly why corners, not edge points, are matched as keypoints, and why edge-based SLAM treats edges as 1D constraints.
Why it matters for SLAM
Image gradients computed by Sobel are the input to the Harris structure tensor and to Lucas-Kanade optical flow, so edge detection is a stepping stone to the feature machinery of SLAM front-ends. Edges themselves are also used directly: line/edge features complement points in low-texture man-made environments (e.g., PL-SLAM), and direct methods such as LSD-SLAM implicitly rely on high-gradient (edge-like) pixels for photometric alignment.