Skip to content
AI360XpertBeta
Computer Vision

Visual explainer

Hough Transform for Lines and Circles

Turn edge pixels into votes for line parameters or circle centers, inspect accumulator peaks, and see how discretization and accidental alignment mislead.

Gather Edge Evidence

Separated edge pixels can support one common line.
Separated edge pixels can support one common line.

The Hough transform detects geometric shapes by letting edge pixels vote for compatible parameters. Several separated pixels can support the same line even when the boundary is broken. Here image x increases rightward and y downward; points (0,2),(1,1),(2,0) all satisfy x+y=2.

The paired scenes keep the same scale. The highlighted line is inferred support, not newly measured pixels. Edge detection supplies candidate locations; a filled object's interior should not vote indiscriminately.

Describe A Line Normally

Rho is the perpendicular distance from the origin to a line.
Rho is the perpendicular distance from the origin to a line.

OpenCV's line-transform documentation uses the normal equation rho=x cos(theta)+y sin(theta). Theta is the normal's angle, not the line's slope angle. With image y downward, positive angles turn clockwise from the rightward x axis.

For x+y=2, theta is 45° and rho is 2/√2=√2. The normal meets the line at (1,1); its length is sqrt(1²+1²)=√2. The little corner marks perpendicularity. Normal form handles vertical lines without an infinite slope.

Let One Pixel Vote

One edge pixel votes for a family of possible lines.
One edge pixel votes for a family of possible lines.

A single pixel cannot choose a unique line. Pixel (1,1) supports rho=cos(theta)+sin(theta): at 0°, 45°, 90°, 135° and 180°, rho is 1,√2,1,0,−1. The plotted dots are those exact samples; straight links only guide the eye along the underlying sinusoid.

Parameter theta grows rightward, rho upward; this parameter plot differs from image coordinates. The drawing uses signed rho and a half-turn theta interval. The endpoint 180° only illustrates the boundary: implementations typically exclude it because it duplicates a line under a sign change.

Find Shared Votes

Collinear pixels cast coincident votes for the same line parameters.
Collinear pixels cast coincident votes for the same line parameters.

Solid A is pixel (0,2), dashed B is (1,1), dotted C is (2,0). All give rho √2 at 45°, so their vote curves cross at the highlighted parameter pair. The three individual pixels have become three votes for one candidate line.

The sampled curves share the same theta and rho scales. Their intersection is the evidence; a scene-space crossing of arbitrary lines would teach a different mechanism. With noise and finite bins, votes cluster around a peak rather than meeting exactly.

Quantize The Accumulator

Quantization sends nearby parameter votes into the same accumulator bin.
Quantization sends nearby parameter votes into the same accumulator bin.

An accumulator is an array of vote counts over parameter bins. This close-up holds theta fixed and uses rho bins of width 0.1. Values 1.40 and 1.44 both round to bin index round(rho/0.1)=14, centered at 1.4. The two tick marks inside the bin are counts, not new spatial coordinates.

Coarse bins can combine different lines; fine bins can spread noisy support across neighbors and require more memory. Angular quantization also matters, especially for long lines. Exact tie rules at bin boundaries are implementation choices; neither value here is on a tie.

Require Enough Support

A minimum-support rule keeps strong accumulator peaks.
A minimum-support rule keeps strong accumulator peaks.

These three candidate bins have 1, 3 and 2 votes, with equal height per vote. Our illustrative rule accepts counts at least 3, keeping B. This is a stated teaching rule, not a claim about every API's strict-versus-inclusive threshold comparison.

Increasing a threshold suppresses weak clutter but also loses short or occluded boundaries. A vote count is evidence of geometric agreement, not a calibrated probability of a real object.

Separate Lines From Segments

A supported infinite line can contain separate finite edge segments.
A supported infinite line can contain separate finite edge segments.

The top line has edge positions 0,1,2,6,7 along it. The bottom keeps two finite runs, from 0 to 2 and from 6 to 7, on the identical coordinate scale. Their endpoint gap is 4 units; sharing a line does not fill it with measured support.

Standard line Hough returns line parameters. Segment detectors such as probabilistic Hough also use length and gap rules. Joining across too large a gap invents continuity; requiring no gaps loses broken boundaries.

Vote For Circle Centers

At a fixed radius, circle-edge pixels vote along circles of possible centers.
At a fixed radius, circle-edge pixels vote along circles of possible centers.

Change to a circle fixture with known radius 2 and edge pixels (2,0),(0,2),(−2,0). Each pixel can belong to any radius-2 circle whose center is distance 2 away. Its possible centers therefore form a circle in center-parameter space around that pixel.

The solid, dashed and dotted loci meet at the outlined center (0,0). These are candidate-center loci, not three detected image objects. A general circle has three parameters: center x, center y and radius. This image is one fixed-radius slice.

Estimate The Radius

Distances from a candidate center can reveal a supported circle radius.
Distances from a candidate center can reveal a supported circle radius.

Given center (0,0), four edge points (±2,0),(0,±2) have distance 2; an outlier (3,0) has distance 3. The distance histogram has counts 4 at radius 2 and 1 at radius 3. Equal stem height per supporting point makes the radius-2 peak visible.

OpenCV's circle tutorial describes its gradient method as finding candidate centers and then radii. It is more selective than exhaustively filling a three-dimensional array. This simple distance vote illustrates the second-stage evidence; it is not a complete implementation of that method.

Where It Breaks

Unrelated aligned edges can create a strong Hough peak without one real object.
Unrelated aligned edges can create a strong Hough peak without one real object.

Four corners from independent shapes happen to share a row. They support the dashed amber line, although no continuous physical boundary connects them. Raising the threshold may retain this false line while discarding a shorter real one.

Hough voting tolerates missing edge samples at the cost of accumulator work, quantization and false geometric consensus. Restrict parameter ranges, check segment support, or add appearance and scene constraints when the task needs object identity. Use a detector trained for the relevant object classes when shape alone cannot settle the question.

The Quick Version

  • Edge locations vote for compatible geometric shapes.
  • Rho is perpendicular distance; theta specifies the normal direction.
  • One pixel supports many possible lines.
  • Collinear pixels agree on shared line parameters.
  • Finite parameter bins merge nearby votes.
  • Support thresholds trade weak detections against clutter.
  • Infinite line agreement does not establish a continuous segment.
  • Known-radius edge pixels vote along possible-center circles.
  • Distances from a candidate center support radius selection.
  • Accidental alignment can produce a strong false peak.