Select Nth Mask (Inspire)
Pull one mask out of a mask batch by index
- masks
- MASK
Plenty of nodes hand you a batch of masks when you really wanted one of them. A detector finds several regions; Inspire's Color Map To Masks pulls out the top N colors as separate masks; a segmentation step returns a stack. Select Nth Mask is the little scalpel that grabs a single mask out of that batch by its index. Nothing clever - but exactly the node you go hunting for the moment a mask input refuses your batch and you just need mask number two.
How it works
A mask batch in ComfyUI is several masks stacked together. This node takes that stack, an index, and returns the one mask at that position. Zero-based, so index 0 is the first mask, 1 the second, and so on. Whatever produced the batch usually has some order to it - Color Map To Masks, for instance, extracts colors by pixel count, so index 0 tends to be the largest region - and Select Nth Mask lets you reach into that ordering and pick.
From there the single mask goes wherever a MASK input wants it: an inpaint node, a Set Area conditioning, Regional CFG, a detailer. It's the bridge between "a node gave me a batch" and "the next node wants one."
The inputs and outputs
masks(MASK) - the mask batch to index into.idx(INT, default 0) - which one to grab, zero-based.- Output is a single MASK.
That's the whole node. Set the index, get the mask.
How to install it
ComfyUI Manager: Install Custom Nodes → search ComfyUI Inspire Pack → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Inspire-Pack
Then restart. Inspire Pack is Dr.Lt.Data's - the ComfyUI Manager and Impact Pack author - so it's dependable and installs with no model downloads.
Common issues
The one real footgun is the index: it's zero-based, and asking for an index past the end of the batch is an error, not a silent empty mask. So if your batch has three masks, valid indices are 0, 1, 2 - request 3 and it'll complain. When the batch size varies run to run (a detector that finds a different number of regions each time), a hardcoded index can fall off the end; either clamp it or drive it from a counter that respects the batch size. Second, don't assume the ordering is what you'd eyeball - it's whatever the upstream node decided (often by region size or color), so if you're grabbing "the wrong" mask, the fix is understanding that source node's order, not this one.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | — | |
| idx | INT | 00–18446744073709550000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |