Skip to main content

Crate lsdetect

Crate lsdetect 

Source
Expand description

A line segment detector (LSD) in Rust, with optional Python bindings.

Implements “LSD: a Line Segment Detector” (Grompone von Gioi et al., IPOL 2012) as an independent, permissively licensed implementation, plus a parallel perspective warp for applying the geometry the segments reveal and a coordinate-map remap for any other geometry.

// A vertical step edge through a 96x96 frame.
let mut image = vec![50u8; 96 * 96];
image.chunks_mut(96).for_each(|row| row[48..].fill(200));

let segments = lsdetect::detect(&image, 96, 96, lsdetect::SCALE)?;
let longest = segments.iter().max_by(|a, b| {
    a.length().total_cmp(&b.length())
});
assert!(longest.is_some_and(|s| s.angle().abs() > 88.0));

Structs§

Segment
One detected line segment, in input-image coordinates.
SizeMismatch
The pixel buffer does not match the stated dimensions.

Enums§

Filter
How the warp samples between source pixels.

Constants§

SCALE
Default working scale, shrinks the image first.

Traits§

Gray
A gray sample the detector can read.
Sample
An RGB sample depth the warp can resample.

Functions§

detect
Find the validated line segments of a grayscale image.
remap_gray
remap_rgb for a single-channel image, such as a mask that has to follow the geometry its picture went through.
remap_rgb
Resample an RGB image through a coordinate map: output pixel (x, y) takes its value from source position (map_x[y][x], map_y[y][x]), in source pixel units, sampled with the chosen filter. The maps are row-major out_width by out_height. Pixels whose source falls outside the image stay black.
warp_rgb
For output pixel (x, y) the source position is inverse * (x / scale + off_x, y / scale + off_y, 1), sampled with the chosen filter into an out_width by out_height frame. Pixels whose source falls outside the image stay black. inverse is the 9 row-major entries of the 3x3 matrix.