Nodes/opencv-comfyui/Nparrays2Image
ComfyUI Node

Nparrays2Image

Turning nparrays back into images

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
Nparrays2Image
  • nparrays
  • image

ComfyUI doesn't speak OpenCV. Its IMAGE type is a torch tensor - float32, RGB, values 0..1 - while every node in the opencv-comfyui pack works on numpy arrays that are usually uint8, BGR, 0..255. Image2Nparray is the door in. Nparrays2Image is how you get back out. Run any cv2 filter, transform, or PCA step in the middle of your graph, and this is the node that turns the result into something a VAE, a ControlNet preprocessor, or a plain Preview node will accept.

It's the less glamorous half of the bridge, and also the one beginners trip over, because it's strict about what it counts as an image.

How it works

The node takes a list of nparrays and returns one IMAGE tensor. Under the hood it walks each array and figures out the channel layout:

  • a 2D (H, W) or single-channel (H, W, 1) array is treated as grayscale and converted to RGB (GRAY2RGB)
  • a 3-channel (H, W, 3) array is assumed to be BGR and converted to RGB (BGR2RGB)

then each frame is divided by 255, cast to float32, moved to your compute device, and stacked into a batch. So the color-channel ritual the rest of this pack forces on you (see the README's cvtColor enums) is handled for you on the way out - as long as your array is actually shaped like an image.

The input that matters

There's exactly one: nparrays, the NPARRAY output of just about any other node in this pack - patchNaNs, pencilSketch, perspectiveTransform, the whole PCA family. Wire it in and you get image (IMAGE) out the other side. Nothing else to set.

Where people get burned: the README's warning is not boilerplate. "Not every return type of nparray is actually an image. Some are just a 1-dimensional array of floats." Feed it a flat (N,) array of scalar stats and you'll get 'NoneType' object has no attribute 'shape', because the code assumes (H, W[, C]). Before you wire the tail of a pipeline straight into this node, check the OpenCV docs for what that function actually returns.

How to install it

It ships with the whole opencv-comfyui pack, so install once:

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

You need OpenCV with contrib modules (pip install opencv-contrib-python - the README's own step, and you almost certainly already have it since half the nodes in a typical ComfyUI setup pull it in). No model files, no keys; this is all deterministic pixel math.

Common issues & troubleshooting

  • Only images with batch_size==1 are supported! - that error comes from Image2Nparray on the input side, not this node. This pack only handles one image at a time, so pull a single frame out of your batch first (the README suggests ImageFromBatch with length=1).
  • NaN pixels survive the /255 and float32 conversion and get baked straight into the tensor. If your OpenCV math produced NaNs, patch them first - patchNaNs_0 exists precisely for that, because NaN in a latent is a silent, ugly failure.

Expect dragons - the author says so himself. But for a pack of 600+ auto-generated wrappers, this is the node that makes the whole thing usable.

Categoryimage/OpenCV

Inputs (1)

NameTypeDefaultDescription
nparraysNPARRAY

Outputs (1)

NameTypeDescription
imageIMAGE