Nodes/comfyui_cv/CV Edge Drawing
ComfyUI Node

CV Edge Drawing

Edge Drawing (cv2.ximgproc.createEdgeDrawing): a cv2 CLASS the generated wrappers cannot reach. Instead of thresholding a gradient like Canny, it picks ANCHOR pixels at gradient maxima and walks the ridge between them, so the edge map is one-pixel-wide and already CHAINED - you get the edge SEGMENTS as ordered point runs (CV_CONTOURS), not a pile of lit pixels you have to trace yourself. On top of those chains it fits straight LINES (Nx4, same layout as HoughLinesP / LSD / FLD) and CIRCLES + ELLIPSES (EDCircles), which is the one thing the other line detectors here cannot do. Nothing found is a valid result: every output comes back empty, never None.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Edge Drawing
  • image
  • edge_map
  • gradient
  • segments
  • lines
  • ellipses
  • segment_count
  • line_count
  • ellipse_count
operatorPrewitt
gradient_threshold20
anchor_threshold0
scan_interval1
min_path_length10
sigma1.0
min_line_length-1
pf_modefalse
nfa_validationtrue
sum_flagtrue
line_fit_error1.0
max_distance_between_two_lines6.0
max_error_threshold1.3
Categoryimage/CV/contrib

Inputs (14)

NameTypeDefaultDescription
imageNPARRAY,IMAGEImage to trace (converted to grayscale internally). Feed the ORIGINAL image, not an edge map - ED computes its own gradient. 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.
operatorCOMBOPrewittGradient operator. Prewitt (cv2's default) and Sobel are 3x3; Scharr is the more rotation-accurate 3x3 kernel; 'LSD' switches the whole line stage to the LSD-style detector.
gradient_thresholdINT201–255Pixels with a gradient below this can never be part of an edge. This is the ONE knob that decides how much low-contrast detail is traced; lower = more edges and more noise.
anchor_thresholdINT00–255How much a pixel must exceed its neighbours along the gradient to become an ANCHOR (a seed the tracing starts from). 0 anchors every local maximum, which is cv2's default; raising it thins the result to the strongest edges.
scan_intervalINT11–32Anchors are only looked for every Nth row/column. 1 scans everything; higher is faster and misses short edges.
min_path_lengthINT100–10000Edge chains shorter than this many pixels are dropped - the declutter knob for the SEGMENTS output.
sigmaFLOAT1.00–10Gaussian blur applied before the gradient. Raise it on noisy images; 0 disables the smoothing.
min_line_lengthoptINT-1-1–10000Shortest line the line stage will fit, in pixels. -1 (cv2's default) derives it from the image size.
pf_modeoptBOOLEANfalseParameter-Free mode: ED validates every edge with the Helmholtz principle instead of the gradient threshold, so the result stops depending on the knobs above. Slower, and the usual choice when you are after ELLIPSES.
nfa_validationoptBOOLEANtrueValidate fitted lines and ellipses with the number-of-false-alarms test. Off returns more, less trustworthy fits.
sum_flagoptBOOLEANtrueGradient magnitude as |gx| + |gy| (on, cv2's default) instead of the exact hypot.
line_fit_erroroptFLOAT1.00–10Maximum RMS error, in pixels, for a piece of chain to be accepted as one straight line.
max_distance_between_two_linesoptFLOAT6.00–100Two collinear line pieces farther apart than this are not merged (used by the ellipse fitting too).
max_error_thresholdoptFLOAT1.30–10Maximum fit error accepted when circular arcs are joined into a circle or an ellipse.

Outputs (8)

NameTypeDescription
edge_mapNPARRAYuint8 (H,W) mask, 255 on the traced edges - one-pixel-wide by construction. Feed it to 'CV Array -> Mask' or to any node that takes a Canny result.
gradientNPARRAYuint16 (H,W) gradient magnitude ED computed - preview it with 'Preview CV Array' (normalize).
segmentsCV_CONTOURSThe edge CHAINS as CV_CONTOURS (one ordered Nx1x2 int32 point run each) - draw them with 'OpenCV Draw Contours' or measure them with the contour nodes. These are open curves, so area is meaningless; length is not.
linesNPARRAYNx4 float32 (x1, y1, x2, y2) straight fits - same layout as HoughLinesP / LSD / FLD, so 'CV Draw Segments' plugs straight in.
ellipsesNPARRAYNx5 float32 (cx, cy, semi_axis_a, semi_axis_b, angle_deg) - circles come back with a == b and angle 0. Draw them with 'CV Draw Ellipses'.
segment_countINTHow many edge chains were traced.
line_countINTHow many straight lines were fitted.
ellipse_countINTHow many circles + ellipses were fitted - branch on it with if/else, 0 is a normal outcome on a scene with no round objects.