Nodes/ComfyUI-nhknodes/🎨 RGBA Flatten (nhk)
ComfyUI Node

🎨 RGBA Flatten (nhk)

Flatten transparent images onto a real background

By EnashkaΒ·Created 12 months agoΒ·Updated 30 days agoΒ· 23
🎨 RGBA Flatten (nhk)
  • image
  • mask
  • image
β—„background_color#FFFFFFβ–Ί
β—„alpha_threshold0.00β–Ί
β—„linear_blendfalseβ–Ί

If you've ever taken a transparent PNG and watched it come back with a nasty white or dark halo around the subject, you've met premultiplied alpha bleed. When an RGBA image with semi-transparent edge pixels gets composited or dropped onto a dark background, those edges carry the color they were designed against - and the result looks like a cheap cutout. RGBAFlatten is the node that eliminates that: it composites the RGBA image over a solid background color you choose, doing it properly so the edges blend instead of bleeding.

It lives in nhk/image of the nhknodes pack, and it's a genuinely useful little utility for anyone working with alpha-channel sources - AI cutouts, background-removed renders, PNG assets - before feeding them into models or pipelines that expect plain RGB.

How it works

The node takes your image, extracts the alpha channel, and does standard "over" compositing: out = foreground Γ— alpha + background Γ— (1 βˆ’ alpha). Every pixel is a weighted blend of the image and the background color. The result is a clean RGB image where the transparent areas are exactly your background color, and semi-transparent edges blend smoothly instead of carrying their original color as a fringe.

The key inputs:

  • background_color - a hex string, default #FFFFFF. #000000, #F2F2F2, whatever you need. It accepts 3-digit shorthand too. A malformed hex falls back to white, so typos don't crash anything.
  • mask (optional) - used if the image has no alpha channel. Note the ComfyUI convention: masks are inverted (1 = transparent), so the node flips it before blending. If you hand it a mask, that becomes the alpha.
  • alpha_threshold (default 0) - pixels with alpha below this value get treated as fully transparent. Leave at 0 to disable; nudge it up if your source has faint noise in supposedly-clear areas.
  • linear_blend (false) - blend in linear color space instead of sRGB. More physically accurate (no dark fringes from gamma), slightly slower. If you see halos at the default, turn this on.

One subtlety worth knowing: if the image has no alpha channel and no mask is connected, the node just passes the RGB through untouched - it won't invent transparency. So the three-channel case silently does nothing, which is correct behavior, not a bug.

Installing

Standard pack install:

cd ComfyUI/custom_nodes
git clone https://github.com/Enashka/ComfyUI-nhknodes

or ComfyUI Manager β†’ search "NHK Nodes" β†’ install β†’ restart. Under nhk/image, no extra dependencies. It works on batches too - each image in a batch is flattened individually.

Where people get burned

  • "It did nothing." Your image is already RGB with no alpha and no mask. That's by design. Add a mask, or check the source actually has an alpha channel.
  • "White edge still there." If your asset has hard semi-transparent pixels, alpha_threshold can clean them up - push pixels near-zero alpha to full transparency so the background wins. And try linear_blend for the fringe problem specifically.
  • Mask looks backwards. ComfyUI masks are 1 = transparent. If you connected a mask and the result is inverted, that's the convention biting you - the node already expects ComfyUI's orientation.

RGBAFlatten is one of those nodes you don't think about until you need it, and then it saves you an afternoon. For anyone doing background-removal workflows or compositing cutouts onto new scenes, it's the difference between "looks cut out" and "looks placed."

Categorynhk/image

Inputs (5)

NameTypeDefaultDescription
imageIMAGEInput image (RGB or RGBA)
background_colorSTRING#FFFFFFBackground color as hex (e.g., #FFFFFF, #000000, #F2F2F2)
maskoptMASKOptional mask input (used if image has no alpha channel)
alpha_thresholdoptFLOAT0.000–1Pixels with alpha below this are treated as fully transparent (0.0 = disabled)
linear_blendoptBOOLEANfalseBlend in linear color space (more accurate, slower)

Outputs (1)

NameTypeDescription
imageIMAGEβ€”