Nodes/ComfyUI-Beyond_nodes/MaskBoundingBox-beyond_nodes
ComfyUI Node

MaskBoundingBox-beyond_nodes

Mask bounding box with padding and blur

By beyondprompting·Created 9 months ago·Updated 7 months ago· 0
MaskBoundingBox-beyond_nodes
  • mask
  • image_optional
  • MASK
  • IMAGE
  • x
  • y
  • width
  • height
padding0
blur0

MaskBoundingBox finds the box around your mask's content and crops to it. Feed it a subject mask and it returns the mask cropped tight to the subject, the subject's image cropped the same way, and the bounding box coordinates as plain integers. This is the backbone of every "crop the face, process it big, paste it back" workflow.

The pattern it enables is a classic ComfyUI power move. Inpainting a face at full frame wastes generation budget on 80% empty canvas; instead you crop the face region tight, run your model at high resolution on just that crop, then paste the result back. This node gives you both halves of that: the cropped assets and the coordinates you need to know where they came from.

How it works

The node scans the mask for nonzero pixels, finds the min/max extent, and crops the mask to that bounding box. Two controls shape the result before the crop happens:

  • padding adds pixels around the box on all sides - essential so a face crop doesn't clip the chin.
  • blur applies a gaussian blur to the mask before computing the bounding box. That's the sneaky useful one: blurring first means the box reflects the soft edge of a feathered mask, not just its hard core.

The optional image_optional input is cropped with the same box, so you always get image and mask that line up. If you omit it, the node builds a placeholder from the mask itself. The output also includes x, y, width, height - the box coordinates - which you can wire into anything that needs placement info, or use to restore the crop into the original frame.

The inputs that matter

  • mask (required) - the MASK whose content defines the box.
  • padding (required, default 0) - extra room around the box.
  • blur (required, default 0) - gaussian blur applied before detection.
  • image_optional (optional) - the IMAGE cropped to match.

Outputs: MASK, IMAGE, then x, y, width, height (all INT).

Install

Part of ComfyUI-Beyond_nodes. ComfyUI Manager → search "Beyond_nodes" → install → restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/beyondprompting/ComfyUI-Beyond_nodes

Restart. No extra dependencies.

Common issues

  • The crop is too tight / cuts the subject. Increase padding. This is the most common first-run mistake - tight bounding boxes are rarely what you actually want to feed a model.
  • It crops to a weird empty area. If your mask has stray noise pixels far from the subject, the box covers them. Blur helps; cleaning the mask helps more.
  • The output image doesn't match the mask. Make sure image_optional is the image the mask was made from, and at the same resolution. If they differ, the node resizes the image to the mask before cropping.
  • I don't know where to paste it back. That's what the x/y outputs are for. Composite the crop back at those coordinates (a pack like ComfyUI's Impact or any composite node will take them).

This is one of those nodes you don't appreciate until you've written the "crop–process–paste" workflow by hand once. Then it becomes the thing you reach for every time.

CategoryBeyond nodes/Masking

Inputs (4)

NameTypeDefaultDescription
maskMASK
paddingINT00–4096
blurINT00–256
image_optionaloptIMAGE

Outputs (6)

NameTypeDescription
MASKMASK
IMAGEIMAGE
xINT
yINT
widthINT
heightINT