Computer Vision/Image Filtering with Hough Transforms
11 / 67

01/2024Computer Vision

Image Filtering with Hough Transforms

Detecting lines and corners with classical vision — Gaussian smoothing, Sobel gradients, the Hough transform, and the Harris corner detector.

╌╌╌╌

This pipeline builds classical edge and feature detection out of convolutions. Given an image, it smooths, estimates gradients, and votes for the geometric structures those gradients imply, lines and corners, all in Python over OpenCV.

Differentiation amplifies high-frequency noise, so Gaussian smoothing convolves the image with a Gaussian kernel first; without it, single-pixel intensity jumps register as spurious edges and swamp the real ones. The Sobel operator then estimates the intensity gradient with a pair of kernels, one per axis, giving at every pixel. Its magnitude measures edge strength and gives the edge orientation. Thresholding the magnitude leaves thick edge bands, so non-maximum suppression thins them: a pixel survives only when its magnitude exceeds both neighbors along the gradient direction, collapsing each band to a one-pixel ridge.

Every filter here is one primitive: the kernel slides over the image, and at each stop the output pixel is the kernel-weighted sum of the window it covers. A Gaussian kernel makes this smoothing; the Sobel pair makes it the image gradient.

The Hough line transform detects lines even when their pixels are broken or partly occluded. A line is written in normal form,

with the perpendicular distance from the origin and the angle of that perpendicular. This parametrization is bounded and avoids the infinite slope that hits on vertical lines. A fixed edge point swept over traces a sinusoid in space; collinear edge points share one line, so their sinusoids all pass through the single that names it.

Left: three collinear edge points in image space and the line through them. Right: each point maps to a sinusoid in space, and the three sinusoids meet at the single that names the shared line — the accumulator peak (dot).

Detection becomes counting: quantize into a grid (the accumulator ), and for each edge point add one vote to every cell on its sinusoid. Cells where many sinusoids cross collect high counts, and each such peak is a detected line. Real edges are noisy, so the votes smear across neighboring cells; peaks are recovered by thresholding and then a second non-maximum suppression over , so one line yields one detection instead of a cluster.

Algorithm:Hough-Lines(E)\textsc{Hough-Lines}(E) — vote for lines in (ρ,θ)(\rho, \theta) space
  1. 1
    input: a set EE of edge points, an accumulator AA over quantized (ρ,θ)(\rho, \theta)
  2. 2
    for each point (x,y)(x, y) in EE do
  3. 3
    for each θ\theta in the quantized range do
  4. 4
    ρxcosθ+ysinθ\rho \gets x \cos\theta + y \sin\theta
  5. 5
    A[ρ,θ]A[ρ,θ]+1A[\rho, \theta] \gets A[\rho, \theta] + 1
  6. 6
    return the (ρ,θ)(\rho, \theta) cells whose vote count exceeds a threshold

Harris corner detection finds points where intensity changes sharply in every direction. Over a window it forms the second-moment matrix of gradients

and scores each pixel by . Two large eigenvalues — variation along both axes — make large and mark a corner; a single large eigenvalue signals an edge, and neither signals flat texture.

You can read the full report.

References

  1. Project repository
  2. Reference notes: Vision and Perception

╌╌ END ╌╌