Nodes/comfyui_cv/CV Stereo Disparity (WLS filtered)
ComfyUI Node

CV Stereo Disparity (WLS filtered)

Disparity from a RECTIFIED stereo pair, cleaned with the ximgproc weighted-least-squares filter: SGBM is run left-to-right AND right-to-left, the two maps are consistency-checked, and the result is smoothed while sticking to the left image's edges. It fills the holes SGBM leaves in low-texture areas WITHOUT inventing structure the way inpainting does - on the example driving pair the valid fraction goes from ~65% to ~95% - and it also outputs a per-pixel confidence map, which is what lets downstream steps keep only trustworthy points ('CV Sample Array At Points' + 'CV Filter Points 3D By Mask'). The pair MUST be rectified first (cv2.stereoRectify + cv2.initUndistortRectifyMap + cv2.remap). Preview with 'Preview CV Array' (normalize / heatmap).

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Stereo Disparity (WLS filtered)
  • left
  • right
  • disparity
  • confidence
  • valid
  • disparity_raw
num_disparities64
block_size7
min_disparity0
modeSGBM (balanced)
wls_lambda8000
wls_sigma_color1.5
uniqueness_ratio10
speckle_window_size100
speckle_range2
lrc_threshold24
depth_discontinuity_radius0
disp12_max_diff-1
Categoryimage/CV/contrib

Inputs (14)

NameTypeDefaultDescription
leftNPARRAY,IMAGELeft rectified frame (grayscaled internally). 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.
rightNPARRAY,IMAGERight rectified frame; resized to left if the sizes differ. 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.
num_disparitiesINT6416–512Disparity search range (0..num_disparities), rounded up to a multiple of 16. Larger covers nearer objects / wider baselines but is slower.
block_sizeINT71–21Matched block size in pixels (forced odd; 3-11 is typical). Smaller = more detail but noisier.
min_disparityINT0-256–256Smallest disparity to search from (usually 0).
modeCOMBOSGBM (balanced)SGBM is the standard; 3-way is faster at lower quality; HH runs the full-scale two-pass (best, slowest).
wls_lambdaFLOAT80000–100000Regularization strength: how strongly the filtered disparity is smoothed towards the edges of the left image. 8000 is the OpenCV-recommended default; larger = smoother, more hole filling, more bleeding across depth edges.
wls_sigma_colorFLOAT1.50–10How sensitive the filter is to left-image edges. 0.8-2.0 is the useful range: too low leaks disparity across object boundaries, too high makes it follow image noise.
uniqueness_ratiooptINT100–100Margin (%) by which the best match must beat the runner-up to be accepted.
speckle_window_sizeoptINT1000–1000Largest smooth disparity blob treated as speckle noise and invalidated (0 = off).
speckle_rangeoptINT20–64Max disparity variation within a speckle component.
lrc_thresholdoptFLOAT240–256Left-right consistency tolerance in 1/16 pixel units: disagreements above it are marked unconfident and re-filled by the filter.
depth_discontinuity_radiusoptINT00–32Radius (px) around depth discontinuities used when computing confidence. 0 = the filter's own heuristic (block_size / 2).
disp12_max_diffoptINT-1-1–64SGBM's OWN left-right check, in pixels: matches that disagree by more than this are invalidated before the WLS filter ever sees them. -1 (cv2's default) turns it off and leaves occlusion junk in the map; 1 is the usual setting when the disparity feeds an interpolation or a point cloud.

Outputs (4)

NameTypeDescription
disparityNPARRAYHxW float32 WLS-filtered disparity in pixels.
confidenceNPARRAYHxW float32 confidence map, 0-255; low where the two matching directions disagreed (occlusions, texture-less areas). Sample it at your points to reject unreliable 3D.
validNPARRAYuint8 0/255 mask of pixels with a valid filtered disparity.
disparity_rawNPARRAYThe unfiltered left-to-right SGBM disparity (float32 pixels) - keep it to show what the filter changed.