Nodes/comfyui_cv/CV Detect Line Segments (LSD)
ComfyUI Node

CV Detect Line Segments (LSD)

Line Segment Detector (cv2.createLineSegmentDetector): finds straight edge segments with SUBPIXEL endpoints and a measured width, in one pass, with no threshold to tune. Unlike cv2_HoughLinesP it works on the gradient field directly - no Canny step, no accumulator resolution, and each segment is a real, bounded piece of edge rather than a vote peak, so it does not fuse two collinear edges into one line. LSD is a cv2 class the raw wrappers cannot expose. Output is the same Nx4 (x1, y1, x2, y2) layout HoughLinesP produces, so 'CV Draw Segments' plugs straight in. Finding nothing is a valid result (count = 0, empty arrays), never an error.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Detect Line Segments (LSD)
  • image
  • segments
  • widths
  • lengths
  • nfa
  • count
refinestandard
scale0.80
sigma_scale0.60
quant2.0
angle_tolerance22.5
density_threshold0.70
min_length0
log_eps0.0
bins1024
Categoryimage/CV/features

Inputs (10)

NameTypeDefaultDescription
imageNPARRAY,IMAGEImage to search (converted to grayscale internally); feed the ORIGINAL image, not an edge map. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
refineCOMBOstandardRefinement level. 'standard' splits arcs and refines endpoints; 'advanced' additionally validates each segment with the NFA (number of false alarms) test and fills the 'nfa' output; 'none' is the raw, fastest pass.
scaleFLOAT0.800.1–2Image is downscaled by this factor before detection. Below 1.0 suppresses noise and speeds things up; 1.0 keeps full resolution and finds more short segments.
sigma_scaleFLOAT0.600.1–2Gaussian blur sigma used for the downscale, expressed as sigma = sigma_scale / scale.
quantFLOAT2.00–20Bound on the gradient quantisation error; raise it on noisy or heavily compressed images.
angle_toleranceFLOAT22.51–90Gradient angle tolerance in DEGREES for pixels to join the same line-support region.
density_thresholdFLOAT0.700–1Minimum density of aligned pixels inside a segment's enclosing rectangle; lower accepts sparser segments.
min_lengthoptFLOAT00–10000Post-filter: drop segments shorter than this many pixels. 0 keeps every segment. LSD has no length knob of its own, and short segments are what clutters a result.
log_epsoptFLOAT0.0-10–10Detection threshold for the 'advanced' NFA test: -log10(NFA) > log_eps. Only used when refine is 'advanced'.
binsoptINT10241–8192Number of bins in the gradient-modulus pseudo-ordering.

Outputs (5)

NameTypeDescription
segmentsNPARRAYNx4 float32 (x1, y1, x2, y2) subpixel endpoints - feed 'CV Draw Segments' directly.
widthsNPARRAY(N,) float32 measured width of each segment in pixels.
lengthsNPARRAY(N,) float32 segment length in pixels - use it with a comparison node to keep only the long structural edges.
nfaNPARRAY(N,) float32 -log10(number of false alarms) per segment (higher = more certain). All zeros unless refine is 'advanced', which is the only mode that computes it.
countINTHow many segments survived - branch on it with if/else for the nothing-found case.