Edd's Knowledge Base

An edge is a place where intensity changes sharply. The image gradient measures that change: at each pixel it is a vector pointing toward the steepest increase in brightness. Edges, corners (Harris Corner Detector) and most feature detectors are built on gradients.

The Gradient

  • Magnitude says how strong the edge is.
  • Direction points across the edge, perpendicular to it.
  • A cheaper approximation of the magnitude is .

On discrete images derivatives are finite differences, which are computed by correlating the image with a small kernel (Cross-Correlation and Convolution).

Sobel Kernels

Absolute Sobel responses on a photograph. The two responses highlight different edge orientations, and the magnitude combines them.

Which kernel finds which edge? subtracts the pixels on its left from those on its right, so it responds to intensity change along x: it fires on vertical edges. differences up against down, so it fires on horizontal edges. A quick test: a kernel whose columns are antisymmetric, -1 0 1 across, is a horizontal derivative, hence a vertical-edge detector. The sign of the response depends on correlation vs. convolution and on whether points down, which is why the absolute value is displayed and the magnitude is unaffected.

Why it works well

  • Each kernel is separable: . It differentiates along one axis and smooths along the other with weights .
  • Smoothing makes it less noise-sensitive than a bare difference [-1, 1].
  • Divide by 8 to get a true derivative estimate in intensity units per pixel.
  • Flat regions give zero response, because each kernel’s weights sum to zero (Gaussian Filtering and Convolution).

Smooth First, Then Differentiate

Derivatives amplify noise: a single noisy pixel creates a large local difference. Pre-blurring with a Gaussian suppresses it, at the cost of fine edges. The scale sets which structures survive:

SmoothingResult
None or small Many thin, noisy edges, including texture
Moderate Clean edges of the main structures
Large Only the broad outlines, with blurred locations

Why does a difference amplify noise? Take two neighbouring pixels with independent noise of variance each. Their difference has variance , because variances of independent quantities add even when you subtract. The noise standard deviation grows by , and since neighbouring noise is independent it cannot cancel. Smoothing does the opposite: averaging independent values divides the noise variance by .

Smoothing and derivative filters are two different kinds of filter:

Smoothing filterDerivative filter
Weights sum to10
Frequency responseLow-passBand-pass or high-pass
Flat regionUnchangedZero response
Effect on noiseReduces itAmplifies it

Because convolution is associative, Gaussian smoothing followed by a derivative equals one filter, the derivative of a Gaussian. Border handling matters too: zero padding produces a false bright frame (Image Borders and Padding).

From Gradients to Edge Maps

Thresholding the magnitude gives thick edge bands. Thin, connected edges need extra steps, as in the Canny Edge Detector: smoothing, gradient, non-maximum suppression across the edge direction (Non-Maximum Suppression), and hysteresis thresholding.

Source: Sobel operator (Wikipedia).


Related: Computer Vision MOC, Harris Corner Detector, Cross-Correlation and Convolution, Corner Detection Snippets