Batch Index (NH)
Grab one frame out of a batch without touching the rest
- batch
- result
- original_count
ComfyUI loves batches - every image you generate is technically a batch of one - and it hands you tools to build them up but surprisingly few to take them apart. Batch Index (NH) is the take-apart tool. Feed it an image batch and an index, and it pulls out a single image (or a slice of them) with the dimensions intact, ready to feed a node that only wants one image at a time.
You'll reach for this the moment you generate a batch of variations and want to run only one of them through the next stage - say, the face detailer - while the others go down a different path.
How it works
Inputs are simple:
- batch - the IMAGE tensor.
- index - which image to pull. Zero-based. This is the one beginners stumble on: image 1 in your head is index 0 here.
- end_index (optional) - if set, returns a slice from
indextoend_indexinstead of a single image. Leave at -1 for single-image mode. - step (optional) - stride for that slice. With
index=0, end_index=6, step=2you get frames 0, 2, 4. Useful for thinning a video frame stack.
Negative indexes count from the end, which is genuinely handy: index=-1 grabs the last image in the batch. If your slice ends up empty (bad indexes), the node defensively returns the first image rather than erroring - a nice touch when index comes from another node's math and might drift out of range.
Outputs are result (the extracted IMAGE) and original_count (the size of the batch that went in) - the count is there so a downstream Counter (NH) or loop knows how many items it started with.
The pattern that makes it useful
The classic combo is index + a batch-aware generator: generate 8 seeds in one go, pull out the one you like via Batch Index (NH), and run the heavy refinement on just that frame. Or pair it with the pack's Any List Split (NH) when you're juggling a list-of-images and want a single one on its own wire.
Installing
Part of NH-Nodes, same one-time install:
cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
pip install -r requirements.txt
Or search NH-Nodes in ComfyUI Manager and restart. No models, no extra deps - this is a torch slice with guardrails.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| batch | IMAGE | — | |
| index | INT | 0-100–1000 | — |
| end_indexopt | INT | -1-100–1000 | — |
| stepopt | INT | 11–10 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| result | IMAGE | — |
| original_count | INT | — |