Nodes/a-person-mask-generator/A Person Mask Generator
ComfyUI Node

A Person Mask Generator

A Person Mask Generator — ComfyUI Node Guide

By djbielejeski·Created 3 years ago·Updated 6 months ago· 404
A Person Mask Generator
  • images
  • masks
face_masktrue
background_maskfalse
hair_maskfalse
body_maskfalse
clothes_maskfalse
confidence0.40
refine_masktrue

If you've ever hand-painted a mask around someone's hair just to change its color, or drawn a rough outline around a shirt so you could swap it in img2img, this node exists to save you that fifteen minutes. Feed it a photo of a person and it hands back a mask of whichever part you asked for - face, hair, body, clothes, or the background - without you touching a lasso tool. It's not a general background remover like BiRefNet or rembg, which just split foreground from background; this one is built specifically to slice up a person, and that specificity is the whole point.

Under the hood it's running Google's multi-class selfie segmentation model via MediaPipe - the same on-device, Apache-2.0 library that shows up all over this ecosystem whenever a tool needs to find or crop a face without touching InsightFace's non-commercial-licensed models. MediaPipe doesn't know who anyone is (that's identity-embedding territory, a different problem entirely), it just segments pixels into classes. Here those classes are the five toggles you get as inputs.

The inputs that matter: images is the only required one. Everything else is a switch. face_mask, background_mask, hair_mask, body_mask, and clothes_mask are all booleans - face_mask defaults to on, the rest default off, so out of the box you get a face mask and nothing else. Flip on whichever combination you need. confidence (default 0.4, range 0.01–1) is the detection threshold: raise it if the model is being too generous and grabbing pixels it shouldn't, lower it if it's missing parts of the person entirely. refine_mask (default true) does something worth knowing about - per the pack's changelog, it crops a bounding box around the detected mask and runs a second segmentation pass on just that crop. That's a real accuracy win on high-res images where the person is small in frame, at the cost of a bit more compute since you're effectively running the model twice.

One detail the README calls out that the node graph won't tell you: when you enable more than one mask type, they come back as a batch in a fixed order - face, then background, then body/clothes, then hair. There's a single masks output (type MASK), so if you're piping this into something downstream that expects one mask, either enable just one toggle or be ready to index into the batch.

Installing it is the standard custom-node routine: search "a-person-mask-generator" in ComfyUI Manager, or cd ComfyUI/custom_nodes && git clone https://github.com/djbielejeski/a-person-mask-generator, then pip install -r requirements.txt from inside the cloned folder, then restart ComfyUI. If you're on the portable Windows build, don't run pip against your system Python - from the ComfyUI_windows_portable folder run python_embeded\python.exe -m pip install -r ComfyUI\custom_nodes\a-person-mask-generator\requirements.txt instead. That's the single most common way people end up with a node that shows up red in the graph: requirements installed to the wrong interpreter, ComfyUI still can't import mediapipe.

Where it actually struggles, and this one's grounded in people hitting it in the wild rather than a hunch: hair segmentation needs actual hair pixels to grab onto. Several people on r/StableDiffusion tried using this to build a bald-to-not-bald workflow - mask the scalp, inpaint hair in - and ran into the same wall: on a bald or close-shaved subject, hair_mask doesn't produce a useful mask, because there's no hair there for the segmenter to detect in the first place. If your use case is "add hair where there currently isn't any," this node's mask output isn't the tool for that step - you'd want to hand-draw or otherwise derive that region.

Once you've got a mask, the obvious next stop is a masked img2img or inpaint pass - feed it into VAE Encode (for Inpainting), or if you're on the newer crop-and-stitch inpainting pattern, straight into Inpaint Crop. Either way, this node's job ends the moment it hands you the mask.

CategoryA Person Mask Generator - David Bielejeski

Inputs (8)

NameTypeDefaultDescription
imagesIMAGE
face_maskoptBOOLEANtrue
background_maskoptBOOLEANfalse
hair_maskoptBOOLEANfalse
body_maskoptBOOLEANfalse
clothes_maskoptBOOLEANfalse
confidenceoptFLOAT0.400.01–1
refine_maskoptBOOLEANtrue

Outputs (1)

NameTypeDescription
masksMASK