Circle Hough Transform
Implement the Hough transform for circle detection, a technique used in computer vision to identify circular shapes in images. The goal is to detect circles of varying radii in an image by transforming the image into a parameter space where circles are represented as peaks.
The Hough transform is a feature extraction technique that uses a voting system to detect shapes, such as lines, circles, and ellipses, in an image. For circle detection, the parameter space is 3D, represented as , where is the center of the circle and is the radius. The equation of a circle is given by .
- For each edge pixel ,
- For each possible radius ,
- Vote for all centers on the circle,
- Find peaks in the accumulator space.
This technique is widely used in object detection and recognition applications.
Output
Return a list of (a, b, r, votes) tuples, where is the centre's column () and its row (), for every with at least threshold votes. Sort them by vote count, highest first, and return at most the 10 strongest.
Example
edges = binary image with circle edges r_min = 10, r_max = 50 threshold = 100
[(center_x, center_y, radius, vote_count), ...]
- Inputs:
edgesis an binary image (1 marks an edge),r_minandr_maxbound the radii tried (inclusive), andthresholdis the minimum vote count; results look like[(center_x, center_y, radius, vote_count), ...]. - Take a image whose 146 edge pixels trace a radius-20 circle around , with radii 15 to 25 and threshold 30.
- Edge pixel fits any centre with , a ring of radius around it; each cell on that ring gains a vote.
- At the rings cross near the true centre, but they only touch whole pixels, so not all meet in one cell: the peak is with 36 votes (one pixel off, as positions round down).
- Neighbour gets 18 and radii 19 or 21 reach at most 15, all under 30, leaving only .
- Notice: at
threshold = 100this circle would not be found, and an image with no edges gives an empty list.
Constraints
- edges: Binary edge image (H, W)
- r_min, r_max: Range of radii to detect
- threshold: Minimum votes to detect circle
- Return: List of (a, b, r, votes) detected circles