Nodes/WebApp API/Image 4D Tensor
ComfyUI Node

Image 4D Tensor

The shape-fixer for nodes that forget a dimension

By MonkeyProof-Solutions-BV·Created 6 months ago·Updated 3 months ago· 2
Image 4D Tensor
  • image
  • Image

Here's a ComfyUI fact you'll hit sooner or later: images are supposed to be 4D PyTorch tensors - [batch, height, width, channels] - and some custom nodes just... don't do that. A node outputs a 3D tensor or a 2D grayscale and the next node in line refuses to connect or silently mangles the data. WebApp_Image4DTensor exists to fix exactly that: it takes whatever image shape it gets and guarantees a 4D tensor comes out the other side.

It's one of the "helper" nodes in the ComfyUI_webapp pack (alongside Random number generator and Combine lists), which means it's not a web-app definition node at all. No parent, no order, no app framework involved. It's a plain image postprocessing fix you can drop into any workflow. That's worth saying because the pack's name makes people assume everything in it is about web apps. Not this one.

What it does

Single input image (IMAGE), single output Image (IMAGE). The logic, straight from the source:

  • Already 4D → passes through untouched.
  • 2D (just width and height, e.g. a grayscale) → adds a leading batch dimension.
  • 3D where the last dimension looks like channels (size ≤ 4) → adds a batch dimension.
  • Otherwise (3D with no obvious channel dimension) → adds a channel dimension on the end.

End result: every path lands on a [batch, height, width, channels] tensor. The pack needs this internally because its web-app image inputs must hand well-formed tensors to downstream nodes - but you'll reach for it in any workflow where a third-party node emits a nonstandard shape and the editor won't even let you make the connection.

When you'd actually use it

The honest use case: you've got a node that outputs something weird and a downstream node that refuses it. Stick this between them. It's also the kind of thing you keep on hand for debugging - if a node downstream complains about rank or shape, confirming that the image is genuinely 4D right before it removes one whole class of "why is this black / why is this 2D" confusion.

Installing it

Same as the rest of the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/MonkeyProof-Solutions-BV/ComfyUI_webapp

Restart ComfyUI, or use ComfyUI Manager → search ComfyUI_webapp ("WebApp API"). No models, no extra dependencies beyond pillow and torch.

Gotchas

This node doesn't resize or convert anything - it only fixes dimensionality. If your image is 3D because it's genuinely a single frame with missing channels, you get a 4D tensor with a channel dimension of 1, which downstream nodes may or may not accept. And the usual pack note: it's written against the newer backend node API (comfy_api.latest), so keep ComfyUI current or the pack won't load at all.

Categoryimage/postprocessing

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (1)

NameTypeDescription
ImageIMAGE