AK Replace Color with Alpha
Cut a flat background out and get a real transparent PNG
- image
- IMAGE
AK Replace Color with Alpha turns a solid background color into transparency. Feed it an image rendered on a flat background and it outputs an RGBA image where everything matching that background color is transparent - a real, alpha-carrying PNG you can drop onto any composite. It's the second half of the author's round-trip workflow: render on a flat color, do your generation, then strip the color back out before saving.
This is not a background-removal model. BiRefNet and friends segment the subject from anything; this node just matches a color. But that's precisely why it's fast, deterministic, and free of model downloads - and for flat-background renders (product shots, icons, poster mockups), it's often the more reliable tool anyway, because it isn't guessing where the subject ends.
How it works. It computes the RGB distance from every pixel to a target color, and pixels within the threshold get their alpha dropped to 0. softness turns that hard cut into a feather - pixels between threshold and threshold + softness get a gradual alpha ramp, which kills the harsh halo you get from a hard threshold on anti-aliased edges. That's the difference between a cutout that looks pasted and one that looks real.
The inputs that matter.
color_pick_mode- eitheruser_color, or one of four auto modes (left_top_pixel,right_top_pixel,left_bottom_pixel,right_bottom_pixel) that sample the actual corner pixel and use that as the target. Auto is great when your background is close to, but not exactly, pure black or white.color_rgb- your target color as a string like"8, 39, 245". Only used inuser_colormode.threshold(0–255) - how close a pixel must be to the target to go fully transparent.softness(0–255) - feather width for the transition edge.crop_size- a center crop, applied first. The README's tip: flat backgrounds render edge artifacts in the outermost pixels, and cropping them off before matching keeps stray fringes out of your alpha.
The output. One IMAGE, now with an alpha channel (4 channels). Save it as PNG to keep the transparency - JPEG will just flatten it to black and look like you deleted your alpha.
How to install. ComfyUI Manager (search "AK Pack") or:
cd ComfyUI/custom_nodes
git clone https://github.com/akawana/ComfyUI-Utils-extra
Restart ComfyUI. No dependencies, no models.
Where people get burned. threshold of 0 means only pixels that match the target color almost exactly go transparent - with any JPEG-ish gradient or noise in the background you'll get speckle. Start around 20–40 and raise softness to clean up the edge. The corner-pixel modes sample exactly one pixel, so a single bright spec stuck in the corner will set your target color to garbage; crop or clean first. And remember the RGBA output - several downstream nodes (including this pack's own AK Contrast & Saturate Image) want RGB and will error on 4 channels, so put the alpha conversion last, right before Save.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| crop_size | INT | 0 | — |
| color_pick_mode | COMBO | user_color | 5 options: user_color, left_top_pixel, right_top_pixel, left_bottom_pixel, right_bottom_pixel |
| color_rgb | STRING | 8, 39, 245 | — |
| threshold | INT | 00–255 | — |
| softness | INT | 00–255 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |