Get Image Batch Count
How many images are in this batch?
- images
- INT
In ComfyUI a "batch" of images is just a stack - a tensor with N pictures in it. Loading a folder of video frames gives you a batch. Generating four variations gives you a batch of four. This node answers the one question that stack won't tell you on its own: how many are in there? It takes an IMAGE (batch) in and spits out a single integer count.
Doesn't sound like much, and on its own it isn't. Where it earns its place is when the count is dynamic and you need that number somewhere else in the graph. You loaded a sequence of unknown length; now you want to drive a loop, set a frame count on a video node, or compute a "last frame" index without hardcoding it. Anywhere a downstream node wants "how many frames" as a number, this is how you get it programmatically instead of counting by hand and typing it in.
How it works
It reads the length of the batch dimension of the image tensor and returns it. That's the entire mechanism. One image in a batch returns 1; sixteen frames return 16.
Inputs and outputs
- images - the image or batch to count.
Output is a single INT. Wire it into whatever needs the number - an integer math node to compute an offset, a frame-count input, a slice range, a loop bound.
Installing it
Lives in the comfyui_image_ops file. Install through ComfyUI Manager by searching Various ComfyUI Nodes by Type (comfyui-various), or clone it directly:
cd ComfyUI/custom_nodes
git clone https://github.com/jamesWalker55/comfyui-various
Restart ComfyUI. No model downloads, no extra dependencies for this node.
Common issues
There's genuinely almost nothing to break here - it counts, it returns a number, done. The only conceptual trip-up is remembering that the count is the batch size, not the total pixel count or the number of channels. If you pass a single image you'll get 1, which is correct even though it might feel odd.
Pair it with JWImageSequenceExtractFromBatch and it becomes properly useful: count the batch, do a bit of integer math to work out your start and stop indices, and slice out exactly the range you want without ever hardcoding a length that breaks the moment the input changes.
If the node appears red when you open a shared workflow, that's the pack simply not being installed - these JW utility nodes ride along inside other people's graphs constantly. Manager's "Install Missing Custom Nodes" or a clone of the repo above fixes it.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |