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.
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)
| Name | Type | Default | Description |
|---|---|---|---|
| frame_a | NPARRAY,IMAGE | First 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_b | NPARRAY,IMAGE | Second 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. | |
| flow | NPARRAY | HxWx2 float32 flow to refine (from 'CV Optical Flow (DIS)' or '(Farneback)'). Resized to the frame if the sizes differ. | |
| iterations | INT | 51–100 | Outer fixed-point iterations; more = smoother and closer to the energy minimum, and slower. |
| alpha | FLOAT | 200–1000 | Weight of the SMOOTHNESS term. Raise it for a smoother, more filled-in field; lower it to keep sharp motion discontinuities. |
| delta | FLOAT | 5.00–1000 | Weight of the colour-constancy term (brightness must match between frames). |
| gamma | FLOAT | 10.00–1000 | Weight of the gradient-constancy term - what keeps the refinement working through illumination changes. |
| sor_iterationsopt | INT | 51–100 | Inner successive-over-relaxation iterations per outer step. |
| omegaopt | FLOAT | 1.601–2 | Relaxation factor of the SOR solver; 1.6 is the standard fast-converging value. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| flow | NPARRAY | HxWx2 float32 (dx, dy) displacement per pixel. |
| magnitude | NPARRAY | HxW float32 motion magnitude in pixels. |
| angle | NPARRAY | HxW float32 motion direction in RADIANS - feed 'CV Flow To Color' in its default radians mode. |