Nodes/ComfyUI-Portrait-Maker/ExpandMaskBox PM
ComfyUI Node

ExpandMaskBox PM

Widen a face box before you crop or inpaint — horizontally, anyway

By THtianhao·Created 3 years ago·Updated 2 years ago· 201
ExpandMaskBox PM
  • mask
  • box
  • MASK
  • BOX
expand_width0.1

ExpandMaskBox PM is a small geometry helper that does one thing: take a face box and its mask, widen the box, and hand you back both the wider box and a matching solid mask. It's the kind of node you'd never install on its own but quietly saves your workflow once you've wired it in - because face detectors return tight bounding boxes, and portrait processing rarely wants a tight box.

When you'd reach for it

In the EasyPhoto-style flow this pack ports, RetinaFace finds the face and gives you a box that hugs the features. That's often too cramped for what comes next: cropping with BoxCropImage, running an img2img pass, or replacing a region. You want some breathing room around the face - a bit of hair, jawline, background context - so the downstream step isn't operating on a face that's been shaved to the skin. ExpandMaskBox is the node that adds that room, proportionally to the face's own width.

How it works

Pure math, no model involved. It reads the box, computes the face's width (right edge minus left edge), then pushes both the left and right edges outward by face_width * expand_width, clipped to the image bounds. Then it zeroes a fresh mask and paints it white inside the expanded rectangle. Because the expansion is a fraction of the face's own width, a bigger face gets proportionally more room - you get the same look on a 512px face as on a 2048px one.

Inputs and outputs

  • mask - the current mask (usually the face mask from RetinaFace PM).
  • box - the corresponding box; wire this from RetinaFace PM or any BOX output.
  • expand_width - float, default 0.15, range 0–10. The fraction of face width added on each side.

Outputs are MASK and BOX. The expanded box feeds BoxCropImage or ReplaceBoxImg; the mask feeds merge or masking nodes.

The gotcha nobody mentions

It only expands left and right. The source code never touches the vertical bounds, so a box that's tight on the forehead stays tight on the forehead. If your problem is a crop that clips the top of the head, this node won't help - reach for the pack's MaskDilateErode PM or just build a manual box. The second gotcha: the output mask is a hard white rectangle, not a feathered one. Use it as a region selector, not as a composite mask you expect soft edges from. At the default 0.15 you get a mild frame; at 0.5–1.0 you're pulling in the shoulders. Values past 2 are mostly silly, though the slider does let you go to 10.

Installing it

Via ComfyUI Manager (search "ComfyUI-Portrait-Maker") or:

cd ComfyUI/custom_nodes
git clone https://github.com/THtianhao/ComfyUI-Portrait-Maker.git

Restart ComfyUI after cloning. This node itself downloads nothing, but the pack pulls its full model set on first startup with no hash verification - let it finish, and if it gets interrupted, delete the half-downloaded files and start over. The install brings heavy dependencies with it (modelscope, insightface, tensorflow, onnxruntime, diffusers==0.18.2); on Windows, stick to Python 3.11 because of the bundled insightface wheel.

Categoryprotrait/other

Inputs (3)

NameTypeDefaultDescription
maskMASK
boxBOX
expand_widthFLOAT0.10–10

Outputs (2)

NameTypeDescription
MASKMASK
BOXBOX