tensor to img
When a raw tensor won't preview, this is the bridge
- tensor
- image
- mask
ComfyUI is picky about what counts as an image. A torch tensor is just numbers, and if some 3D or batch node hands you a raw Tensor, you can't preview it, can't feed it to a VAE, can't do anything image-like with it - the graph sees an unconnected type. tensor to img is the adapter that fixes that: it takes a raw tensor and presents it as a proper ComfyUI IMAGE, plus a MASK output you get almost for free.
The mechanism is simple and worth understanding because it's what tells you which tensors this node actually handles. It looks at the number of dimensions:
- A 3D tensor (
[H, W, C], a single unbatched image) gets returned as-is for theimageoutput, and the whole thing becomes themask. - A 4D tensor (
[B, H, W, C], a batch) is checked on its last channel count. Three channels (RGB) → returned as image, with an all-ones mask built for you (fully opaque). Four channels (RGBA) → returned as image, and the alpha channel is split out as themask. - Anything else prints an error to the console - this node expects image-shaped tensors with 3 or 4 channels, not arbitrary data.
So the real workflow answer is: your tensor has to already be in the [B, H, W, C] layout with 3 or 4 channels, and this node's job is typing, not converting. If your tensor is in a different layout - say [C, H, W] channels-first, which some ML code produces - it'll pass through looking wrong or error on the channel count. That's the single most common way this bites people, and the fix is to transpose it before it gets here.
The mask output is genuinely useful even if you didn't ask for it. If you're working with RGBA renders or multi-view outputs, you get the alpha for free and can wire it into compositing, background replacement, or anything that wants a matte - no separate mask extraction step needed.
This node ships in 807502278/ComfyUI-3D-MeshTool, the one-author 3D utility pack that leans on ComfyUI-3D-Pack conventions (the Tensor type comes from there, so keep that pack installed for workflows to resolve). No models, no extra deps - it's pure shape logic.
Install via ComfyUI Manager (search "ComfyUI-3D-MeshTool") and restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/807502278/ComfyUI-3D-MeshTool
cd ComfyUI-3D-MeshTool
pip install -r requirements.txt
One honest caveat: the author's node naming has shifted between versions, and renamed nodes show up red in old workflows - just recreate tensor to img and reconnect. And if the image looks wrong after conversion, check your channel count before you blame the node.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| tensor | Tensor | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |