LSD: a Line Segment Detector

Rafael Grompone von Gioi, Jérémie Jakubowicz, Jean-Michel Morel, Gregory Randall

LSD is a high-speed, linear-time algorithm designed to detect line segments in digital images with subpixel accuracy. Its primary innovation is being completely "automatic"—it requires zero parameter tuning. By employing a statistical "a contrario" validation method, LSD filters out noise and ensures that, on average, no more than one false detection occurs per image.

The Challenge of Robust Line Detection

Detecting straight lines is a foundational task in computer vision, yet achieving robustness across diverse image types is difficult. Traditional methods often rely on manual thresholds for edge strength, line length, or connectivity. A configuration optimized for high-contrast architectural photography frequently fails on noisy medical scans or low-contrast natural scenes.

The authors developed LSD to be:

  1. Fast: Operating in $O(N)$ time relative to the number of pixels.
  2. Accurate: Providing subpixel precision.
  3. Autonomous: Controlling its own "false alarm" rate without user intervention.

Methodology

The LSD pipeline combines geometric region growing with statistical validation to identify meaningful structures.

1. Pre-processing and Gradient Computation

The input image is first scaled to 80% of its original size to mitigate "staircase" aliasing artifacts common in digital sensors. The algorithm then computes the "level-line angle"—the direction tangent to the image gradient—at every pixel using a 2x2 mask.

Definition of level-line and gradient direction at an edge.

2. Region Growing and Approximation

Starting with pixels exhibiting the highest gradient magnitude, LSD groups neighboring pixels with similar level-line angles into "line support regions." Each region is then modeled as a rectangle, where the center of mass and principal inertial axis define its position and orientation.

The LSD pipeline: from the input image to the level-line field and the resulting line support regions.

3. A Contrario Validation

The core innovation is the use of the Helmholtz Principle. The algorithm assumes that a "meaningful" structure is one that is highly unlikely to occur by pure chance in a noise image. LSD calculates a "Number of False Alarms" (NFA) for each candidate rectangle. If the NFA is low (typically $\le 1$), the rectangle is accepted. If it fails, the algorithm attempts to refine the rectangle by testing finer angle tolerances or reducing its width to find a significant core.

Key Insights

  • Statistical Thresholding: Instead of defining a detection by its "strength," LSD defines it by its "rarity" in a random noise model. This provides a mathematically grounded, automatic threshold.
  • Linear Complexity: By using a "pseudo-ordering" (sorting pixels into 1024 bins based on gradient magnitude), the algorithm avoids the $O(N \log N)$ cost of a full sort.
  • Directional Sensitivity: LSD distinguishes between "dark-to-light" and "light-to-dark" transitions, providing directional information useful for higher-level scene understanding.
  • Optimal Scaling: The 80% downsampling factor is a "sweet spot" that removes pixel-level artifacts which would otherwise fragment single straight lines into many tiny horizontal/vertical fragments.

Results and Limitations

LSD is extremely efficient and robust. In tests on pure white noise, it correctly produces zero detections. By utilizing the gradient field rather than binary edges, it achieves precision beyond the pixel grid. The same internal constants worked across vastly different image types, from architectural photography to scanned documents.

However, LSD has limitations:

  • Curvature: It is strictly a line detector. It approximates curves with short segments, but high curvature or very short segments may fail the statistical significance test.
  • Grayscale Dependency: The current implementation operates on grayscale. Color transitions with identical luminance (e.g., certain red/green boundaries) may be missed entirely.
  • Low Contrast: Soft gradients, such as those in shadows, may not provide enough alignment to pass the NFA threshold despite human perception.

Summary updated

BibTeX
@article{gioi2012lsd,
  author = {Rafael Grompone von Gioi and Jérémie Jakubowicz and Jean-Michel Morel and Gregory Randall},
  title = {{LSD: a Line Segment Detector}},
  journal = {Image Process. Line},
  year = {2012},
  doi = {10.5201/ipol.2012.gjmr-lsd},
}
Figure