Find Hough Peaks
Implement a function to find the top-k peaks in a Hough accumulator, which represents the parameter space of lines in an image. The goal is to identify the most prominent lines, characterized by their Hough transform parameters and , where is the angle and is the distance from the origin.
The Hough transform is a feature extraction technique used to detect lines in images by transforming the image into a parameter space, where each cell represents a line in the original image. Peaks in the accumulator correspond to lines that received the most votes from edge points, indicating their presence in the image.
To find these peaks, follow these steps:
- Collect all cells with their values and coordinates
- Sort by vote count (descending)
- Return the top k pairs
This technique is widely used in computer vision applications for line detection and image analysis.
Example
accumulator = [[1, 2, 1],
[3, 1, 3],
[1, 5, 1]]
k = 2[(2, 1), (1, 0)]
Flattening with coordinates: (0,0)=1, (0,1)=2, (0,2)=1 (1,0)=3, (1,1)=1, (1,2)=3 (2,0)=1, (2,1)=5, (2,2)=1
Sorting by value (descending):
- (2,1)=5
- (1,0)=3
- (1,2)=3
- (0,1)=2 ...
Top 2: [(2, 1), (1, 0)] Note: (1,0) and (1,2) tie at 3, but (1,0) comes first due to smaller rho_idx.
Constraints
- accumulator is a 2D array (theta_bins × rho_bins)
- k is the number of peaks to find
- Return list of (theta_idx, rho_idx) tuples
- Sorted by votes (highest first)
- If tied, prefer smaller theta_idx, then smaller rho_idx