MaskToBBox(FaceParsing)
Turn a mask into a bounding box
- mask
- BBOX
This is the node that turns "here's a mask" into "here's a rectangle." It takes a MASK and hands back a BBOX - the bounding box that tightly wraps whatever's non-zero in that mask, padded by however many pixels you ask for. Simple job, but it's the hinge between two very different ways of thinking about a region: a mask is a pixel-accurate shape, a bbox is just four numbers. A lot of ComfyUI plumbing - crops, resizes, model providers - only speaks bbox, so this node is how you hand it one.
Why you'd reach for it
The comfyui_face_parsing pack's whole pitch is giving you a proper face-shaped mask instead of a bounding box, using a semantic segmentation model rather than the YOLO-detector-plus-rectangle approach that ADetailer and Impact Pack's FaceDetailer use. That's a real difference - a segmentation mask follows the jawline and hairline instead of drawing a box around the head - and it's specifically valuable when you're blending, not just re-generating: someone recommending exactly this kind of node in the wild put it as "download FaceParser nodes and blend images with mask from FaceParser" when a bbox-based face swap was leaving visible rectangular seams.
But masks and bboxes both have jobs a workflow needs. Once you've got your nicely-shaped parsing mask, you often still need a bbox out of it - to drive a crop node, to feed a detector-style provider that expects box coordinates, or just to know "roughly where is this thing" for downstream logic. MaskToBBox is that conversion step. It pairs naturally with MaskCropWithBBox and MaskInsertWithBBox elsewhere in this pack: parse the face into a mask, convert to a bbox with some padding, crop the image to that box for a focused pass, then use the same box to paste results back where they belong.
Inputs and outputs
Only two inputs, and they're both required:
mask- the MASK you're converting. In this pack's typical flow, that's a face-parsing output (or a composite of several parsed regions via MaskComposite/MaskBatchComposite) rather than something hand-painted, though there's nothing stopping you feeding it any mask.pad- an integer, default 0, minimum 0. Padding added around the tight bounding box before it's returned. This is the one knob you'll actually touch. A tightly-fit box around a parsed face mask can crop right up against the eyebrows or jaw with zero margin, which is a bad idea if anything downstream is going to resize or re-composite that region - you want breathing room. Something in the 10–30px range (scaled to your image resolution) is a reasonable starting point if the crop is feeding a detail pass.
Output is a single BBOX, which wires directly into ImageResizeWithBBox, MaskCropWithBBox, or MaskInsertWithBBox from this same pack.
Installing it
Through ComfyUI Manager: search comfyui_face_parsing, install, restart. By hand:
cd ComfyUI/custom_nodes
git clone https://github.com/Ryuukeisyou/comfyui_face_parsing.git
Restart ComfyUI. This particular node doesn't touch any model weights - it's pure geometry - but the pack as a whole downloads its face-parsing model files to models/face_parsing/ and a YOLOv8 face detector to models/ultralytics/bbox the first time you run a workflow that needs them. If your connection to HuggingFace is flaky, the README has the manual download links (the jonathandinu/face-parsing repo for the segmentation model, Bingsu/adetailer for the YOLO weights).
Where this bites
The one thing to watch: an empty or near-empty mask. If everything upstream failed silently - the parsing model returned nothing for the class you asked for, or a composite operation zeroed the mask out - MaskToBBox has nothing to wrap a box around, and you'll get a degenerate box that breaks whatever crop node consumes it next. If a downstream crop is coming back as a sliver or throwing a size error, don't debug the crop node first - check that the mask feeding this node actually has content, ideally by routing it to a Preview Image node before it hits MaskToBBox. It's a five-second check that saves you chasing the wrong node.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| pad | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| BBOX | BBOX | — |