Nodes/ComfyUI-Desert-Pixel-Nodes/DP 5 Image And Mask Switch
ComfyUI Node

DP 5 Image And Mask Switch

Pick 1 of 5 image+mask pairs with one number

By DesertPixelAi·Created 2 years ago·Updated about a year ago· 25
DP 5 Image And Mask Switch
  • images1
  • mask1_opt
  • images2_opt
  • mask2_opt
  • images3_opt
  • mask3_opt
  • images4_opt
  • mask4_opt
  • images5_opt
  • mask5_opt
  • image
  • mask
select1
export_with_mask_alphafalse
force_rgb_outputfalse

A router for image workflows: wire up to five image-and-mask pairs, and pick which one flows downstream with a single integer. The point over a plain image switch is that the mask travels with its image - flip to source 3 and you get image 3 and mask 3 together, guaranteed in sync. Handy for A/B/C/D/E testing different inputs through one pipeline, or for building a graph you can retarget without rewiring.

It's a switch node in DesertPixelAi's Desert Pixel pack, in the same family as its 3/5/10-way image switches - this one just keeps masks paired.

How it works

You connect image/mask pairs into the optional slots: images1/mask1_opt, images2_opt/mask2_opt, up through 5. The select value (1–5) chooses which pair passes through to the image and mask outputs. Change select and the whole downstream graph is now operating on a different source, mask included.

Two output-format toggles ride along: export_with_mask_alpha bakes the mask into the image as an alpha channel, and force_rgb_output guarantees flat RGB out. These handle the "downstream node wants a specific channel layout" problem without an extra conversion node.

The real trick is that select is just an integer input - so wire a seed, a primitive, or an incrementing counter into it and the switch cycles through your sources automatically across a batch. That turns it from a manual selector into an automated "run all five inputs through this pipeline" driver.

The inputs and outputs that matter

select is the control. The image/mask pairs are optional inputs - connect only the ones you're using. Outputs are image and mask; the mask is empty if the selected slot had no mask connected.

How to install it

ComfyUI Manager: search Desert Pixel, install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/DesertPixelAi/ComfyUI-Desert-Pixel-Nodes

Restart ComfyUI. No downloads. Under the DP category.

Common issues & troubleshooting

select points at an empty slot. If you set select to 4 but never connected images4_opt, there's nothing to pass. Point it at a slot you've actually wired, or connect that input.

The mask output is blank. The image slots and mask slots are separate connections. Selecting an image whose paired maskX_opt wasn't connected gives you the image but no mask. Wire the mask alongside the image if you need both.

Cycling doesn't advance. If you wired a counter/seed into select expecting it to step through sources, make sure the value is actually changing per run and stays within 1–5 (values outside that range have nothing to select). A fixed control value just holds on one source.

Channel mismatch downstream. If a later node rejects the output, toggle force_rgb_output for clean RGB, or export_with_mask_alpha if the consumer expects the mask carried in the alpha channel.

CategoryDP/image

Inputs (13)

NameTypeDefaultDescription
selectINT11–5
export_with_mask_alphaBOOLEANfalse
force_rgb_outputBOOLEANfalseConvert RGBA to RGB for compatibility with nodes like RMBG
images1optIMAGE
mask1_optoptMASK
images2_optoptIMAGE
mask2_optoptMASK
images3_optoptIMAGE
mask3_optoptMASK
images4_optoptIMAGE
mask4_optoptMASK
images5_optoptIMAGE
mask5_optoptMASK

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK