Mpi Bbox To Mask
Detector boxes to usable masks, in either format you were handed
- images
- bbox
- masks
Every detector in existence hands you bounding boxes, and half the time they don't even agree on what the four numbers mean. Mpi Bbox To Mask is the bridge between "I have boxes from a detector" and "I need a mask for an inpaint or a detail pass." You feed it the images and a BBOX, pick which coordinate convention the boxes use, and it produces a MASK - white where the box is, black everywhere else, one per image in the batch.
The single most useful thing this node does is eat the format confusion for you. Detectors speak two dialects: xyxy (x_min, y_min, x_max, y_max - two corners) and xywh (x_min, y_min, width, height). Pick the matching bbox_format in the dropdown and the node converts correctly; pick wrong and your mask comes out shifted or stretched, which is the classic "why is the mask in the wrong place" bug. The conversion is done per-image through the pack's create_mask_from_bbox helper, which also handles the normalized-vs-pixel question internally.
Inputs: images (IMAGE), bbox (BBOX), and the bbox_format enum (xyxy / xywh). Output: masks (MASK).
The one hard requirement to know up front: the number of boxes must match the batch size. The source raises ValueError: Expected {B} bboxes, got {len(bbox)} if they don't line up. That's a strict, deliberate check - a detector that found two faces in a single image can't produce two masks from one image unless the image is batched to match, so expect to pair one box per frame or get the error and fix your batching. It's a loud failure, which is the good kind: it tells you exactly what's wrong instead of silently producing a garbage mask.
Where this lives in a workflow is the automation loop the KB's masking doc spells out: detect → mask → re-render. A bbox detector (YOLO, GroundingDINO, any of the Ultralytics family) returns boxes; this turns them into masks; the masks feed an inpaint sampler or a detail pass so only the detected region is regenerated. It's the rectangular start of the pipeline that ends with a re-rendered face or object. For automated batches - a hundred images, each with one detected subject - the strict one-box-per-image contract actually helps, because it keeps the loop honest.
The honest caveat is inherited from rectangles: a box mask has hard edges, and the KB's detailing doc is blunt that bbox-derived masks show seams against surrounding pixels, where a polygon (segmentation) mask hugs the subject and hides them. If your box is just a coarse region, run the mask through a blur or dilation afterward to soften the edge. If your detector already offers segments instead of boxes, use those and skip the rectangle entirely.
Install is pack-standard: ComfyUI Manager → search ComfyUi-MpiNodes → install, or clone it:
cd ComfyUI/custom_nodes
git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes
Restart, and it's under MpiNodes/ImgOps. No requirements file, no model downloads - pure Python on top of ComfyUI, the same pack behind the Cubric Vision app.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | — | |
| bbox | BBOX | — | |
| bbox_format | COMBO | 2 options: xyxy, xywh |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| masks | MASK | — |