Nodes/ComfyUI-UtilsCollection/Layered Background Composite
ComfyUI Node

Layered Background Composite

Cut, place, and layer subjects onto a new background without Photoshop

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Layered Background Composite
  • background
  • foreground_images
  • background_removal_model
  • image
  • mask
mask_threshold0.50
border_cleanup_width2
artifact_cleanup_radius2
gap_fill_radius2
feather_radius2
image_resize_methodauto
mask_resize_methodauto
placement_data{"version":2,"workspace_padding":0.5,"layers":{}}

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.

Categoryutils/image

Inputs (11)

NameTypeDefaultDescription
backgroundIMAGESingle image used as the scene canvas.
mask_thresholdFLOAT0.500–1Minimum background-removal confidence retained as foreground before cleanup.
border_cleanup_widthINT20–64Source-edge strip width in pixels where weak foreground predictions are removed; 0 disables it.
artifact_cleanup_radiusINT20–64Opening radius in pixels used to remove small or thin mask artifacts; 0 disables it.
gap_fill_radiusINT20–64Closing radius in pixels used to fill small mask cracks and holes; 0 disables it.
feather_radiusINT20–64Inward mask-edge softness in pixels; 0 keeps the resized edge unchanged.
image_resize_methodCOMBOautoForeground resampling method. auto uses FP32 area reduction when shrinking and bicubic when enlarging; choose another method to override it.
mask_resize_methodCOMBOautoMask resampling method. auto uses area when shrinking and bilinear when enlarging while preserving soft coverage; nearest-exact produces a hard binary edge.
placement_dataSTRING{"version":2,"workspace_padding":0.5,"layers":{}}Versioned per-layer placement data managed by the LiteGraph scene editor.
foreground_imagesCOMFY_AUTOGROW_V3One image per socket, composited from foreground_0 at the back to the highest socket at the front.
background_removal_modeloptBACKGROUND_REMOVALOptional Core background-removal model. Uses the internal BiRefNet model when disconnected.

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK