Nodes/ComfyUI_Mira/PngRectangles to Masks
ComfyUI Node

PngRectangles to Masks

Every layout rectangle as a mask, at once

By mirabarukaso·Created 2 years ago·Updated 5 days ago· 206
PngRectangles to Masks
  • PngRectangles
  • mask_0
  • mask_1
  • mask_2
  • mask_3
  • mask_4
  • mask_5
  • mask_6
  • mask_7
  • mask_8
  • mask_9
Intenisity1.0
Blur0.0
Start_At_Index0

The fan-out version of PngRectanglesToMask. Feed it the PngRectangles list from a Mira Create PNG Mask node and it renders every box into its own MASK, up to ten of them at once. For a grid or tiling layout where you want a mask per cell, this is the one-node way to get all of them instead of dropping a separate single-mask node for each region.

Quick context if you're new to it: this lives inside regional prompting, the standard fix for attribute bleed - put two characters in one prompt and they'll swap hair colors and outfits, because conditioning is global and applies to the whole canvas. Splitting the canvas into regions and giving each its own prompt fixes it, and each region needs a mask. Rectangles give you those regions by geometry (clean coordinate boxes) rather than by color-matching, which is the tidier route when your layout is a regular tiling.

How it works

The rectangle list is coordinates - one x/y/width/height box per block, plus the whole image's dimensions as the final entry. This node walks the list from your Start_At_Index and paints each box into a grayscale mask at the intensity and blur you set, filling the numbered outputs in order. Only as many sockets as you have rectangles get populated.

Note the one thing it doesn't have: the overlap controls from the single-mask PngRectanglesToMask. This is the straight fan-out; if you need regions to bleed into each other, do them one at a time with the single node instead.

The inputs that matter

  • PngRectangles - the rectangle list from a Mira Create PNG Mask node. The source.
  • Start_At_Index - where to begin, zero-based. Skip leading blocks by raising it.
  • Intenisity - mask strength 0–1; 1.0 is solid. (The misspelling is the real input name.)
  • Blur - edge feather; 0 for a hard edge, higher to soften the seam between regions.

The outputs

Ten MASK sockets, mask_0 through mask_9. Each wires into the region input of a conditioning node. It's exactly the set of masks you'd otherwise assemble by hand, delivered in one node.

Installing it

ComfyUI Manager: Manager -> Custom Nodes Manager, search ComfyUI_Mira, Install, restart. Or clone:

cd ComfyUI/custom_nodes
git clone https://github.com/mirabarukaso/ComfyUI_Mira.git

Restart, and if you hit a load error run pip install -r requirements.txt inside the folder before restarting again. No model downloads.

Common issues

Ten masks is the hard cap, so a layout with more than ten regions won't fully unpack here. In practice that's rarely a real limit - regional prompting gets unwieldy well before ten regions, and most character setups sit at two to five.

Watch the final rectangle: it's the whole image's dimensions, not a region. If you crank Start_At_Index right up to it you'll get a full-canvas mask, which is almost never what you wanted.

Seams between regions looking harsh? Raise Blur. But if the fix you actually need is regions overlapping - bleeding into their neighbors so the joins vanish - this list node can't do it; switch to PngRectanglesToMask per region, which has the Overlap controls. That soft-boundary approach is the standard cure for the collaged, visible-seam look that hard masks produce.

One caveat on support: ComfyUI_Mira is a niche one-person pack (the author is better known for the WAI Character Select app), so there isn't much of a community trail. The README's regional-conditioning example is the reference to follow for wiring it all together.

CategoryMira/Mask

Inputs (4)

NameTypeDefaultDescription
PngRectanglesMIRA_MASKS_LIST
IntenisityFLOAT1.00–1
BlurFLOAT0.0
Start_At_IndexINT0

Outputs (10)

NameTypeDescription
mask_0MASK
mask_1MASK
mask_2MASK
mask_3MASK
mask_4MASK
mask_5MASK
mask_6MASK
mask_7MASK
mask_8MASK
mask_9MASK