ComfyUI Node

Image Batch Slicer

Grab one frame, or a run of frames, out of an image batch

By DebugPadawan·Created about a year ago·Updated 5 months ago· 2
Image Batch Slicer
  • images
  • sliced_images
  • count
index0
count1

Once you start generating batches - or working with video frames - a single IMAGE tensor stops being "one picture" and becomes a stack of them. ComfyUI represents that as a tensor shaped [B, H, W, C], where B is how many images are in the batch. Image Batch Slicer is the node that reaches into that stack and pulls out a contiguous run: frame 3 through 5, or just frame 7 by itself. If you've ever wanted to detail one frame of a batch while the rest flows on, this is your lever.

It's part of DebugPadawan's ComfyUI Essentials, a small MIT-licensed utility pack. It's a genuinely useful companion to the pack's Image Info node (which tells you the batch size) and Color Palette Extractor (which only looks at the first frame).

How it works

Two numbers, one idea: it returns images[start : start + count], where start comes from index and count is how many frames you want. The code clamps the start so it never exceeds the last frame, and it clamps the end to the batch, so you can't slice past what exists - you just get fewer frames than you asked for at the tail.

Important mental model: the output is still a batch. ComfyUI images are always [B, H, W, C], so asking for a single frame with count = 1 gives you a batch of one, not a standalone image. That's fine - most nodes accept it - but it's why you sometimes see batch_size = 1 on a "single" image.

Inputs and outputs that matter

  • images - the IMAGE tensor to slice.
  • index - where to start, default 0.
  • count - how many frames to take, default 1, min 1.

Outputs: sliced_images (the IMAGE slice) and count (an INT telling you how many frames you actually got - handy when the batch ran short).

Install

Standard custom-node fare:

cd ComfyUI/custom_nodes
git clone https://github.com/DebugPadawan/DebugPadawans-ComfyUI-Essentials.git

Restart ComfyUI, or install via ComfyUI Manager by searching "DebugPadawan". requirements.txt lists numpy, torch, and opencv-python - numpy and torch already ship with ComfyUI and the shipped code never imports cv2, so no heavy downloads, no model files, no API keys.

Where people get burned

  • Expecting an error on out-of-bounds. It clamps instead. index = 999 on a 4-frame batch gives you the last frame, silently. If your workflow depends on detecting a short batch, check the count output.
  • Forgetting the batch dimension survives. count = 1 doesn't unwrap the tensor to a non-batch image. If a downstream node demands a batch anyway (most do), you're fine; if something expects the "image, not batch" shape, this will confuse you.
  • Index is zero-based. index = 0 is the first frame. Classic off-by-one territory.

A clean pattern: run Image Info to get batch_size, then use this node to split a big batch into slices that fit your VRAM budget, or to hand frame 0 to a detailer while the rest keeps going through the main pipeline.

CategoryDebugPadawan/Image

Inputs (3)

NameTypeDefaultDescription
imagesIMAGE
indexINT00–1000
countINT11–1000

Outputs (2)

NameTypeDescription
sliced_imagesIMAGE
countINT