Batch Average
Slice an image or mask batch into even chunks and pick one
- images
- masks
- select_img
- exclude_img
- select_mask
- exclude_mask
You've got a batch of images or masks - a video's worth of frames, say - and you need to work on it in chunks instead of all at once, or you need to pull out just one chunk and keep the rest separate. That's what Batch_Average does: it cuts a batch into evenly-sized segments and hands you back both the segment you asked for and everything else, for images and masks at the same time.
This kind of windowed slicing is a familiar shape if you've dealt with long Wan video generation - the community's chunk-based extension nodes divide long clips into fixed-size windows for the same practical reason (a model or process that can only handle so many frames at once). Batch_Average isn't a video-specific node - it works on any image or mask batch - but it's the same underlying idea in generic form: divide, select, keep going.
How it works
You set division, which controls how many segments the batch gets split into. select then picks which segment comes out the select_img/select_mask side - and it supports negative indexing, so -1 grabs the last segment and -2 grabs the second-to-last, without you needing to know the exact segment count up front.
division_batch_n changes what division even means: off (default), it's the number of segments to split into; on, it's reinterpreted as the batch size per segment instead, and the node works out how many segments that implies.
Batches rarely divide evenly, so Complete_end controls what happens to the leftover tail: None just leaves it short, copy repeats the last frame to pad it out to a full segment, and mirror reflects the last few frames backward to fill the gap - the same ping-pong padding trick you'll see elsewhere in the ecosystem for handling frame counts that don't land on a clean boundary.
The inputs and outputs that matter
division(default 1, up to 4096) - segment count, or per-segment size ifdivision_batch_nis on.select(default 1, range -4096 to 4096) - which segment to pull out; negative counts from the end.division_batch_n(BOOLEAN, default false) - reinterpretsdivisionas a fixed batch size per segment.Complete_end-None/copy/mirror, how to pad an uneven final segment.images/masks(both optional) - feed either or both; the node processes whatever's connected.
Four outputs: select_img / select_mask (the segment you picked) and exclude_img / exclude_mask (everything else in the batch). Wire select_* into whatever processes one chunk at a time, and exclude_* back into a loop, a save node, or a later re-merge.
Installing it
Via ComfyUI Manager: search ComfyUI-WJNodes, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/807502278/ComfyUI-WJNodes.git
cd ComfyUI-WJNodes
pip install -r requirements.txt
No models, no heavy dependency - it's pure batch-indexing logic.
Common issues & troubleshooting
Selected segment isn't the size you expected. Check whether division_batch_n is on or off - it flips the meaning of division entirely, and it's the single easiest setting in this node to misread.
Last segment looks wrong or has duplicated/mirrored frames you didn't want. That's Complete_end doing exactly what it's set to do on an uneven split. Set it to None if you'd rather have a short final segment than a padded one.
Nothing comes out of exclude_img/exclude_mask. If your batch divides evenly into exactly division segments and you selected the only one, there may be nothing left to exclude past what the split logic already accounted for - check your actual batch size against division first.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| division | INT | 11–4096 | — |
| select | INT | 1-4096–4096 | — |
| division_batch_n | BOOLEAN | false | — |
| Complete_end | COMBO | 3 options: None, copy, mirror | |
| imagesopt | IMAGE | — | |
| masksopt | MASK | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| select_img | IMAGE | — |
| exclude_img | IMAGE | — |
| select_mask | MASK | — |
| exclude_mask | MASK | — |