Pick From Batch (mtb)
Grab the first or last N images from a batch
- image
- mask
- IMAGE
- MASK
Small, sharp utility: given a batch of images, keep the first N or the last N and drop the rest. That's it. It sounds almost too simple to need a node, but the moment you're working with batches - a grid of samples, a stack of video frames, a sequence coming out of an animation node - you constantly need to slice off just the ones you want, and this does it cleanly.
Common uses: grab the first image of a batch for a quick preview, keep the last few frames of a generated clip, or trim a batch down before an expensive downstream step so you're not processing frames you'll throw away. It's the kind of node you don't plan for and then reach for constantly once your graphs start dealing in batches rather than single images.
How it works
It slices the image batch tensor from either end. No model, instant. If you pass a mask alongside, it slices the mask in lockstep so the two stay aligned.
The inputs that matter
image- the batch to pick from.from_direction-start(default) takes from the head of the batch,endtakes from the tail. So "first frame" isstartwith count 1; "last three frames" isendwith count 3.count- how many to keep (default 1).mask(optional) - a matching batch of masks, sliced the same way so image N and mask N stay together.
Two outputs: IMAGE (the picked images) and MASK (the picked masks). If you didn't pass masks in, you just use the image output.
How to install it
ComfyUI Manager: search MTB Nodes (comfy_mtb), install, restart. Or manually: cd ComfyUI/custom_nodes && git clone https://github.com/melMass/comfy_mtb and restart. Pure Python - nothing to download.
Common issues
The predictable edge case is asking for more than the batch holds - count of 10 on a batch of 4. It can only give you what's there, so you get the whole batch back rather than an error; if a downstream node expected exactly 10 images, that mismatch is where to look.
The other thing people trip on is from_direction semantics when they're thinking in terms of "which frame." start + count 1 is the first image; if you wanted the last one, that's end + count 1. And if you're feeding masks in, make sure the mask batch length matches the image batch length - if they're out of sync, the "keep them aligned" guarantee only holds when they started aligned. For anything more surgical than "N from an end" - say, the 3rd and 7th specifically - you'll want an index-based selector instead; Pick From Batch is deliberately just the head/tail slice.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| from_direction | COMBO | start | 2 options: end, start |
| count | INT | 1 | — |
| maskopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |