Latent to Mask (Bounding Box)
Quick rectangular masks by coordinates
- latent
- MASK
Need a rectangular mask and you know exactly where it goes? This is the fast way. LatentToMaskBB takes a latent and four numbers - x, y, width, height - and hands you a clean box mask, sized to match. No mask editor, no painting, no importing a black-and-white PNG. It's the natural partner to AttentionCouplePPM for regional prompting, but it's useful anywhere a workflow wants a simple area mask.
Why coordinates instead of painting
Painting masks is great for organic shapes and terrible for "the right half of the image." When your regions are rectangles - left character / right character, top / bottom, a corner - typing coordinates is faster, exactly repeatable, and it scales with your resolution automatically. That last part matters: because the values are relative to the latent (0 to 1), the same mask works whether you're at 512 or 1024, and it moves correctly when you change aspect ratio. A painted mask is stuck at the resolution you painted it.
Regional prompting has churned through a dozen tools since 2023, but the core move never changes: split the canvas, give each area its own prompt. This node is the "split the canvas" half, done in the least fussy way possible.
The inputs, and how the coordinates read
Everything's a 0-to-1 fraction of the image, which is the bit to get straight:
- latent (LATENT) - just for sizing; the mask comes out matching its dimensions.
- x (default 0) / y (default 0) - the top-left corner of the box, as fractions.
x=0.5, y=0starts halfway across, at the top. - w (default 1) / h (default 1) - width and height of the box, as fractions.
w=0.5, h=1is half-wide, full-height.
So the README's own example, x=0.5, y=0.0, w=0.5, h=1.0, gives you a mask covering the right half of the image. Left half? x=0, y=0, w=0.5, h=1. Top-third banner? x=0, y=0, w=1, h=0.33. Once it clicks it's genuinely quick.
Two more controls for finer work:
- value (default 1) - the strength inside the box. Turn it down below 1 to make that region's conditioning weaker. This is your per-region strength dial when feeding Attention Couple.
- outer_value (optional, default 0) - the strength outside the box. Usually 0 (fully masked out), but you can lift it if you want the region to bleed into the rest instead of being a hard cutout.
Output is a single MASK you wire into AttentionCouplePPM's mask inputs, or any node that eats a MASK.
Install
No models, no dependencies:
- ComfyUI Manager: search "ComfyUI-ppm", install, restart.
- Manual:
cd ComfyUI/custom_nodes && git clone https://github.com/pamparamm/ComfyUI-ppm, then restart.
Using it well, and the traps
The intended combo is one LatentToMaskBB per region into an AttentionCouplePPM node - box off the left, box off the right, feed each its own prompt, done. There's an attention_couple+negpip template in Browse Templates → Custom Nodes → ComfyUI-ppm showing the full wiring; start there rather than from scratch.
Watch for these. Rectangles are hard-edged - if you want a soft transition between regions, this node won't feather it for you (that's what value/outer_value tuning and stopping the mask early in the sample are for; Attention Couple leaks a little at the bounds regardless). Overlapping boxes are allowed but the overlap zone gets contested conditioning, so decide deliberately whether your regions touch. And feed it the same latent your sampler actually uses - mask a 512-wide latent, sample a 1024-wide one, and your regions land in the wrong place.
Pack-wide note: erroring after an update? Delete the node, re-add it. This one's simple enough that you'll rarely hit trouble.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| latent | LATENT | — | |
| x | FLOAT | 0.000–1 | — |
| y | FLOAT | 0.000–1 | — |
| w | FLOAT | 1.000–1 | — |
| h | FLOAT | 1.000–1 | — |
| value | FLOAT | 1.000–1 | — |
| outer_valueopt | FLOAT | 0.000–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |