Smart Background Fill
Flatten your cutout onto a color in one node
- image
- mask
- IMAGE
So you cut a subject out with SmartBackgroundRemove and you've got a nice transparent-background image. Now you want to see it on a colored backdrop - white for a product shot, orange for a thumbnail, anything. Smart Background Fill does exactly that: it composites the transparent areas onto a solid color and hands you back a flat RGB image. It's the natural next node in the pipeline, and it saves you from building the same alpha-composite three times.
How it works
The node reads the image's alpha channel. Fully transparent pixels get the solid background color outright; semi-transparent pixels get a proper blend (original * alpha + background * (1 - alpha)) instead of a hard edge - so soft hair or feathered edges from a mask stay soft instead of turning into crunchy outlines. The output is always RGB, which is usually what you want after a cutout, and what most downstream nodes and samplers expect.
There's a wrinkle worth knowing: if you wire an optional mask in, the node uses that instead of the image's alpha channel (inverted, so mask 1.0 means "fill with background"). That's handy when your transparency lives in a separate mask rather than in the image itself - say after an AI matting pass that outputs a mask, not an RGBA image.
Inputs and outputs
image- your RGBA cutout. RGB input passes through unchanged (there's nothing to flatten).background_color- the same 15-color dropdown as the other Smart nodes:white,black,gray,red, and the rest. Note thattransparentis in the list but the code quietly falls back to white, because "fill with transparent" is a contradiction - don't pick it and wonder why nothing happened.mask(optional) - aMASKto drive the fill instead of the alpha channel.
Output: a single IMAGE in RGB, background baked in.
Installing it
Part of the ComfyUI-SmartImageTools pack:
cd ComfyUI/custom_nodes
git clone https://github.com/slvslvslv/ComfyUI-SmartImageTools
pip install -r ComfyUI-SmartImageTools/requirements.txt
Restart ComfyUI (or install "SmartImageTools" via ComfyUI Manager). No model files, no extra downloads beyond the pack's shared numpy/OpenCV/Pillow stack.
When to reach for it
After any background removal - flood-fill or AI matting - when the end result needs to sit on a solid color, whether for e-commerce flat-lays, social graphics, or just previewing the cutout against different backings to see where the edges look bad. The one thing it won't do is fill with anything besides a solid color. If you need a gradient or an image backdrop, composite those yourself with the standard blend/combine nodes - this one is deliberately a one-trick pony, and the trick is solid.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| background_color | COMBO | white | 15 options: transparent, red, green, blue, black, white, +9 |
| maskopt | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |