Nodes/ComfyUI-YCNodes/Image Batch Selector
ComfyUI Node

Image Batch Selector

Pull one named image out of a batch — without counting frames

By yichengup·Created 2 years ago·Updated 4 months ago· 47
Image Batch Selector
  • images
  • IMAGE
namesimage1,image2,image3
selected_nameimage1

ComfyUI's built-in ways to pull one image out of a batch are index-based, and index-based is exactly how you end up counting frames and getting it wrong. ImageBatchSelector replaces "frame 3" with a name. You give it a batch of images plus a comma-separated list of names, one per image, and it returns whichever image matches the name you select. Your batch of 8 variations becomes "moody", "bright", "vintage", "clean", and you select by intent instead of position.

How it works

It takes a batch tensor and a names string, splits the names on commas, and requires the count to match the batch size - one name per image, in order. Then selected_name (a plain string) looks up the matching image and returns it. If the name doesn't exist, it errors loudly rather than guessing, which is the right behavior. It's the batch-oriented sibling of the pack's ImageSelector (which uses ten fixed input ports); this one scales to any batch size and works on whatever flows out of a batch sampler, video frame extraction, or a multi-image generator.

Under the hood it's a dict lookup plus an unsqueeze to keep the output a proper 4D tensor. Trivial, and that's the appeal - there's no shape gymnastics between you and the image you want.

The inputs that matter

  • images - the batch tensor.
  • names - multiline, comma-separated, exactly one name per image in batch order. Default image1,image2,image3.
  • selected_name - which name to output.

Output is a single IMAGE (the chosen frame, in batch format so it feeds anything downstream without an extra reshape).

Where it earns its place

Any workflow where batch position is meaningless but identity isn't. Run 8 seeds, label them by their prompt variant, then pick "best" by name instead of by slot number - and if you reorder the batch later, the name keeps working. It also makes shared workflows readable: a node labeled "choose: faceA / faceB / faceC" is self-documenting in a way "index 5" never is. If you pair it with a text switch (the pack's YC-Text-Index-Switch does the same job for prompts), you can name your way through an entire batch pipeline.

Installing it

Part of ComfyUI-YCNodes. ComfyUI Manager → search ComfyUI-YCNodes → install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes

Restart, then look under YCNode/Image. Torch and numpy only.

Gotchas

The count mismatch is the whole failure mode: if your batch has 5 images and names has 4 entries, it raises 图像数量(5)与名称数量(4)不匹配 - the error message is in Chinese, which is your first clue if things look foreign. Keep names unique (a duplicate name silently wins the first match) and trim stray whitespace - the parser strips it, but trailing commas create empty entries that throw off the count. Also note this selects one image; for slicing a range out of a batch, the pack's MaskFromBatch or core tools are the better fit.

CategoryYCNode/Image

Inputs (3)

NameTypeDefaultDescription
imagesIMAGE
namesSTRINGimage1,image2,image3
selected_nameoptSTRINGimage1

Outputs (1)

NameTypeDescription
IMAGEIMAGE