Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Hough Transform

Hough transform is a voting-based computer vision technique that detects lines, circles, and shapes, even with gaps or noisy image edges.

The Hough transform is a geometric feature-extraction technique that detects lines, circles, and other parameterized shapes by letting image points vote for possible shapes. Points belonging to the same structure reinforce one another, producing a strong peak in a voting table. In computer vision, this helps recover shapes with gaps or noisy boundaries.

Paul V. C. Hough introduced the technique in 1959 in Machine Analysis of Bubble Chamber Pictures, addressing particle tracks in physics photographs. Richard Duda and Peter Hart introduced the widely used angle–distance representation in their 1972 line-and-curve detection paper.

How Hough Voting Works#

A typical workflow starts with data preprocessing and edge detection. An edge detector identifies local brightness changes; the Hough transform groups edge pixels into geometric structures. The Sobel operator estimates brightness gradients, while Canny produces a thin edge map suitable for line voting.

Each candidate line is represented by rho, its signed perpendicular distance from the image origin, and theta, the angle of that perpendicular relative to the x-axis. This handles vertical lines without an infinite slope. Every edge pixel votes for compatible rho–theta pairs in an accumulator, a table dividing parameter space into discrete bins. Collinear pixels contribute to the same bin, even when separated in the image. Peaks identify supported lines.

Geometry and voting rules determine the output. A deep learning detector learns visual patterns from training data; Hough detection uses a chosen shape model and numerical thresholds rather than learned model weights.

Line, Probabilistic, and Circle Transforms#

Three common implementations differ in their search and output:

  • Standard line transform: cv2.HoughLines() returns rho–theta pairs describing infinite lines. Segment endpoints require additional processing.
  • Probabilistic line transform: cv2.HoughLinesP() reduces voting work through point sampling and returns segment endpoints directly. minLineLength rejects short segments; maxLineGap controls how far apart aligned pieces may be joined.
  • Circle transform: Circle candidates require a center and radius. cv2.HoughCircles() uses a gradient-based approach, with radius limits narrowing the search. Its input is grayscale, whereas the line functions take a binary image.

Detecting Line Segments in Python#

Install the dependencies with pip install opencv-python numpy. This example uses OpenCV to detect and draw line segments in the bus sample image.

from urllib.request import urlopen

import cv2
import numpy as np

with urlopen("https://ultralytics.com/images/bus.jpg") as response:
    encoded = np.frombuffer(response.read(), dtype=np.uint8)
image = cv2.imdecode(encoded, cv2.IMREAD_COLOR)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Extract edges for voting.
edges = cv2.Canny(gray, 50, 150)
# Detect finite segments supported by accumulator votes.
lines = cv2.HoughLinesP(
    edges,
    1,
    np.pi / 180,
    threshold=80,
    minLineLength=80,
    maxLineGap=10,
)
if lines is not None:
    for x1, y1, x2, y2 in lines[:, 0]:
        cv2.line(image, (x1, y1), (x2, y2), (0, 0, 255), 2)
cv2.imwrite("hough_segments.jpg", image)

The saved image overlays returned segments in red. Rho bins are one pixel wide, theta bins span one degree, and threshold=80 sets the accumulator vote threshold. Segment-length and gap settings are measured in pixels.

Applications and Practical Limits#

In document processing, extracting grid lines supports structural analysis: OpenCV demonstrates Hough detection on a Sudoku image. Circular voting locates coin centers and radii in scikit-image's circle-and-ellipse examples. These outputs describe geometry; object detection adds semantic categories, and instance segmentation assigns pixels to individual objects.

A steel-beam measurement prototype combines YOLOv8 masks, Canny edges, and probabilistic Hough lines to support corner extraction. Ultralytics YOLO26 segmentation provides masks for object isolation, enabling the same masked-input approach before separate geometric processing.

Finer accumulator bins increase memory use; coarse bins merge nearby candidates. In table-boundary extraction, incomplete borders reduce detectable boundaries, while unrelated lines can produce incorrect boundary corrections. Increasing maxLineGap joins larger breaks between aligned pieces; increasing minLineLength removes shorter segments.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning