tezvyn:

Hough Transform: Finding Shapes by Voting

AI-drafted, machine-checkedSource: Wikipedia: Hough transformbeginner

The Hough Transform finds shapes by letting pixels "vote" for all lines or circles they could belong to. It's used to detect features like road lanes in noisy images.

WHY IT EXISTS Real-world images are noisy, and objects are often partially hidden or imperfect. Trying to match a perfect template of a line or circle will fail on a broken or distorted shape. The Hough Transform was created to find the general presence of a shape even in messy, incomplete data.

THE MENTAL MODEL Think of it as an election for shapes. Every edge pixel in an image is a voter. Instead of voting for one candidate, each pixel votes for every possible line that could pass through it. The lines that get the most votes from many different pixels are declared the winners—the ones that actually exist in the image. The "accumulator" is simply the ballot box where votes are tallied.

HOW IT WORKS The algorithm doesn't search the image for shapes directly. Instead, it works in a "parameter space." For a line, this space might represent every possible slope and intercept. Each edge pixel from the original image is converted into a curve in this parameter space, representing all possible lines it could be on. The points where many of these curves intersect are local maxima—peaks of votes. The coordinates of these peaks correspond to the parameters of the shapes detected in the original image.

WHEN TO USE IT Use this technique to detect simple geometric primitives like lines, circles, or ellipses in images that are noisy or have gaps. It's a classic tool in computer vision for tasks like lane detection in self-driving cars, finding circular pupils in biometrics, or identifying round objects on a conveyor belt.

WHEN NOT TO USE IT The Hough Transform is not designed for detecting complex, arbitrary shapes. It is also computationally intensive, and its cost grows with the complexity of the shape (e.g., a circle has 3 parameters, an ellipse has 5). If your image is clean and shapes are perfect, faster methods like template matching may be better.

ONE CANONICAL EXAMPLE To find lines in an image, we first find all the edge pixels. For each edge pixel, we plot a curve in a 2D parameter space of (rho, theta), which represent the line's distance from the origin and its angle. A point in this parameter space that has many curves passing through it corresponds to a line that has many edge pixels lying on it. This high-density point, or "peak," in the accumulator array reveals the detected line.

Read the original → en.wikipedia.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.