Permute Mask Batch
Every combination of your detail masks, in one batch
- masks
- MASK
Automatic face detailing is a solved problem right up until it isn't. Impact Pack's FaceDetailer usually fixes the mangled face, and occasionally wrecks a perfectly good one - and the fix for that used to be re-running the detailer with a different prompt, eyeballing it, re-running again. What you actually want is to see all the possibilities at once: detail face A only, face B only, both, neither, and pick the winner. That's exactly what Permute Mask Batch is for.
This node from the tiny curiousjp/ComfyUI-MaskBatchPermutations pack takes a batch of masks and returns a new batch containing every possible subset of them. Feed it two masks, "A" and "B", and you get four masks back: empty, A, B, and A+B. Feed it three, and you get eight. The name is doing honest work - it's just an exhaustive permutation of your mask regions.
How it works
The mechanism is almost embarrassingly elegant, which is typical of this pack. Each mask in your input batch gets an index, and each index is treated as a bit position. The output is built by counting from 0 to 2ⁿ−1, where n is your mask count - because the count itself is a bit pattern, each number is the list of masks to include. Output 0 is the empty mask (all bits clear, i.e. nothing detailed). Output 3 (binary 11) is masks 0 and 1 combined. The combined masks are merged with a max, which for binary masks is a boolean OR - overlapping regions just union together.
The inputs and outputs that matter
Honestly, the whole node is one wire in and one wire out:
- masks (MASK) - a batch of masks. The intended source is Impact Pack's SEGS to Mask Batch node, which turns detected SEGS regions into a mask batch.
- MASK output - a new batch of 2ⁿ masks in binary-counting order, starting with the empty mask.
That's it. No settings, no model files, no hidden knobs.
Where it slots into a workflow
The README's example workflow shows the full loop: DetailerForEach → SEGS to Mask Batch → Permute Mask Batch → MasksToMaskList → MaskToImage → ImageCompositeMasked → ImageListToImageBatch → preview. In plainer terms: you generate all the region combinations as masks, then run a single detail pass per combination and preview the whole grid. It turns "should I detail the eyes, the mouth, or both?" from a guess into a browse-able decision.
How to install it
Same as any custom node - via ComfyUI Manager, search ComfyUI-MaskBatchPermutations, or:
cd ComfyUI/custom_nodes
git clone https://github.com/curiousjp/ComfyUI-MaskBatchPermutations
then restart ComfyUI. There's no requirements.txt, no model download, and the entire pack is a single MIT-licensed __init__.py that only imports torch. It's about the least risky install in the ecosystem - worth remembering, since most ComfyUI dependency pain comes from exactly the heavy packs this one doesn't pull in.
Where people get burned
The exponential. 2ⁿ is not your friend past a point. Three masks is a cozy eight combinations; eight masks is 256; ten is 1,024 masks all materialized in memory at once. If you're feeding it a whole crowd of detected faces, throttle the SEGS output or you'll discover VRAM pressure you didn't plan for.
Also worth knowing: the output order is binary counting, so it's empty, A, B, A+B, C, A+C, B+C, A+B+C - not "sensible groupings." Your preview grid will look scrambled until you notice the pattern. It's consistent, so you'll learn to read it in one run.
Reach for this node when you're comparing detail choices; skip it when you already know exactly which regions you want. It's a decision-making tool, not a daily-driver.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |