Nodes/ComfyUI-MaskBatchPermutations/Flatten Batch against Original
ComfyUI Node

Flatten Batch against Original

The pack's invisible third node, and the alpha trap that catches everyone

By curiousjp·Created 2 years ago·Updated 2 years ago· 5
Flatten Batch against Original
  • base_image
  • candidates
  • IMAGE

Here's something the README won't tell you: curiousjp/ComfyUI-MaskBatchPermutations ships a third node, and the README's own headline - "provides two nodes" - never mentions it. It's called Flatten Batch against Original, and it's the oldest tool in the pack, the one the author originally built in mid-2024 to solve the same "the detailer wrecked the face, now stitch the good parts back" problem that Combinatorial Detailer later automated. If you want the raw compositing primitive instead of the all-in-one, this is it.

It does one thing: takes a base image plus a batch of candidate images and alpha-composites every candidate over the base, in order, producing a single flattened result per base image. In the detailer workflow that's the hand-stitching step - you run a couple of separate passes, get back transparent overlays of where each one changed things, and this node stacks them onto the original so you don't have to fire up GIMP.

The trap - and it's a real one, people have been here

This is the node people actually google, because it has a sharp edge: candidates must be RGBA, not RGB. The code reads every candidate's alpha channel unconditionally as the last channel - c[..., -1:]. Feed it a plain 3-channel RGB image and that "alpha" is actually your blue channel, and you get a black/garbage overlay that makes zero sense.

This isn't a theoretical edge case. On r/comfyui in May 2024, a user posted about spending hours on exactly this with this exact node - the PNG kept coming out with a black overlay and they couldn't see the base image through it. The author personally walked them through it, then rewrote the node's compositing to be RGBA-aware the same week. The lesson stuck: check your candidates are RGBA (the base image can be 3 or 4 channels and gets handled either way, but candidates are always assumed 4-channel). If you're feeding in ImageBatch outputs from PreviewImage-style paths, you almost certainly need a convert-to-RGBA node in front.

Inputs, outputs, and the mechanism

  • base_image (IMAGE) - what everything gets composited onto. Batchable: you get one output per base frame.
  • candidates (IMAGE) - the stack of transparent overlays to flatten on top.
  • IMAGE output - the composited result, one per base image.

Mechanically it's straight "over" alpha compositing, the standard Porter-Duff operation: output alpha is candidate alpha plus base alpha times one-minus-candidate-alpha, and RGB is blended in premultiplied space. No masking input, no blend modes, no feathering - it's deliberately low-level, and if you understand alpha you can predict exactly what it'll do.

Installing it

Same pack, same boring answer: ComfyUI Manager → search ComfyUI-MaskBatchPermutations, or

cd ComfyUI/custom_nodes
git clone https://github.com/curiousjp/ComfyUI-MaskBatchPermutations

restart, done. No dependencies beyond torch, no models to download, MIT licensed. It's as low-risk as a custom node gets.

When to reach for it

Combinatorial Detailer is the fancier sibling, but this node is still the right call when you already have your candidates and just want them stitched onto the original in one node - a small stack of overlay passes, a batch of frames, no need for the exponential-combination machinery. It's a quiet utility that does exactly one thing, and once you've hit the RGBA gotcha once, you'll never hit it again.

Categoryimage

Inputs (2)

NameTypeDefaultDescription
base_imageIMAGE
candidatesIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE