Nodes/ComfyUI-BrainDead/BD MP SAM3 Face Segment
ComfyUI Node

BD MP SAM3 Face Segment

MediaPipe-guided SAM3 face segmentation: localizes each feature with MediaPipe, then prompts SAM3 per feature (box + positive landmark points + sibling negatives) for pixel-accurate masks. Solves the stylized-brow offset that landmark-only bands can't. Outputs RGBA zone map + individual masks. Wire a comfy-core SAM3 MODEL (same as SAM3 Detect).

By BizaNator·Created 7 months ago·Updated 16 days ago· 14
BD MP SAM3 Face Segment
  • image
  • model
  • silhouette_mask
  • head_mask
  • rgba
  • face_oval
  • skin
  • left_eye
  • right_eye
  • eyes
  • left_brow
  • right_brow
  • brows
  • left_iris
  • right_iris
  • irises
  • lips
  • nose
  • left_ear
  • right_ear
  • ears
  • forehead
  • hair
  • head_mask
  • masked_skin
  • silhouette
  • debug_overlay
  • status
  • head_cutout
  • head_cutout_clean
anglefront
do_browstrue
do_eyestrue
do_lipstrue
do_nosetrue
do_earsfalse
detection_confidence0.30
min_face_span0.35
mask_threshold0.50
refine_iterations1
bleed_guard48
brow_bleed_guard44
lips_bleed_guard12
eye_bleed_guard10
cleanuptrue
fill_holestrue
lips_modemouth
edge_smooth3
edge_refineoff
refine_radius8
refine_eps0.0001
refine_threshold0.50
vitmatte_modelsmall
remove_backgroundfalse
head_promptshead face hair ear
exclude_promptsneck shirt clothing shoulder
neck_cuttrue
cutout_bgtransparent
drop_eyestrue
drop_browstrue
drop_lipstrue
drop_nosefalse
skin_color_filteroff
skin_color_threshold0.30
drop_facial_hairfalse
Category🧠BrainDead/Segmentation

Inputs (39)

NameTypeDefaultDescription
imageIMAGEFull-color full-resolution face image. Only image[0] is used.
modeloptMODELComfy-core SAM3 model (override). Leave UNWIRED to auto-load + auto-download the official SAM3 checkpoint in-house (bd_sam3) — no setup.
angleoptCOMBOfrontStored for downstream/context use only.
do_browsoptBOOLEANtrueSegment eyebrows with SAM3 (recommended — fixes the offset).
do_eyesoptBOOLEANtrueSegment eyes with SAM3.
do_lipsoptBOOLEANtrueSegment lips with SAM3.
do_noseoptBOOLEANtrueSegment nose with SAM3.
do_earsoptBOOLEANfalseSegment ears with TEXT-grounded SAM3 ('ear', split L/R at the face centre) instead of the weak MediaPipe approximation (the face mesh has no outer-ear points). Off = MediaPipe ears. Loads the SAM3 text encoder in-house.
detection_confidenceoptFLOAT0.300.1–1MediaPipe face detection confidence. 0.3 works for stylized renders.
min_face_spanoptFLOAT0.350–1Tiny-detection guard (see BD MP Face Export). 0 disables.
mask_thresholdoptFLOAT0.500.05–0.95SAM3 mask probability cutoff.
refine_iterationsoptINT10–5SAM decoder refinement passes. NOTE: extra passes tend to SHRINK masks on stylized/non-photo renders — 1 (no mask-refine) gives the fullest feature; raise only if SAM3 over-segments.
bleed_guardoptINT480–200GENERAL bleed-guard: dilate the MediaPipe feature zone by this many px (at native res), then clip SAM3's mask to it. Used for NOSE + as the fallback. Brows/eyes/lips have their own (brow_/eye_/lips_bleed_guard). 0 = clip exactly to MediaPipe.
brow_bleed_guardoptINT440–200Bleed-guard for BROWS only. Brows need a LARGE guard (~40-45): their MediaPipe landmarks sit inside/below the painted brow, so SAM3 must grow out to fill it. Raise if brows read thin; this won't loosen eyes/lips (they're separate).
lips_bleed_guardoptINT120–200Bleed-guard for LIPS only — kept separate because brows need a LARGE guard (40-45) to fill while lips need a SMALL one or they overflow onto the face. Lower = tighter lips (12 hugs the lip contour; 0 = clip exactly to MediaPipe).
eye_bleed_guardoptINT100–200Bleed-guard for EYES only. SAM3 grows to the whole eye (lid/lashes/sclera); a small guard clips it back toward the eyelid aperture so the mask hugs the eyeball — like BD Face Infill's eroded eyelid hull. Lower = tighter (0 = clip exactly to the MediaPipe eye contour).
cleanupoptBOOLEANtrueClean SAM3 noise: keep only the connected component(s) the positive landmark seeds land in (drops stray chunks around eyes/lips).
fill_holesoptBOOLEANtrueFill interior holes on NON-lip features (eyes/nose/etc.) so each is solid. Lips are controlled separately by lips_mode.
lips_modeoptCOMBOmouthLips-specific: mouth — fill the whole mouth area (lips + teeth + tongue) into the lips mask (default; what the pipeline wants). lips_only — lip flesh only; color-aware edge_refine excludes teeth/tongue. Overrides fill_holes for the lips feature.
edge_smoothoptINT30–15Morphological close+open radius (px @native) to smooth jagged SAM3 edges during cleanup. 0 = no smoothing.
edge_refineoptCOMBOoffSnap the mask edge to image color/edges after cleanup. off — no refinement guided — guided filter (fast, edge-aware; good general snap) matting — PyMatting closed-form alpha matting (CPU, no model) vitmatte — VitMatte deep matting model (best on soft/hair edges; GPU; loads hustvl vitmatte-small). All run on the feature ROI crop.
refine_radiusoptINT81–40Guided-filter radius / matting trimap band width (px @native). Larger = looks further for an edge / wider uncertain band.
refine_epsoptFLOAT0.00010.000001–0.1Guided-filter edge sensitivity (smaller = sharper, hugs edges harder). Ignored by matting.
refine_thresholdoptFLOAT0.500.05–0.95Binarize the refined alpha at this level.
vitmatte_modeloptCOMBOsmallVitMatte variant for edge_refine='vitmatte'. Auto-downloaded from the HF hub (hustvl/vitmatte-{small,base}-composition-1k) on first use — standalone, no other node pack required. base = higher quality, larger.
silhouette_maskoptMASKOptional head silhouette (white=head). When wired, ALL outputs are clipped to it and it becomes head_mask; masked_skin = skin within it. Overrides remove_background. (Or let remove_background compute it in-house.)
head_maskoptMASKOptional inner head/face-plate mask used as the skin base (skin = head_mask − eyes − brows − lips). Falls back to face_oval. Echoed to the head_mask output.
remove_backgroundoptBOOLEANfalseCompute a clean HEAD silhouette IN-HOUSE (text-grounded SAM3, no extra nodes): segment head_prompts as positive, exclude_prompts (neck/shirt/etc.) as negative → head minus neck/clothing/background. Clips every output to it, becomes head_mask, and is emitted as the `silhouette` output. Skipped if silhouette_mask is wired. Auto-downloads the SAM3 checkpoint if needed.
head_promptsoptSTRINGhead face hair earremove_background positives — one per line. Union = the head.
exclude_promptsoptSTRINGneck shirt clothing shoulderremove_background negatives — one per line. Their union is SUBTRACTED from the head (peels off neck / clothing / body).
neck_cutoptBOOLEANtrueWith remove_background: remove the neck. PRIMARY = in-house SegFormer face parser (1038lab/segformer_face, auto-downloaded) — subtracts its real Neck/Clothing/Necklace classes (per-pixel, reliable). FALLBACK if it can't load = cut below the MediaPipe jawline contour. Off = keep the neck.
cutout_bgoptCOMBOtransparentBackground for the head_cutout / head_cutout_clean image outputs: transparent (RGBA alpha), or composited on black / white.
drop_eyesoptBOOLEANtruehead_cutout_clean: remove the eyes (punch-out — fill is left to BD MP Face Infill).
drop_browsoptBOOLEANtruehead_cutout_clean: remove the brows.
drop_lipsoptBOOLEANtruehead_cutout_clean: remove the lips/mouth.
drop_noseoptBOOLEANfalsehead_cutout_clean: remove the nose (off by default — nose is usually kept skin).
skin_color_filteroptCOMBOoffRefine the `skin`/`masked_skin` outputs by COLOUR (same engine as BD SAM3 Multi-Prompt / BD Mask Resolver): adaptive_lab samples the skin tone from the current skin region and keeps pixels within ΔE tolerance (works for any tone); fixed_hsv uses HSV skin ranges; both = stricter. Drops non-skin pixels (e.g. a dark mustache) from skin. Off = skin is purely geometric (head − features).
skin_color_thresholdoptFLOAT0.300–1skin_color_filter cutoff: keep pixels with skin-likelihood ≥ this. Lower for stylized art (more permissive).
drop_facial_hairoptBOOLEANfalsehead_cutout_clean: also punch out non-skin-coloured facial hair (mustache/beard) in the lower face, found via the skin colour filter (SAM3 text + face-parse can't segment facial hair on stylized art). Best-effort; uses skin_color_threshold. Wire the result to BD MP Face Infill to repaint it.

Outputs (26)

NameTypeDescription
rgbaIMAGERGBA zone map: R=lips, G=brows, B=eyes, A=face_oval.
face_ovalMASK
skinMASK
left_eyeMASK
right_eyeMASK
eyesMASK
left_browMASK
right_browMASK
browsMASK
left_irisMASK
right_irisMASK
irisesMASK
lipsMASK
noseMASK
left_earMASK
right_earMASK
earsMASK
foreheadMASK
hairMASK
head_maskMASK
masked_skinMASK
silhouetteMASKThe head silhouette used for clipping (head − neck/clothing/bg). When remove_background is on it's the in-house text-SAM3 head cutout; else the wired silhouette_mask, else face_oval. Wire this anywhere you need 'head but not neck' — replaces a separate background-removal + silhouette chain.
debug_overlayIMAGERender with feature masks tinted (lips=R, brows=G, eyes=B, nose=Y).
statusSTRING
head_cutoutIMAGEThe input image with the head silhouette applied, on cutout_bg (transparent RGBA / black / white) — head only, background+neck removed.
head_cutout_cleanIMAGESame as head_cutout but with the drop_* features (eyes/brows/lips/nose) punched out (holes empty / bg-filled). Wire into BD MP Face Infill to fill them, or use as the skin plate.