Layered Background Composite
Cut, place, and layer subjects onto a new background without Photoshop
- background
- foreground_images
- background_removal_model
- image
- mask
Most background-removal nodes just give you a cutout. UC_LayeredBackgroundComposite is the step after that: it removes the background from one or more foreground images, lets you position each one independently on a background canvas in a scene editor, and composites the whole stack into one image. It's a mini photo-compositor living inside a ComfyUI node - background plate, subject layer, another subject in front, and a placement tool to arrange them.
Reach for it when a simple "swap the background" isn't enough: a character standing in front of a building, a product shot on a new surface with a foreground element overlapping it, a two-subject scene where one walks in front of the other. The layered approach means you control occlusion order, not just which pixels are kept.
How it works
Each foreground image is background-removed, then cleaned up, then becomes a placeable layer. The segmentation is BiRefNet under the hood - ComfyUI shipped BiRefNet in core and it's the current default for hard edges like hair. You can disconnect the optional background_removal_model input to use the pack's internal BiRefNet, or wire in a Core background-removal model you already have.
The cleanup knobs are the four radii/thresholds people actually tune:
- mask_threshold (0.5) - how confident the removal must be before a pixel counts as foreground.
- border_cleanup_width (2) - strips weak foreground predictions along the source image's edge. Useful because BiRefNet tends to smear onto the frame border.
- artifact_cleanup_radius (2) - opening radius; kills small speckles and thin stray predictions.
- gap_fill_radius (2) - closing radius; fills cracks and holes in the mask. feather_radius (2) then softens the inward mask edge so the cutout doesn't look pasted-on.
There's also image_resize_method / mask_resize_method (default auto picks sensible resampling per direction), and the placement_data string - a versioned JSON blob that the LiteGraph scene editor manages for you. You don't hand-edit it; the node writes it as you drag layers around. foreground_images is an autogrowing socket, so add as many foreground layers as you need (the schema allows up to 50, but compositing sanity runs out well before that).
Outputs: a final image and the combined mask for the whole composite.
Where it sits in the pack
This is the single-shot version of the compositing family. The pack also ships UC_StagedLayeredBackgroundComposite (retains cutouts, with a staging run where you place subjects before committing), UC_StagedIndividualComposites, and face-specific variants. If you want the workflow where you run once, adjust placements in the editor, then re-run without recomputing the removals, the staged variant is the upgrade path. This node is the "just composite it now" option.
Install and gotchas
cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection
Restart (or ComfyUI Manager → search "ComfyUI-UtilsCollection"). The pack's own deps are opencv-python and typing-extensions. BiRefNet weights download on first use through ComfyUI's model system - you don't fetch them by hand.
Two things to know. First, hair and fur are still the enemy; if the cutout edge looks bad, raise the feather a notch and check mask_threshold before blaming the node. Second, all foregrounds must share a compatible resolution story - wildly different-sized inputs get resampled, which is where quality quietly leaks. Keep sources roughly consistent and this node is genuinely pleasant to use.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| background | IMAGE | Single image used as the scene canvas. | |
| mask_threshold | FLOAT | 0.500–1 | Minimum background-removal confidence retained as foreground before cleanup. |
| border_cleanup_width | INT | 20–64 | Source-edge strip width in pixels where weak foreground predictions are removed; 0 disables it. |
| artifact_cleanup_radius | INT | 20–64 | Opening radius in pixels used to remove small or thin mask artifacts; 0 disables it. |
| gap_fill_radius | INT | 20–64 | Closing radius in pixels used to fill small mask cracks and holes; 0 disables it. |
| feather_radius | INT | 20–64 | Inward mask-edge softness in pixels; 0 keeps the resized edge unchanged. |
| image_resize_method | COMBO | auto | Foreground resampling method. auto uses FP32 area reduction when shrinking and bicubic when enlarging; choose another method to override it. |
| mask_resize_method | COMBO | auto | Mask resampling method. auto uses area when shrinking and bilinear when enlarging while preserving soft coverage; nearest-exact produces a hard binary edge. |
| placement_data | STRING | {"version":2,"workspace_padding":0.5,"layers":{}} | Versioned per-layer placement data managed by the LiteGraph scene editor. |
| foreground_images | COMFY_AUTOGROW_V3 | One image per socket, composited from foreground_0 at the back to the highest socket at the front. | |
| background_removal_modelopt | BACKGROUND_REMOVAL | Optional Core background-removal model. Uses the internal BiRefNet model when disconnected. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |