Nodes/comfyui_cv/CV Refine Flow (Variational)
ComfyUI Node

CV Refine Flow (Variational)

Polishes an EXISTING dense flow field by minimising the classic brightness-constancy + smoothness energy (cv2.VariationalRefinement) - the same refinement DIS runs internally, exposed as its own step so it can be applied to any flow: a Farneback field, a DIS field with refinement turned off, a flow you built yourself, or the same flow twice. It sharpens motion boundaries and fills small holes but cannot recover motion the input flow missed entirely - it refines, it does not search. VariationalRefinement is a cv2 class the raw wrappers cannot expose. The input flow is copied before refining, so the upstream node's cached array is never modified.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Refine Flow (Variational)
  • frame_a
  • frame_b
  • flow
  • flow
  • magnitude
  • angle
iterations5
alpha20
delta5.0
gamma10.0
sor_iterations5
omega1.60
Categoryimage/CV/features

Inputs (9)

NameTypeDefaultDescription
frame_aNPARRAY,IMAGEFirst frame - the same frame_a the flow was computed from; converted to grayscale. 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.
frame_bNPARRAY,IMAGESecond frame; resized to frame_a 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.
flowNPARRAYHxWx2 float32 flow to refine (from 'CV Optical Flow (DIS)' or '(Farneback)'). Resized to the frame if the sizes differ.
iterationsINT51–100Outer fixed-point iterations; more = smoother and closer to the energy minimum, and slower.
alphaFLOAT200–1000Weight of the SMOOTHNESS term. Raise it for a smoother, more filled-in field; lower it to keep sharp motion discontinuities.
deltaFLOAT5.00–1000Weight of the colour-constancy term (brightness must match between frames).
gammaFLOAT10.00–1000Weight of the gradient-constancy term - what keeps the refinement working through illumination changes.
sor_iterationsoptINT51–100Inner successive-over-relaxation iterations per outer step.
omegaoptFLOAT1.601–2Relaxation factor of the SOR solver; 1.6 is the standard fast-converging value.

Outputs (3)

NameTypeDescription
flowNPARRAYHxWx2 float32 (dx, dy) displacement per pixel.
magnitudeNPARRAYHxW float32 motion magnitude in pixels.
angleNPARRAYHxW float32 motion direction in RADIANS - feed 'CV Flow To Color' in its default radians mode.