Edge Detection

Image Processing with Edge Detection

Edge Detection is a fundamental image processing and classical computer vision technique that aims to identify points in a digital image where luminous intensity (brightness) changes abruptly. These changes generally correspond to physical object boundaries.

⚙️ How it works: Practical Context

Mathematically, edges are detected by calculating the image’s gradient, which measures the direction and rate of change in pixel intensity.

Most common classical algorithms:

  • Sobel: Applies simple convolution matrices to find vertical and horizontal gradients. Fast, but produces thick edges.
  • Canny Edge Detector: A more complex pipeline involving:
    1. Gaussian Blur to remove noise.
    2. Sobel gradient calculation.
    3. Non-Maximum Suppression to keep only the local maximum “ridge” of the edge (thinning it).
    4. Hysteresis Thresholding to discard false edges and connect true ones.

🧮 Mathematical Foundation (Image Gradient)

Given an image represented by a matrix AA, the Sobel operator approximates the derivatives using two 3×33 \times 3 convolution kernels, one detecting horizontal changes (GxG_x) and the other vertical changes (GyG_y):

Gx=[10+120+210+1]AandGy=[121000+1+2+1]AG_x = \begin{bmatrix} -1 & 0 & +1 \\ -2 & 0 & +2 \\ -1 & 0 & +1 \end{bmatrix} * A \quad \text{and} \quad G_y = \begin{bmatrix} -1 & -2 & -1 \\ 0 & 0 & 0 \\ +1 & +2 & +1 \end{bmatrix} * A

Eq. 1: Sobel operators for horizontal and vertical gradients.

The matrix GxG_x is designed to respond maximally to vertical edges, and GyG_y to horizontal edges. The symbol * denotes the 2D discrete convolution operation.

At each pixel, we calculate the gradient magnitude (the edge’s “strength”) by combining these two approximations:

G=Gx2+Gy2|G| = \sqrt{G_x^2 + G_y^2}

Eq. 2: Gradient magnitude.

Where:

  • G|G|: total gradient magnitude at the pixel.
  • GxG_x: gradient component in the horizontal direction.
  • GyG_y: gradient component in the vertical direction.

And the edge orientation (angle), which is crucial for the Non-Maximum Suppression step in Canny:

θ=arctan(GyGx)\theta = \arctan\left(\frac{G_y}{G_x}\right)

Eq. 3: Edge direction (angle).

Where:

  • θ\theta: edge orientation angle relative to the horizontal axis.
  • arctan\arctan: arc tangent, used to compute the angle from the gradient vector components.

With θ\theta, the algorithm checks the neighborhood along the gradient direction and discards the current pixel if it isn’t a local maximum, producing perfectly delineated thin edges.

🎯 When to use

  • Preprocessing for ML: Reduces data volume. Instead of a heavy RGB image, an object-detection model might receive the edge map to focus on geometry.
  • OCR (Optical Character Recognition).
  • Classical feature extraction for systems without Deep Learning.

⚠️ Trade-offs and Pitfalls: Because the gradient measures sudden variations, it is highly sensitive to high-frequency noise. Applying derivatives to un-smoothed images will result in false edges scattered everywhere. A Gaussian Blur is always applied beforehand.


Related: object-detection

Built with Eleventy · search by Lunr.js