PS Flatten Image
Alpha Onto White
- images
- image
The name promises Photoshop's "Flatten Image" - merge all your layers down into one. What PS Flatten Image actually does is narrower and handier than that: it takes an image with an alpha channel and bakes that transparency onto a solid white background. If your workflow ends in a cutout (RMBG, BiRefNet, any background remover) or anything that emits RGBA, this is the node that stops your "transparent" PNG from coming out as black mush when you save it.
Here's the context that makes it click. After you remove a background, you've got an RGBA image - red, green, blue, plus an alpha channel. ComfyUI is inconsistent about what happens to that alpha downstream. Some nodes silently drop it, and the core SaveImage node doesn't carry alpha through, so transparency usually turns into black or a checkerboard preview rather than a clean background. The standard fix is compositing the cutout onto a real background before you save, and this node does exactly that for the most boring, most common background there is: white.
How it actually works
The mechanism is one line of standard "over" compositing, straight from the source:
result = rgb * alpha_expanded + white_bg * (1.0 - alpha_expanded)
For every frame, it takes the RGB, multiplies it by the alpha, and fills the transparent parts with white. Hard-edged cutout pixels get white edges, soft matted edges (hair, fur, glass) blend naturally. It runs on your GPU in torch, no model download, no extra dependency.
But read the name with suspicion, because the README oversells it. This node does not stack a batch of images on top of each other and merge them. It flattens each frame independently onto white. If you feed it a batch of RGBA frames - which is the "sequences (movies)" case the code comments mention - you get the same batch back, every frame flattened to its own white background. That's great for RGBA video, and it's not layer merging. If you feed it plain RGB, it does nothing at all: pure pass-through, no matter how many images are in the batch.
The one input that matters
images(IMAGE) - your RGBA or RGB image or batch. That's it. No widgets, no settings, no way to change the white background.
Output: image (IMAGE) - the flattened batch, ready to wire into SaveImage, PreviewImage, or another composite step.
The images input is the whole interface, which is both the appeal and the limitation.
Installing it
No dependencies, no models, no requirements.txt - it's a single file of torch. From the README:
cd ComfyUI/custom_nodes/
git clone https://github.com/ShmuelRonen/ComfyUI-PS_Flatten_Image.git
Restart ComfyUI and it appears under PS Operations in the node menu - search "flatten" and it shows up. It may also be findable via ComfyUI Manager if you search the pack title, but the clone is the documented, guaranteed route.
Where people get burned
- You fed it a normal image and nothing changed. Right - if the input has no alpha channel, this node is a pass-through by design. ComfyUI's
LoadImagegives you RGB plus a separate MASK output, not baked-in alpha, so a freshly loaded photo does nothing here. You need real RGBA: from a background remover in alpha mode, a matting model like BiRefNet, or LayerDiffusion output. - You expected a stack to merge. It won't. Each frame is flattened onto white on its own; there's no "bottom layer, top layer" compositing happening.
- You wanted a colored or image background. It's hard-coded to white. For anything else, reach for
ImageCompositeMaskedor a proper composite node instead - the KB's inpainting essay makes the same point: compositing a region back is the step people skip, and it's a single node when you use the right one.
Honestly, this is a tiny utility - 0 impressions on comfy.icu and near-zero community chatter, so you're unlikely to find it discussed anywhere. But for the narrow job of "cutout onto white before save," it's one node that does it correctly, including for video batches. Just don't ask it to flatten layers the way Photoshop does, because that half of the feature never shipped.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |