Image Batch Count XYZ
Auto-detect how a batch is actually laid out
- images
- x_black
- y_white
- z_black
Here's a genuinely weird one, and it deserves an honest explainer. Image Batch Count XYZ looks at a batch of images, classifies each frame as "white" or "black" by its average brightness against a threshold, and reports three integers: x_black, y_white, and z_black - how many black frames came before the white run, how many white frames are in it, and how many black frames follow.
Why would you ever need that? Think of an XYZ-plot workflow that packs its results into a single batch and uses black separator frames to encode layout - or any pipeline that produces a batch where the number of frames is variable and the structure matters. This node answers "how big is this batch, really, and where are the separators" without you hardcoding a count. y_white is effectively the number of real frames in the white run, and x/z tell you what's bracketing it. The source computes mean brightness over RGB (ignoring the alpha channel so RGBA doesn't skew the numbers) and treats brightness ≥ threshold as white.
The edge cases are where you can get caught. An all-black batch returns (0, 0, 0). An all-white batch returns (0, batch_size, 0). Otherwise it finds the first and last white frame and reports the counts around and inside that run. Note the subtle assumption buried in there: it reports the first contiguous white run - it isn't counting arbitrary patterns, it's counting a single white block surrounded by black.
Honestly? This is a niche node built around the pack author's own XYZ-plot workflow, and it shows. It sits naturally next to the pack's Image Batch Interleave and Interleave Split, which reorder exactly the kind of batches this counts. If you're not running a separator-frame XYZ pipeline, you may never need it.
Inputs and outputs that matter
- images (in) - the batch to inspect.
- threshold (in) - brightness cutoff, 0–1, default 0.5. Frames averaging above it count as white.
- x_black / y_white / z_black (out) - the three counts as INTs.
Installing it
Part of wenchengxiang/ComfyUI-Practical-Tools. ComfyUI Manager → Custom Nodes Manager → search "ComfyUI-Practical-Tools" → Install → restart. Or clone:
cd ComfyUI/custom_nodes
git clone https://github.com/wenchengxiang/ComfyUI-Practical-Tools
and restart. No pip dependencies, no models - pure Python.
Issues and gotchas
The threshold is doing more work than it looks. A default of 0.5 on a dark-ish image can classify a "black" separator as white, or vice versa, and since everything downstream trusts those three numbers, a bad threshold silently poisons the layout math. If you're feeding an all-black or all-white batch through, remember the special-case outputs above - (0,0,0) and (0, batch, 0) are by design, not a bug. It's a tool you'll use precisely when you have a workflow that needs it, and ignore otherwise.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| threshold | FLOAT | 0.500–1 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| x_black | INT | — |
| y_white | INT | — |
| z_black | INT | — |