Nodes/ComfyUI/Get Image from Batch
ComfyUI Node Runs on cloud

Get Image from Batch

Get Image from Batch

By Comfy-Org·Created 4 years ago·Updated 16 days ago· 121,575
Get Image from Batch
  • image
  • IMAGE
batch_index0
length1

You ran a batch of four, or decoded a stack of video frames, and now you want just one of them - or a slice of the middle. Get Image from Batch is the node that pulls a single image (or a run of images) out of a batch by index. It's the inverse of batching: batch nodes stack images together, this one takes them back apart.

Why you'd reach for it

Lots of ComfyUI operations produce or move images in batches - a KSampler with batch_size 4, a video decode, an IPAdapter reference stack. When you only want to save frame 12, or send the first image of a batch down a different branch, you need a way to address one position. That's this node. It's small, but in any workflow that generates several images at once and then treats them differently, it's the node doing the "pick this one" work.

How it works

You point it at a batch and give it a starting batch_index. It returns the image at that position - and if length is greater than 1, it returns that many images starting from the index, i.e. a contiguous slice. So index 0 / length 1 is "the first image," index 2 / length 3 is "images 2, 3, and 4." The index can be negative, which counts from the end, handy when you want the last frame without knowing the batch size.

Inputs and outputs

Three inputs: image (the batch), batch_index (where to start; negatives count from the end), and length (how many to take, default 1). The output is IMAGE - either a single image or the sub-batch you sliced. Feed it into a Save Image, a preview, or whatever branch handles that specific frame.

Installing it

Good news first: this one is in ComfyUI core now. Its module is comfy_extras, not a custom pack, so an up-to-date ComfyUI already has "Get Image from Batch" under the image/batch category - no install needed. It's another node that graduated out of cubiq's Essentials pack into core, which is exactly what that pack was for (the README calls itself a temporary home "until the nodes get included into ComfyUI").

If you're on an older build or a workflow references the Essentials version, install the pack through ComfyUI Manager (search ComfyUI Essentials) or:

cd ComfyUI/custom_nodes
git clone https://github.com/cubiq/ComfyUI_essentials

and restart. The behavior is the same either way.

Common issues

The most common mistake is an index past the end of the batch - asking for image 5 in a batch of 4. Depending on your build that either errors or clamps, so keep the index inside the batch (wire a Get Image Size batch_size output into your math if the batch length is dynamic). Also don't confuse length with "which image": length is how many to grab, not a second index. Want a single frame? Leave length at 1 and move the index.

Categoryimage/batch

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
batch_indexINT0-16384–16384
lengthINT11–4096

Outputs (1)

NameTypeDescription
IMAGEIMAGE