Auto Image Selector
The fallback switch that uses numbers, not wires
- image1
- image2
- image3
- image4
- ng_image
- image
- rank
ComfyUI has no native "give me whichever of these images is the best one right now" node. There are switches - rgthree's Any Switch walks its inputs and returns the first non-empty one - but that's a fixed wire order with no numbers attached. Auto Image Selector is the numbered version: you give each of up to four images a rank, and it outputs the connected image with the lowest rank. Lower wins. It's the plumbing-layer answer to "my workflow has several possible image sources and I don't want to rewire it by hand every time."
How it works
The mechanism is one loop over four image/rank pairs. An entry is "valid" if an image is actually connected and its rank is at least zero. The node tracks the smallest rank it's seen, returns that image, and reports the winning rank. Ties go to the first input. There's also an ng_image input that blacklists anything exactly equal to it.
That ng_image bit is where people get burned, so let's be precise: "exactly equal" means torch.equal - identical tensor shape, values, and dtype. It only excludes the literal same tensor flowing through that wire. Re-encode a copy, resize it, or pass it through any node, and it's a different tensor that won't match. Treat ng_image as "exclude this exact upstream branch", not "exclude images that look like this". The second behavior needs an actual image-comparison node, and this isn't it.
The inputs and outputs that matter
Everything is optional, which is the whole trick:
image1–image4- candidate IMAGEs. Leave any unwired; they get skipped.rank1–rank4- INT priority, defaults 1, 2, 3, 4, minimum 1. Smaller number = higher priority.ng_image- an IMAGE; any input exactly equal to it is skipped.
Outputs:
image- the winning IMAGE.rank- the INT rank that won, handy when you want downstream logic to know why it won.
The one setting you'll actually touch is the ranks. By default image1 wins, because its rank is 1. Want image2 to win when it's connected? Set rank2 to 1. You can also right-click a rank widget → Convert widget to input, and let another node decide priority at runtime. That's when this stops being a static switch and becomes actual logic.
Installing it
Same pack, same story as the rest of comfyui_my_img_util. ComfyUI Manager, search "comfyui_my_img_util", or:
cd ComfyUI/custom_nodes
git clone https://github.com/sugarkwork/comfyui_my_img_util
cd comfyui_my_img_util
pip install -r requirements.txt
Restart, and it's under the "image" category. Dependencies are numpy, Pillow, and opencv-python; no models, no downloads. One pack-level caveat: nodes.py imports cv2 at module load, so a missing opencv-python breaks every node in the pack, not just the denoise one. Don't skip the pip install.
Common issues
- Nothing connects and the graph breaks downstream. If no input is valid, the node returns
Nonefor the image andsys.maxsize- a gigantic integer - for the rank.Noneflowing into a node that expects a tensor is a hard error, and the message won't point back here. The fix is structural: keep at least one branch always wired, or feed the output into a fallback that toleratesNone. - The
ng_imageblacklist "doesn't work". Feeding in a slightly different image and expecting exclusion is the exact-equality behavior above, not a bug. - Rank 0 vs. min 1. The UI says the minimum is 1, but the code accepts 0 (the author's own test uses it). Not a problem unless you hoped rank 0 meant "disabled" - it doesn't.
Where you'd actually use it
Any graph where the "best" image source changes run to run: a ControlNet workflow that takes a pose reference or a depth map depending on what's available, a batch process that wants a different reference when one is absent, optional branches feeding a single consumer. It's a small, honest node - one loop, one comparison - and for that narrow "lowest rank wins" job it's exactly what you want.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image1opt | IMAGE | — | |
| rank1opt | INT | 1 | — |
| image2opt | IMAGE | — | |
| rank2opt | INT | 2 | — |
| image3opt | IMAGE | — | |
| rank3opt | INT | 3 | — |
| image4opt | IMAGE | — | |
| rank4opt | INT | 4 | — |
| ng_imageopt | IMAGE | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| rank | INT | — |