Nodes/opencv-comfyui/OpenCV phase_1
ComfyUI Node

OpenCV phase_1

Turn an (x, y) vector field into a direction map with OpenCV phase_1

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

If you've ever had an optical flow field or a gradient map and wanted to know which direction every pixel is pointing, this is the node. phase_1 is a direct port of OpenCV's cv2.phase: you feed it two same-sized arrays, one for the x component and one for the y component, and it hands you back an array of angles - the rotation angle of every 2D vector, computed as atan2(y, x).

It's part of the opencv-comfyui pack, which auto-generated nodes for basically every standalone function in OpenCV's Python API. The author, Gerold Meisinger, shipped it to r/comfyui in April 2025 with a fair warning attached: these nodes are thin, auto-generated wrappers and "ugly and complex to use. Expect dragons!" That's accurate. phase_1 is not an image-processing node in the pretty sense - it's a math node that happens to live in your graph.

What it does and why you'd reach for it

The mechanism is straightforward. OpenCV's phase takes two floating-point arrays x and y of identical size and computes, per pixel, the angle of the vector (x, y) measured from the positive x-axis. Flip angleInDegrees on and you get angles in [0, 360]; leave it off and you get radians in [0, 2π).

Where does this actually matter? The most common real-world use is visualizing optical flow. Flow algorithms like Farneback give you two channels - horizontal displacement and vertical displacement - and those are exactly the x and y this node wants. Once you have a per-pixel direction, the classic trick is to map the angle onto hue in an HSV image so you can see the motion: angle → hue channel, magnitude → value channel. Same idea works for gradient direction maps in edge-analysis pipelines, or for building HOG-style feature images by hand.

The inputs that matter

Only two are worth thinking about:

  • x and y - the two component arrays (NPARRAY). Must be the same shape and floating point. A uint8 BGR image straight out of Image2Nparray will not work; cv2.phase will reject non-float input.
  • angleInDegrees - the boolean that changes your units from radians to degrees. If you're mapping to hue, degrees is usually what you want.

angle in the optional slot is an OpenCV out-parameter. The README explicitly says to skip the optional out-params (usually called dst), and this is one of those - leave it unconnected.

How to install

Install the pack once and you get all ~635 nodes, this one included. Via ComfyUI Manager, search "opencv-comfyui" (or "OpenCV"), or clone manually:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Then restart ComfyUI. The pack's requirements pull in opencv-contrib-python (that's the one real dependency - numpy and torch are already in ComfyUI):

pip install opencv-contrib-python

The workflow shape and the traps

You're working in NPARRAY land, not IMAGE land. The standard chain is IMAGE → Image2Nparray → phase_1 → Nparrays2Image → IMAGE, and Image2Nparray only accepts batch_size==1. If you hit "Only images with batch_size==1 are supported!", slip an ImageFromBatch (length 1) in front.

Where people get burned with phase_1 specifically: the output is a float array of angles, not a displayable image. If you wire it straight into Nparrays2Image, you'll either get a meaningless gray blob or the "NoneType object has no attribute shape" error when the result isn't actually an image. Normalize or remap the angle range before display, and remember Nparrays2Image expects BGR or grayscale - check what you're feeding it.

Honestly? You won't reach for this node often. But when you're debugging why an optical flow pass is smearing everything sideways, converting displacement to direction is the fastest way to see what's actually happening - and that's a genuinely useful trick to have in the box.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
xNPARRAY
yNPARRAY
angleInDegreesBOOLEAN
angleoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY