Change Background of Image (SEGM SEGS)
Swap a Photo's Background With a Two-Pass Inpainting Sampler
- model
- model_2
- positive
- positive_2
- negative
- negative_2
- image
- vae
- segs_from_SEGM_Detector
- IMAGE
Take a photo of a person, keep the person, generate a brand-new background around them - that's this node. It's not a background-removal tool in the BiRefNet sense (see the KB essay on why you should pick your cutout model by failure mode); it's a generative background replacer. It decides what's foreground and what's background from a mask, regenerates the background with a sampler, then runs a second pass over the whole image to blend the seam. Two passes, two checkpoints, one output.
Why you'd reach for it
When you want the subject preserved exactly and the scene around them reinvented - putting a portrait on a beach, dropping a product onto a studio backdrop. The key difference from compositing: the new background is generated, so it's lit and textured by the same model that made the subject, which makes it blend far better than pasting a cutout onto a stock photo. The KB's inpainting essay is relevant context here: this is the "mask still wins" case where you want the subject pixels untouched, which is exactly what a masked inpaint pass guarantees and what edit-models can't.
How it works
It's an inpainting sampler built on Impact Pack's output. You feed it SEGS from Impact Pack's SEGM Detector (the node that finds the person/object and produces a mask), and the node builds a mask from those segs - the code is literally borrowed from Impact Pack for compatibility. That mask is inverted (background becomes the region to regenerate), grown a few pixels so the latent-space seam stays clean, and used as the noise mask for a first sampling pass that fills in the background according to your positive/negative. Then the whole image is resampled with the second model and conditioning at low denoise (default 0.4) and no mask, which is what blends everything together.
Inputs and outputs
The long input list is really three groups:
- Who does what:
model/positive/negativedrive the background pass;model_2/positive_2/negative_2drive the blend pass. They can be the same model - most people use one checkpoint for both and just write a background description inpositiveand a whole-scene description inpositive_2. - The subject:
image(your photo),vae(for encode/decode), andsegs_from_SEGM_Detector(the mask, from Impact Pack's SEGM Detector). - The dials:
seed,steps(20),steps_2(12),cfg(8),sampler_name,scheduler,denoise(1.0) anddenoise_2(0.4).
One output: IMAGE, the finished composite.
Installing it
Part of "quadmoon's ComfyUI nodes", but it has a real dependency: Impact Pack must be installed for the SEGS input to exist. Install both:
cd ComfyUI/custom_nodes
git clone https://github.com/traugdor/ComfyUI-quadMoons-nodes.git
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack.git
Or use ComfyUI Manager for both (search "quadmoon's ComfyUI nodes" and "Impact Pack"). Restart ComfyUI. No extra model downloads for the node itself - though the SEGM detector may want its own detection model, which Impact Pack guides you through.
Common issues
The usual failure is the seam: if you see a hard edge around the subject, denoise_2 is doing too little work - nudge it up toward 0.5. Crank it too far and you get a subject that drifts from the original, because the second pass is un-masked and re-draws everything. Also, your input image dimensions should be multiples of the VAE's downscale factor or the node crops a few pixels off an edge (it handles this internally, but it's why a 512x512-friendly input is safest).
Inputs (17)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| model_2 | MODEL | — | |
| positive | CONDITIONING | — | |
| positive_2 | CONDITIONING | — | |
| negative | CONDITIONING | — | |
| negative_2 | CONDITIONING | — | |
| image | IMAGE | — | |
| vae | VAE | — | |
| segs_from_SEGM_Detector | SEGS | — | |
| seed | INT | 00–18446744073709550000 | — |
| steps | INT | 201–10000 | — |
| steps_2 | INT | 121–10000 | — |
| cfg | FLOAT | 8.00–100 | — |
| sampler_name | COMBO | 44 options: euler, euler_cfg_pp, euler_ancestral, euler_ancestral_cfg_pp, heun, heunpp2, +38 | |
| scheduler | COMBO | 9 options: simple, sgm_uniform, karras, exponential, ddim_uniform, beta, +3 | |
| denoise | FLOAT | 1.000–1 | — |
| denoise_2 | FLOAT | 0.400–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |