Region Mask
Pull one region's mask out of the builder's batch
- masks
- mask
Region Mask is a tiny utility that exists to solve one specific annoyance: the Regional Prompt Builder hands you a MASK batch with one mask per region, but sometimes you only want to mask a single object. This node picks one region's mask out of the batch by its canvas number and hands you just that one. That's the whole job, and it's genuinely useful because it's the missing connector between "I drew regions on a canvas" and "I want to inpaint exactly one of them."
Why would you want a single mask? The KB's inpainting essay is the background here: instruction editors drift pixels you didn't ask about, so the standing fix for surgical edits is to bolt a mask back on. The builder's canvas gives you regions with segmentation masks; Region Mask lets you isolate one - say, the person in region 2 - and feed that mask to an inpainting pass while the rest of the frame stays untouched. It's the mask-based complement to the builder's whole-frame prompt approach.
The inputs
masks- the mask batch from the Regional Prompt Builder (one mask per region, in region order)region- the canvas region number, 1-based, where 1 is backmost; range 1 to 1024
That's it - no optional inputs, no other widgets. The output is a single mask (MASK), delivered as a single-mask batch so it drops straight into any node that expects a mask batch.
A detail worth knowing from the source: out-of-range numbers don't error, they clamp. Ask for region 7 when only 3 exist and you get region 3's mask. The clamp logic is explicit in the node's implementation (max(0, min(count - 1, region - 1))), so you won't get a crash - just possibly not the mask you thought you were asking for. The region field's tooltip confirms it: "Out-of-range numbers clamp to the batch."
Install
Same pack, same story as everything else in the ERPK Collection:
cd ComfyUI/custom_nodes
git clone https://github.com/eRepublik-Labs/comfyui-nodes-erpk.git erpk
cd erpk && pip install -r requirements.txt
Or "ERPK Custom Nodes" from ComfyUI Manager, restart. It lives under ERPK/utils, right next to the Regional Prompt Builder it's designed to pair with. No API key needed - this node is pure tensor plumbing, fully local.
Where it fits in a workflow
The canonical chain: Regional Prompt Builder → (masks output) → Region Mask (region = 2) → your inpainting setup. The builder's masks come with a known ordering (region order on the canvas, 1 = backmost), so pick the number off the canvas and you're wired. Hand-drawn regions get filled-rectangle masks; scanned regions get their real segmentation. If you're doing anything mask-based - targeted inpaint, a compositing blend, selective upscaling - this is the node that turns the builder's batch into a targeted cut. It's a two-input utility, and it's exactly as useful as the builder you're pairing it with.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | Masks batch from the Regional Prompt Builder (one mask per region, in region order). | |
| region | INT | 11–1024 | Canvas region number (1 = backmost). Out-of-range numbers clamp to the batch. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | The selected region's mask as a single-mask batch. |