ComfyUI Node

img to tensor

A boring adapter that quietly unifies image and tensor types

By 807502278·Created 2 years ago·Updated 2 years ago· 23
img to tensor
  • image
  • mask
  • image_tensor
  • mask_tensor

There's nothing glamorous about img to tensor, and that's exactly why it's useful. ComfyUI images are already torch.Tensors under the hood, but the graph treats them as a distinct IMAGE type. This node from ComfyUI-3D-MeshTool just re-labels an image and/or mask as the pack's custom Tensor type so it can flow into the tensor-based camera and array nodes. It's a type bridge, not a transformation.

You'll reach for it when a wire won't connect: the pack's Tensor socket refuses to accept an IMAGE output, or vice versa. Feed the image in, get image_tensor out, and now it plugs into things like List_to_Tensor, tensor-new, or the mesh editing math. Feed a mask in too and you get mask_tensor alongside it.

How it works

The mechanism is deliberately thin. If the input isn't already a torch tensor, it does a torch.from_numpy(...) conversion and hands it through. Both image and mask inputs are optional, so you can convert just one at a time. The reverse direction is handled by the pack's sibling node tensor-to-img, which returns an IMAGE and a MASK and is where you'll land back when you want to preview or save what the tensor math produced.

The install, quickly

It ships in the ComfyUI-3D-MeshTool pack, so install the pack once and every node in it comes along:

cd ComfyUI/custom_nodes
git clone https://github.com/807502278/ComfyUI-3D-MeshTool
cd ComfyUI-3D-MeshTool
pip install -r requirements.txt

Then restart ComfyUI. ComfyUI Manager also has it (search "ComfyUI-3D-MeshTool"). No models to download; the heavy dependency is kiui, which you likely already have if you run any 3D-Pack-style workflow.

Notes and gotchas

Nothing in this node validates shapes or channels - it's a passthrough, so garbage in, garbage out. If you convert a batch of 4-channel images, you get a 4-channel tensor, and downstream math nodes may not know what to do with that. Convert after your image is in the shape you actually want, not before. And if you're only converting to satisfy a wire, double-check the target node doesn't have a native IMAGE input you missed - this adapter exists because the pack's tensor nodes are picky, not because ComfyUI images are hard to work with.

Category3D_MeshTool/Array/Tensor

Inputs (2)

NameTypeDefaultDescription
imageoptIMAGE
maskoptMASK

Outputs (2)

NameTypeDescription
image_tensorTensor
mask_tensorTensor