Nodes/ComfyUI_Gemini/πŸ”’ Gemini Image Select
ComfyUI Node

πŸ”’ Gemini Image Select

Pull one image out of a batch by index

By aarnoatchiΒ·Created 2 months agoΒ·Updated 2 months agoΒ· 0
πŸ”’ Gemini Image Select
  • images
  • image
  • mask
  • selected_index
  • batch_size
β—„index0β–Ί
β—„out_of_rangeclampβ–Ί

Gemini Image Select is a one-job local node: pick a single image out of a batch by index and hand it to the next node. Batch of five frames, you want the third - index of 2, done. It sounds trivial, and mostly it is, which is exactly why it's worth having when you need it. No API, no key, runs in milliseconds.

Why does this need a dedicated node at all? Because ComfyUI's IMAGE type is one tensor of shape [B, H, W, C] - a "batch" is just the first dimension - and slicing one element out in a type-safe way that other nodes accept is a small ritual people end up rebuilding constantly. This node wraps it.

What it actually does

Three useful behaviors beyond the plain slice:

  1. It normalizes odd layouts. The source is blunt about this: different upstream nodes hand images out in non-standard tensor layouts - channel-first, gray, mismatched batch conventions. The node coerces whatever it gets into a standard (B, H, W, C) batch and prints a note when it had to. If you've ever wired a weird pack's image output into a standard node and watched it explode, you know why this exists.
  2. It reports the real batch_size as an output. Wire that into your index source and you can clamp or randomize over the true range instead of guessing.
  3. out_of_range decides what happens when index is past the end: clamp returns the last available image (the default), wrap wraps around (index 5 in a batch of 3 β†’ image 2). Handy in loops, where wrap turns a batch into a cycle.

And there's a bonus in the output list: alongside image it also returns a mask - for a real RGB photo that's the luminance of the selected image, and for a mask-shaped input it just lifts the white area back out as a 0–1 alpha. So it doubles as a lazy "batch of masks β†’ one mask" too, though Gemini Mask Select is the cleaner tool for that job.

Outputs: image (as a single-item batch, shape (1, H, W, C)), mask, selected_index (the resolved index after clamping/wrapping), batch_size.

When to reach for it

The canonical pairing is right in the pack: Gemini Separate Mask Components splits a mask into blobs and tells you to use Image Select to grab one. It's also the natural partner for an index that's driven by anything dynamic - a seed, a UI widget, a loop counter. If your index is a fixed number you type once, honestly, a lot of the time you could just bypass the batch. But the moment the index comes from somewhere else in the graph, this node is the clean junction.

Install

Pack-wide: ComfyUI Manager search "ComfyUI_Gemini", or clone into custom_nodes and pip install -r requirements.txt. No scipy, no key, nothing special. Under AI/Image Analysis/Google after restart.

One thing to keep straight: this node takes a batch (one tensor). The pack also ships Gemini Select Image From List, which takes a list of mixed-size images and keeps each one's native dimensions. Feed a list of differently-sized images into Image Select and you'll be fighting the engine - that's what the list node is for. Grab the right sibling and you'll never notice the difference.

CategoryAI/Image Analysis/Google

Inputs (3)

NameTypeDefaultDescription
imagesIMAGEAn image batch. Index 0 is the first image, 1 the second, etc.
indexINT00–4095Which image to pick from the batch (image 0, image 1, ...).
out_of_rangeoptCOMBOclampWhat to do when index is past the end of the batch: clamp β€” return the last available image wrap β€” wrap around (index 5 in a batch of 3 β†’ image 2)

Outputs (4)

NameTypeDescription
imageIMAGEβ€”
maskMASKβ€”
selected_indexINTβ€”
batch_sizeINTβ€”