Nodes/ComfyUi-MpiNodes/Mpi Box Mask
ComfyUI Node

Mpi Box Mask

Turn a rectangle into a mask without touching a brush

By MadPonyInteractive·Created 11 months ago·Updated 5 days ago· 3
Mpi Box Mask
  • image
  • mpi_box
  • mask
  • mpi_box

If you need a mask that's a rectangle - and for a huge share of automated workflows you do - Mpi Box Mask is the one-line answer. You give it an image and an MPI_BOX, and it hands back a mask the size of the image: pure black, with a solid white rectangle drawn where the box is. Black is "don't touch," white is "this region," which is the convention ComfyUI's inpaint and detail passes expect.

Mechanically it's as direct as it looks. It reads the image's batch, height, and width, clamps the incoming box to the image bounds (same clamping rule as Mpi Box Crop - out-of-bounds is trimmed, not an error), and builds a zero tensor with a 1.0 block over the box region. Two outputs: mask (MASK) and mpi_box - the clamped box actually drawn, so downstream nodes see the region that really got masked, not just the one you asked for.

Inputs: image (IMAGE, used for its dimensions and device) and mpi_box (MPI_BOX, forceInput). No widgets to set, nothing to tune. You build the box with Mpi Box, and - this is the pattern the pack is built around - the same MPI_BOX wire can also feed Mpi Box Crop, so the region you mask is exactly the region you crop. One rectangle, consistently understood across both operations, no loose wires to drift out of sync.

Where this shows up for real is the automation loop the KB's masking doc calls the "detect-mask-inpaint-composite" pattern. A detector gives you a bounding box around a face or object; you want to inpaint or re-render just that region. Feed the detector's box into Mpi Box, then into Mpi Box Mask, and the resulting mask drives an inpaint sampler - or a detail pass - while everything outside stays untouched. It's the programmatic answer to hand-painting a mask: you didn't brush anything, the box did the work.

The honest caveat is the shape itself: a box mask is a rectangle, and rectangle masks have rectangular seams. The KB's detailing doc flags this directly - a bbox-detector mask shows its edges against the surrounding pixels, whereas a polygon or blurred mask hugs the subject. So use this when the region genuinely is a rectangle (a crop target, a tiled region, a reference area), and reach for something smoother when the region is an organic shape. You can also post-process: feed the mask through a blur or dilation node to soften the hard edge if the rectangle is just a starting point.

Also worth knowing: the mpi_box output being the clamped version means you can chain it forward - pass the clamped box to Mpi Box Crop and crop exactly the region the mask covers, no guessing. That pairing is where this node earns its keep in a workflow.

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.

CategoryMpiNodes/ImgOps

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
mpi_boxMPI_BOX

Outputs (2)

NameTypeDescription
maskMASK
mpi_boxMPI_BOX