Nodes/ComfyUI CV/cv2.flipND
ComfyUI Node

cv2.flipND

Flip one axis of the array you're actually holding

By bmad4ever·Created 4 months ago·Updated 15 days ago· 1
cv2.flipND
  • src
  • result
◄axis0►

cv2.flip gives you three options: horizontally, vertically, both. cv2.flipND gives you any axis of the array - which matters more than it sounds, because in this pack "the array" is whatever arrives: a BGR image as [H,W,C], a single-channel mask as [H,W], a latent as float32 [H,W,C], or an NPARRAY stack you bridged in as [B,H,W,C]. Choosing the axis means choosing which of those dimensions mirrors.

It's one of the raw Auto-generated wrappers in ComfyUI CV (bmad4ever), the pack exposing OpenCV 5.0 to ComfyUI. The generated layer is thin on purpose - one cv2 call, NPARRAY-flavoured sockets, no hand-holding - so the trick with this node is knowing what your array's axes actually are.

How it works, per input type

OpenCV 5's flipND(src, axis) is the n-dimensional generalisation of flip; the pack's conversion conventions decide what axis counts. An IMAGE tensor becomes a uint8 BGR array shaped [H, W, C], so:

  • axis=0 - mirror top-to-bottom (rows).
  • axis=1 - mirror left-to-right (columns). Same result as cv2.flip with code 1.
  • axis=2 - reverse the channel order. On BGR data that's a red/blue swap. It won't error, and it looks like a colour glitch, which is exactly how you'll recognise it.

A MASK becomes [H, W], so only 0 and 1 are meaningful. A LATENT becomes float32 [H, W, C] with values untouched, same axis mapping - and note that the pack routes spatial ops like this through frame 0 of a latent batch.

The interesting case is an NPARRAY. Pass an array that's already [B, H, W, C] - e.g. from Image Batch → CV Batch, which turns a whole batch into one 4-D array - and axis=0 flips the batch order. That's a reversed sequence: play the clip backwards, or feed flipped-order frames to something that walks a stack. It's how you do the frame-order reversal that cv2.flip can't express, and it's a good reason to keep this node in mind beyond the obvious mirror.

Note the asymmetry, because it will bite you: if you hand it a ComfyUI IMAGE batch, the pack's per-frame path flips each frame individually and keeps the order (this function is on the pack's per-frame-safe list). If you hand it a batched NPARRAY, you get one operation on the whole 4-D array. Same node, two behaviours, and the difference is the container type you wired in.

Inputs and outputs

  • src - IMAGE, MASK, LATENT or NPARRAY; the output echoes whichever you used, so an IMAGE comes back an IMAGE and an NPARRAY stays an NPARRAY.
  • axis - an INT, default 0. There is no dropdown and no tooltip; it is a raw numpy axis index for the array as converted. If you're unsure, wire the array through CV Array Shape first and read the sizes: seeing the shape written out is far faster than guessing which axis is which.

Install

ComfyUI Manager → ComfyUI CV, or:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
pip install -r comfyui_cv/requirements.txt

Python ≥3.12, current ComfyUI (V3 node API), restart after. opencv-contrib-python-headless~=5.0.0.93 is the one dependency. Watch out for the contrib trap once you're browsing the rest of the pack: installing opencv-python over the contrib wheel leaves cv2.fisheye, cv2.aruco, cv2.ft and friends as empty stubs, and the corresponding nodes silently disappear. python ComfyUI/custom_nodes/comfyui_cv/tools/repair_opencv_contrib.py --check tells you, --apply fixes it with the server stopped.

Common issues

Colours came out swapped. You flipped axis 2. On BGR data, reversing channels is a red/blue exchange, and it's almost never what anyone means.

"Nothing happened" on a mask. A binary mask flipped vertically about its centre can look unchanged if it's symmetric - and a mostly symmetric one is easy to misread. Diff it with cv2.absdiff against the original to be sure.

cv2.flipND missing from your node list. This is an OpenCV 5 function; the pack builds its registry from whatever your installed build exposes, so an older OpenCV means this node doesn't exist rather than failing at run time. Check the pin (~=5.0.0.93) and CV Build Information, which prints the OpenCV build banner including which modules are compiled in.

Axis out of range. Flatten or reshape first - CV Reshape Array, CV Permute Axes (np.moveaxis, for when you need to reorder rather than flip) and CV Array Shape are the three utilities that make this node predictable.

Categoryimage/CV/low-level/cv2 F

Inputs (2)

NameTypeDefaultDescription
srcCOMFY_MATCHTYPE_V3 The image output(s) echo this input's format. A LATENT link is processed in latent space: frame 0 becomes a float32 [H,W,C] array (any channel count), values untouched. Arithmetic ops (add, multiply, etc.) also accept a full LATENT batch ({samples: [B,C,H,W]}) — the whole batch flows through when both inputs have the same batch size. 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.
axisINT0-2147483648–2147483647 - - -

Outputs (1)

NameTypeDescription
resultCOMFY_MATCHTYPE_V3Echoes the 'src' input's format: an IMAGE link comes back as IMAGE, MASK as MASK, NPARRAY stays NPARRAY.