ComfyUI Node

AlphaFlatten

The cure for PNGs that look wrong against black

By keit0728·Created 2 years ago·Updated about a year ago· 3
AlphaFlatten
  • images
  • IMAGE

Every ComfyUI user hits this eventually: you've got an image with a nice transparent background, you composite it onto something or save it out, and it looks like garbage - dark halos, crushed edges, or a checkerboard where there should be white. That's an alpha compositing problem, and AlphaFlatten exists to solve the most common version of it by flattening transparency onto a white background.

The scenario that makes this node a life-saver is subtle but common. Lots of models - and lots of LoRA training datasets - are built around white-background images. When you feed those workflows a transparent PNG and it gets composited against whatever the default background color happens to be (frequently near-black), the result looks wrong even though every pixel's math is "correct." Flattening the alpha onto white up front gives you a stable RGB image that behaves identically everywhere, with no hidden transparency to trip up downstream nodes.

How it works

Straightforward alpha compositing, done in numpy on CPU. For each pixel it computes:

result = rgb * alpha + white * (1 - alpha)

which is the standard "over" compositing equation against a white backdrop (white = 1.0 in normalized float terms). The alpha channel is then dropped - the output is a clean 3-channel RGB image. If you feed it an image that has no alpha channel at all, it just passes it through untouched, which is a reasonable safety behavior even if it means "flattening" does nothing.

Inputs and output

  • images (IMAGE) - an RGBA (or RGB) image or batch. That's the only input.

Output is a single IMAGE tensor, RGB with no alpha. Handy if a node downstream refuses to consume RGBA, or if you're about to save a PNG and want the transparency baked in rather than stored as a channel.

One thing worth knowing: the background is hard-coded to white. There's no color picker, no checkbox for "flatten onto black instead." If you need a different backdrop - and for product shots or transparent overlays a black flatten is often the right call - you'll want a generic composite/blend node instead. This one does exactly one job.

Where it fits

It pairs naturally with the rest of this pack. BrightnessTransparency will turn a bright background transparent; AlphaFlatten is the bookend that bakes the result back down to a normal RGB image when you're done playing with the alpha. It's also the right cleanup step before training a LoRA on transparent assets - a consistent white background is a lot friendlier to the trainer than a pile of images where the background color varies.

Installing

Same pack, same drill:

cd ComfyUI/custom_nodes
git clone https://github.com/keit0728/ComfyUI-Image-Toolkit

Restart ComfyUI, or search "ComfyUI-Image-Toolkit" in ComfyUI Manager. The pack's single dependency is opencv-python==4.11.0.86 (pinned), and nothing here needs a GPU or a model download - this node is pure CPU math.

Gotchas

The "it does nothing on RGB images" behavior is worth remembering - if you feed this an image that already lost its alpha earlier in the graph, it silently passes through, which can hide bugs. And note the README's clone command contains a placeholder username (your-username); the real repo is keit0728/ComfyUI-Image-Toolkit. It's a tiny anonymous pack from a Japanese author, last touched in mid-2025 - expect it to work, and don't expect much support if it doesn't.

CategoryComfyUI-Image-Toolkit

Inputs (1)

NameTypeDefaultDescription
imagesIMAGEInput images to flatten alpha channel into RGB colors.

Outputs (1)

NameTypeDescription
IMAGEIMAGE