Nodes/opencv-comfyui/OpenCV phase_0
ComfyUI Node

OpenCV phase_0

The angle of every vector in a field — where flow, gradients, and orientation live

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV phase_0
  • x
  • y
  • angle
  • nparray
angleInDegrees

phase_0 answers one question, for every pixel: which direction is this vector pointing? Give it the x and y components of a 2D vector field - optical flow, image gradients, motion vectors - and it returns the angle of each vector, as an image where every pixel holds a direction. It's OpenCV's cv2.phase, which is just atan2(y, x) applied elementwise. Boring math, genuinely useful output.

Where does a direction-image get you in a ComfyUI workflow? The classic cases: visualizing optical flow (run calcOpticalFlowFarneback or calcOpticalFlowPyrLK - both in this pack - split the flow into x/y, and phase gives you a per-pixel motion-direction map you can colorize), and gradient orientation (run Sobel_0 twice for horizontal and vertical derivatives, then phase to get edge orientation per pixel - the foundation of HOG-style features). If you're doing motion analysis, frame-difference direction, or any "which way is everything moving" math on video frames, this is the node.

How it works

cv2.phase(x, y[, angle[, angleInDegrees]]) computes atan2(y, x) for each element. The x and y arrays must be the same size (and ideally the same type - both float32 works best). Output:

  • angleInDegrees = True → angles in degrees in [0, 360)
  • angleInDegrees = False → angles in radians in [-π, π]

The output nparray is the same shape as the inputs: an angle for every pixel.

The inputs that matter

  • x (NPARRAY) - the horizontal component (e.g., the x output of flow or Sobel on the x-axis).
  • y (NPARRAY) - the vertical component.
  • angleInDegrees (BOOLEAN) - degrees or radians. Degrees if you'll eyeball the values; radians if you're feeding the result into more math.
  • angle (NPARRAY, optional) - OpenCV out-parameter; ignore it.

Output: nparray - one angle per pixel.

How to install it

Pack-level install, once:

  • ComfyUI Manager → search opencv-comfyui → Install, restart ComfyUI.
  • Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Requires opencv-contrib-python (README's pip install opencv-python-contrib, same wheel). No model files.

Common issues & troubleshooting

  • x and y must be the same shape - mismatch is the most common error, and it throws the pack's usual (-215:Assertion failed).
  • Radians vs degrees confusion. Check angleInDegrees before comparing values against expected angle ranges; it's easy to read a 0.7 as "degrees" when it's radians.
  • NaN land. If your flow or gradients contain divisions that blew up, phase can propagate NaN into the angle map - run patchNaNs_0 on the components first if you see weird blank pixels.
  • Batch rule: batch_size==1 only - use ImageFromBatch if Image2Nparray complains.

It's a one-liner of a node, but it's the difference between "I have flow vectors" and "I can see where everything is going."

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
xNPARRAY
yNPARRAY
angleInDegreesBOOLEAN
angleoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY