Nodes/ComfyUI-UtilsCollection/Unified Background Replace
ComfyUI Node

Unified Background Replace

Drop a whole cast onto one background in a single queue

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Unified Background Replace
  • background
  • foreground_images
  • background_removal_model
  • images
  • masks
foreground_scale0.90
long_axis_shift0.00
short_axis_shift0.00
mask_threshold0.50
border_cleanup_width2
artifact_cleanup_radius2
gap_fill_radius2
feather_radius2
image_resize_methodauto
mask_resize_methodauto
workspace_padding0.50

Most background-replacement nodes handle one subject at a time. This one takes up to fifty foreground images, cuts them all out, and independently places each one over a single shared background - all in one queue, with per-foreground outputs you can inspect and composite yourself. If you've ever manually re-ran a cutout node fifty times to build a group shot, you know why this exists.

What it is

A batch background-replace node. It uses an internal BiRefNet model to segment each foreground, cleans up the masks, resizes each cutout relative to the shared canvas, positions it with two shift sliders, and composites. The important design choice: each foreground gets its own output image and mask, rather than everything stacked into one final composite. That means you can check every placement before committing, and the compositing control stays in your hands.

How it works

The pipeline per foreground: BiRefNet produces a soft mask → mask_threshold (0.5) decides what counts as solid foreground → border_cleanup_width strips weak predictions at the source edges → artifact_cleanup_radius (opening) removes small specks → gap_fill_radius (closing) fills cracks and holes → feather_radius softens the edge inward while keeping the interior opaque.

Sizing and placement are the clever part. foreground_scale is defined as the fraction of the background's shortest side occupied by the foreground's longest bound - 0.9 default means the subject nearly fills the canvas; values above 1 overscale and crop at the edges. long_axis_shift and short_axis_shift slide it along the background's long and short axes, each from -1 (one end) through 0 (center) to 1 (the other end). workspace_padding (0.5 default) lets placements sit partly off-canvas by up to 25% per axis, which is how you get natural edge-cropped compositions instead of everything floaty in the middle.

The inputs that matter

  • background - the single shared canvas.
  • foreground_images - the autogrow batch of subjects to cut out and place.
  • foreground_scale - size relative to the background's short side.
  • long_axis_shift / short_axis_shift - placement.
  • mask_threshold - how confident the model must be to keep a pixel.
  • background_removal_model (optional) - plug in a Core background-removal model to override the internal BiRefNet.

Outputs: images (the composed results) and masks (the placement masks for each output) - both IMAGE/MASK, sized to match the number of foregrounds.

Installing it

Part of ComfyUI-UtilsCollection:

cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection

Restart ComfyUI (or use Manager, search "ComfyUI-UtilsCollection"). No model download step on your end - BiRefNet is pulled from the Comfy-Org repo the first time the node runs. The pack's own deps are minimal and it needs a recent ComfyUI, since BiRefNet support and the background-removal model type are Core features from 2026.

Common issues

BiRefNet is the right default for hair and fur - that's exactly what it beats the old u2net at - but fine hair at low mask_threshold can still fuzz out, so raise it if you get halos, lower it if you lose strands. Watch foreground_scale: above 1.0 you're intentionally cropping, which surprises people the first time a subject's head vanishes. And with 50 foregrounds, memory adds up - the node is batch-happy, but your GPU isn't infinite. If the internal model's first run is slow, that's the one-time download, not a hang.

Categoryutils/image

Inputs (14)

NameTypeDefaultDescription
backgroundIMAGESingle image used as the shared output canvas.
foreground_scaleFLOAT0.900.05–10Fraction of the background's shortest side occupied by the foreground's longest bound. Values above 1 overscale and crop at the canvas edges.
long_axis_shiftFLOAT0.00-1–1Position along the background's longest axis: -1 is left/up, 0 is centered, and 1 is right/down.
short_axis_shiftFLOAT0.00-1–1Position along the background's shortest axis: -1 is up/left, 0 is centered, and 1 is down/right.
mask_thresholdFLOAT0.500–1Minimum model confidence retained as solid foreground.
border_cleanup_widthINT20–64Width of the source-edge strip where weak foreground predictions are removed.
artifact_cleanup_radiusINT20–64Opening radius used to remove small and thin mask artifacts.
gap_fill_radiusINT20–64Closing radius used to fill small cracks and holes in the foreground.
feather_radiusINT20–64Inward edge softness; the foreground interior remains fully opaque.
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.
workspace_paddingFLOAT0.500–1Permitted off-canvas placement margin, up to 25% of each background axis.
foreground_imagesCOMFY_AUTOGROW_V3Images to isolate, resize, and position over the background; each flattened image produces an independent output.
background_removal_modeloptBACKGROUND_REMOVALOptional Core background-removal model. Uses the internal BiRefNet model when disconnected.

Outputs (2)

NameTypeDescription
imagesIMAGE
masksMASK