Batch to Multiband
Turn a batch of images or masks into one multiband stack
- images
- masks
- multiband
Batch to Multiband answers a specific, annoying problem: you have a batch of things - four masks from SAM, or a batch of images - and you want them treated as channels of one multi-band object, not as separate items in a batch. In normal ComfyUI, a batch is a stack along the batch axis, which most nodes then process frame-by-frame. This node flattens the batch axis into the channel axis instead, so each input becomes its own named channel.
The classic use is the SAM-mask pile. Run a detector or a segmentation pass over a batch and you get N masks you want to store as a single MULTIBAND_IMAGE with a name per mask. Multiband gives you that: batch axis goes away, channel axis appears, and each channel is labeled.
How it works
Two optional inputs, and you can feed either or both:
- images - a batch of IMAGEs
(B, H, W, C). Each image becomesCchannels, namedimg_01_r,img_01_g,img_01_b,img_02_r, and so on (orimg_01_0,img_01_1… for more than four channels). - masks - a batch of MASKs
(B, H, W). Each mask becomes one channel namedmask_01,mask_02, …
The output is a single multiband with batch 1 - everything you fed in is now channels of one object. If you pass both images and masks, both get flattened in and the channels stack up in input order. One guardrail: if you feed both, their spatial sizes must match, or you get a dimension error.
Channel names here are the star feature, because they're what make the pack's name-based tooling work later. Multiband to Masks with auto_detect_masks on will find every channel with "mask" in its name and pull them all out in one go - that's the loop this node is built for: batch in, stacked masks in, pull the mask channels back out by name.
When to reach for it vs. the alternatives
If you have exactly one mask, Mask to Multiband is simpler. If you have a handful of different masks (person, car, sky) from different sources, Compose Multiband with one wire each is clearer. Batch to Multiband earns its keep when the inputs genuinely arrive as a batch - a batch of SAM masks, a batch of rendered feature maps - because it's the only one that turns the batch itself into channels.
Installing the pack
From ComfyUI-Multiband. ComfyUI Manager → search "ComfyUI-Multiband" → Install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/PozzettiAndrea/ComfyUI-Multiband.git
pip install -r ComfyUI-Multiband/requirements.txt
Plain tensor shuffling under the hood - numpy, torch, tifffile as deps, no models to download.
A trap to keep in mind
Batch semantics can bite. A batch of 4 masks is not four channels until it goes through this node - and if you skip the conversion and feed the batch straight to a save node, you'll get a (B,1,H,W) multiband with batch 4, not a 4-channel one. If your saved file's channel count looks wrong, check which node created the multiband and whether the batch axis got flattened when you expected it to.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| imagesopt | IMAGE | Batch of images (B, H, W, C). Each image becomes C channels named img_XX_r/g/b/a | |
| masksopt | MASK | Batch of masks (B, H, W). Each mask becomes one channel named mask_XX |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| multiband | MULTIBAND_IMAGE | — |