Nodes/Remove Background (SET)/Get background mask
ComfyUI Node

Get background mask

Get background mask — the cutout without the cutting

By set-soft·Created about a year ago·Updated 9 months ago· 18
Get background mask
  • model
  • images
  • depths
  • masks
  • depths
  • edges
width1024
height1024
upscale_methodbicubic
mask_threshold0.000
batch_size1
out_dtypeAUTO

Most of the time you don't actually want a transparent image - you want the mask that says which pixels are the subject. That's what this node gives you, and it's the right tool whenever the next step in your workflow isn't "save a cutout" but something like "composite onto a new scene," "inpaint behind the subject," or "feed a mask to a mask-aware node." It runs the full pre/post-processing pipeline - normalize, scale to model size, run the network, scale the mask back - and stops before removing or replacing anything.

It sits in the RemBG_SET/Basic category and is the middle child of the pack's three mask nodes: Remove background (does everything), this one (mask with sane defaults), and Get background mask low level (raw, no processing - see its article). If you're reaching for this, you already know you need the mask as a first-class output.

The inputs that matter

  • model (SET_REMBG) - from any loader in the pack.
  • images (IMAGE) - scaled internally to a model-friendly size.
  • width / height (default 1024, step 32) - the pre-processing size, and the tooltip is explicit: does not affect the final output mask size. Most models accept any multiple of 32; the train_w/train_h outputs from a loader node are the right values to wire in here.
  • upscale_method (default bicubic) - interpolation for scaling in and out. Bicubic is a fine default.
  • mask_threshold (default 0) - leave at 0 to keep soft fractional values (matter for matte models); set something like 0.5 to force a hard 0/1 mask. A higher value means the model is more confident the pixel is foreground.
  • batch_size - raise for video/batch; the README notes RTX 3060-class boards are better off at 1.
  • depths (optional) - externally computed depth maps, only relevant for PDFNet.
  • out_dtype - float16 to halve memory on long video jobs.

Outputs

  • masks (MASK) - the foreground mask, higher = more confident.
  • depths (MASK) - the depth map (only PDFNet generates one).
  • edges (MASK) - edge map (only DiffDIS generates one).

Wire masks into compositing, inpainting, or anything else that eats a mask.

Install and troubleshooting

Standard pack install: ComfyUI Manager search "Remove Background (SET)", or

cd ComfyUI/custom_nodes
git clone https://github.com/set-soft/ComfyUI-RemoveBackground_SET
pip install -r ComfyUI-RemoveBackground_SET/requirements.txt

ComfyUI 0.3.48+, seconohe >= 1.0.6 (fresh pip install git+https://github.com/set-soft/seconohe.git if it errors). Models land in ComfyUI/models/rembg.

If the mask looks soft at the edges, that's the model being honest, not a bug - raise mask_threshold or switch to a matting checkpoint if you need clean alpha. And remember the wider lesson from the background-removal discourse: a mask that looks great against a grey preview can fall apart composited onto a coloured background, so judge it in context. This node is the pack's polite middle ground - all the control of the advanced node, none of the output clutter.

CategoryRemBG_SET/Basic

Inputs (9)

NameTypeDefaultDescription
modelSET_REMBGThe remove background model from `Load RemBG model by file` or any of the `Load XXXXXX model by name` nodes
imagesIMAGEOne or more images to process, will be scaled to a size that is good for the model.
widthINT10240–16384The width of the pre-processing image, does not affect the final output image size
heightINT10240–16384The height of the pre-processing image, does not affect the final output image size
upscale_methodCOMBObicubicInterpolation method for pre-processing image and post-processing mask
mask_thresholdFLOAT0.0000–1Most models generates masks that contain a value from 0 to 1, but can be any value in between. Matte models can estimate transparency using it. If you need to make the mask 0 or 1, but nothing in between, you can provide a threshold here. Values above it will become 1 and the rest 0.
batch_sizeINT11–256How many images to process at once
depthsoptMASKFor models that starts with a depth map
out_dtypeoptCOMBOAUTOData type used for the outputs. `AUTO` means the same as the input.Using `float16` can help when processing videos.

Outputs (3)

NameTypeDescription
masksMASKThe estimated masks, where a higher value means the model estimates it belongs to the foreground with more confidence.
depthsMASKThe estimated depth map. Either from the `depths` input or computed. Note this applies only to PDFNet. This is the map generated by `Depth Anything V2`
edgesMASKThe estimated edges. This is only generated by the DiffDIS model.