Nodes/ComfyUI-Pt-Wrapper/Pt To Rgb Tensors
ComfyUI Node

Pt To Rgb Tensors

Split an image into channels you can do real math on

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt To Rgb Tensors
  • tens
  • R
  • G
  • B

Pt To Rgb Tensors does one thing and does it plainly: it splits an image tensor into its red, green, and blue channel tensors. One input (tens, TENSOR), three outputs named R, G, B - each a TENSOR. If the input has a batch axis, it's kept, so you can split a whole batch at once.

The mechanism is a clean slice along the last axis: R, G, B = tens[..., 0], tens[..., 1], tens[..., 2]. That means it assumes your channel dimension is the final axis - HWC layout, the same convention ComfyUI itself uses. Feed it a CHW tensor (channel first, as PyTorch models prefer) and you won't get an error for rank-3/4, but you'll get slices of the height axis, which is nonsense. If your data is CHW, transpose it first.

It also enforces its own sanity: if the last axis isn't exactly 3 channels, it raises a ValueError. So no silent surprises with alpha channels or grayscale - you'll get told, loudly.

When would you actually want this? Channel-wise math is the answer. Standard ComfyUI color nodes are blunt instruments, but once you've got separate R, G, B tensors you can do precise per-channel work - threshold one channel, reweight another, compute channel differences, feed individual channels into a model that expects them separately. It's also a great debugging tool: split a tensor, feed each channel to a preview node, and see exactly what each channel contains instead of squinting at a composite.

Install

ComfyUI Manager (search "ComfyUI-Pt-Wrapper"), or:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper

Restart ComfyUI. Heavy requirements (transformers, datasets, peft, accelerate, scikit-learn, pandas, seaborn, matplotlib, gensim, sentencepiece) mean a slow first launch. No model files to download.

Common issues

If you get a ValueError about channels, your tensor doesn't end in a 3-channel axis - check the layout. If you get plausible-but-wrong channels, you fed it CHW and sliced the wrong axis. And if you split and then want to put the image back together, there's no dedicated merge node in this trio - but a stack/permute on the tensors gets you there, or you can keep the original until your per-channel work is done.

CategoryData Analysis

Inputs (1)

NameTypeDefaultDescription
tensTENSOR

Outputs (3)

NameTypeDescription
RTENSOR
GTENSOR
BTENSOR