ComfyUI Node

Auto Person Mask

One-click person mask, with one dependency the README forgets to mention

By diffussy69·Created 11 months ago·Updated 9 months ago· 2
Auto Person Mask
  • image
  • person_mask
  • masked_image
model
alpha_mattingfalse
alpha_matting_foreground_threshold240
alpha_matting_background_threshold10
alpha_matting_erode_size10
post_process_maskfalse
show_debugfalse

Feed this node an image, and it hands you a mask of the person plus a cut-out version, no prompt engineering required. It's the pack's shortcut for "give me the subject as a mask" - the kind of thing you reach for when you want to inpaint the background, drive a regional prompt from the person, or swap a background in a ControlNet workflow. It does exactly what it says. Just know what it's actually running underneath, because the README is quietly silent on it.

How it works

The node is a thin wrapper around rembg - the standard background-removal library. rembg spins up a U2-Net ONNX model, runs it over your image, and returns the alpha. The node then converts that into a person_mask tensor and a masked_image (the person composited on a transparent background, represented as an image). There's no magic here; it's the same segmentation pipeline that's been in the ecosystem since 2020, packaged as a node.

You pick the segmenter through the model dropdown:

  • u2net - the general-purpose default.
  • u2netp - the lightweight, faster one.
  • u2net_human_seg - tuned for people, which is usually the right call for a person mask.
  • silueta - same network as u2net at a smaller size.

The settings that matter

  • alpha_matting - better edge quality, noticeably slower. Turn it on when the default edges look ragged.
  • alpha_matting_foreground_threshold / alpha_matting_background_threshold / alpha_matting_erode_size - matting tuning; defaults (240 / 10 / 10) are a fine starting point, only touch these if edges go mushy.
  • post_process_mask - runs morphological cleanup to tidy stray specks. Cheap, usually worth it.

Outputs are person_mask (MASK) and masked_image (IMAGE). The mask feeds regional prompting, the temporal combiner, or an inpaint; the masked image is handy for compositing or a quick preview.

The dependency the README doesn't mention

The README lists matplotlib pillow numpy torch scipy and stops. This node also needs rembg, and it's not in that list. Install it or the node throws at runtime:

pip install rembg

First run downloads the U2-Net ONNX weights (roughly 150–170MB), so don't panic at the stall on your first execution. It also needs onnxruntime - rembg pulls that in as a dependency, but if you're on a constrained setup, be ready for it.

Honest take

U2-Net is old and it shows. On clean studio shots - a person against a plain background - it's great, fast, and runs fine on CPU. On hair, fur, and transparent fabrics it produces exactly the kind of messy edges the background-removal crowd has been complaining about since 2020. If you're masking for a regional prompt, that's often fine. If you need a crisp cutout for compositing, you'll get better results from a BiRefNet node elsewhere in the ecosystem and save this one for quick jobs. It's a free win when it fits, not a replacement for careful masking.

Categorymask

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
modelCOMBO4 options: u2net, u2netp, u2net_human_seg, silueta
alpha_mattingoptBOOLEANfalseBetter edge quality but slower
alpha_matting_foreground_thresholdoptINT2400–255
alpha_matting_background_thresholdoptINT100–255
alpha_matting_erode_sizeoptINT100–50
post_process_maskoptBOOLEANfalseClean up mask with morphological operations
show_debugoptBOOLEANfalse

Outputs (2)

NameTypeDescription
person_maskMASK
masked_imageIMAGE