Mask Pick By Index
Grab mask number N — or the last one, which is the actual move
- masks
- mask
Mask Pick By Index is the tiny node you'll use more than you expect. Give it a list of masks and an integer, and it hands back one mask. The name understates the one feature that makes it worth having: negative indexing. -1 is the last mask, exactly like Python. That sounds trivial until you realize it lets you say "the rightmost subject" without knowing how many subjects there are.
The workflow it unlocks
Pair it with Mask Sort By Position and the pair becomes the reliable way to address subjects by their position in the frame:
- Sort your mask list left-to-right with Mask Sort By Position.
- Feed the sorted list into this node.
- Set
indexto0for the leftmost subject, or-1for the rightmost - no matter how many masks your segmenter detected.
Try doing that with plain indexing. Your segmenter found five people this run and four the next, and a hardcoded 4 breaks on the second image. -1 never does. The same trick works for top/bottom once you sort vertically.
Inputs and outputs
masks- a list of masks to pick from (needs to be a list, not a batch - run Mask Batch To List first if your segmenter gave you one).index- which mask to return.0= first,1= second, negative counts from the end. Out-of-range values clamp to the nearest end instead of erroring, so999on a three-mask list quietly gives you the third. That clamping is deliberate and handy for automation - driveindexwith a seed or random int and you can cycle subjects without ever hitting a crash.mask(output) - a single mask, ready to feed MaskToImage, an inpaint node, or whatever you're targeting.
Installation
Standard for this pack - clone, restart, no dependencies:
cd ComfyUI/custom_nodes
git clone https://github.com/INuBq8/ComfyUI-MultiMaskOps
All nodes appear under MultiMaskOps. The requirements.txt is empty; torch/scipy/torchvision come with ComfyUI. Manager search "MultiMaskOps" should work too, though the README marks the listing "(soon)" so the clone is the reliable route.
Troubleshooting
- Empty list - this node raises if you hand it zero masks. Make sure your segmenter found something before you pick.
- "It picked the wrong subject" - the list is only as ordered as what you feed it. If you haven't sorted, "index 0" is whatever the segmenter happened to emit first. Sort first, then pick; that's the intended flow.
One honest caveat: with so few impressions on this node and a pack that's effectively brand new (one commit as of mid-2026), there's no battle history to cite - but the code is short enough to read in a minute, and it does exactly what the tooltip says.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | A list of masks to pick from. | |
| index | INT | 0-10000–10000 | Which mask to return. 0 = first, 1 = second, ... Negative counts from the end (-1 = last). Out-of-range values clamp to the nearest end. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |