Apply Mask using AFFCE
Apply a background-removal mask without the edge halo
- images
- masks
- image
- mask
You've got a mask from a background-removal model and you want to actually use it - cut the background out and get a transparent PNG, or drop the subject on a new background. Naively multiplying the image by the mask is how you get those ugly hard-edged cutouts with background color smeared along the hairline. This node exists so you don't do that. It's the "apply this mask properly" step, and it does the job by running AFFCE (Approximate Fast Foreground Colour Estimation) on your image + mask, then compositing the result onto transparency or a color.
If that sounds like the Estimate foreground (AFFCE) node with extra steps - you're half right. The sibling node only estimates the clean foreground and hands it back to you for manual compositing. This one packages the estimation and the cutout into a single image output, which is what you actually want 90% of the time. The AFFCE engine is the same: a two-pass blur-and-fuse algorithm, ported to pure PyTorch from the Photoroom fast-foreground-estimation work (via BiRefNet's image processing code), that recovers the true foreground color where the pixels are a mix of subject and background.
The inputs that matter
- images - the subject on its original background.
- masks - the alpha matte telling it what's foreground and what's background.
- fill_color - the big decision. Off (default): you get an RGBA image with the background made transparent. On: the background is replaced by
colorand you get a plain RGB image. Turn it on if a downstream node can't handle alpha. - color - the fill color when
fill_coloris on; hex#RRGGBBor comma-separated RGB in 0–255 or 0.0–1.0. - blur_size / blur_size_two - the coarse and fine blur diameters driving the estimation. Defaults (90 and 6) work for most photos; raise the first for very soft edges, drop the second for more detail.
- batched - process the whole batch at once (faster, more VRAM) or one image at a time.
Outputs are image and mask. The mask output is just your input mask echoed back - handy for keeping the pipeline tidy, not a new result.
Installing it
Same pack, same drill. ComfyUI Manager → "Image Misc", or:
cd ComfyUI/custom_nodes
git clone https://github.com/set-soft/ComfyUI-ImageMisc
cd ComfyUI-ImageMisc && pip install -r requirements.txt
Restart, find it under image/manipulation. No model downloads - it's pure PyTorch on top of ComfyUI's stack, which is the pack's whole point.
Where it falls short
AFFCE is fast and free, but it's approximate. On semi-transparent material - glass, veils, smoke - no blur-and-fuse pass can reconstruct detail that the original image genuinely blended away; for those you want the pack's FMLFE node (a real multi-level solver that also produces a background plate) or a matting-specific model. And remember this node does not sharpen your mask: feed it a blurry, noisy mask and you'll get the halo gone but the fuzziness baked in. Clean masks in, clean cutouts out. For the common case - a decent BiRefNet-style mask on a portrait - this is the one-step node that just works, and it costs nothing to run.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| masks | MASK | — | |
| blur_size | INT | 901–255 | — |
| blur_size_two | INT | 61–255 | — |
| fill_color | BOOLEAN | false | Fill the background using a color. Returns an RGB image, otherwise an RGBA. |
| color | STRING | #000000 | Color for fill. Can be an hexadecimal (#RRGGBB). Can comma separated RGB values in [0-255] or [0-1.0] range. |
| batched | BOOLEAN | true | Process the images at once. Faster, needs more memory |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |