Mask Selection Of Masks
Pull One Mask Out of a Stack
- mask
- mask
A lot of ComfyUI mask-producing nodes don't hand you back one mask, they hand you a batch - a stack of them. Any detector that finds multiple objects (multiple faces, multiple people, multiple garments) will happily return "here's every mask I found," and then you're stuck: your next node wants a single mask, not a pile of them. Mask Selection Of Masks is the plain, boring fix - you give it a mask batch and an index, it gives you back the one mask at that position.
The inputs are exactly two, and both are things a beginner will actually touch: mask, the batch you're indexing into, and index, an integer from 0 up to 99 (default 0). Index 0 is the first mask in the stack - if a detector sorts its results by confidence or size, that's usually your "best" or "biggest" match, but that ordering comes from whatever produced the batch, not from this node, so don't assume it without checking. The single output is mask, ready to plug into anything downstream that expects one - a crop node, a composite, a detailer pass.
The obvious pairing inside this same pack is Split Masks, which takes one mask containing multiple disconnected regions (think: a segmentation mask with three separate blobs in it) and splits it into a batch. Split it, then index into the pieces one at a time with this node - that's the two-step "I have one messy mask, give me the individual regions" pattern. It also plays well with anything from a segmentation or detection pipeline that natively returns a mask batch, which in this ecosystem usually means something built around SAM or GroundingDINO-style detectors, the same family this pack's Model Change Device node has plumbing for.
Installing it: comfyui-mask-util is a small utility pack from longgui0318, the same author behind comfyui-magic-clothing (a virtual-try-on node wrapper that had a short burst of attention on Reddit in 2024 and hasn't come up since). This pack looks like the general-purpose glue that got split out of that project - device juggling, dtype juggling, crop math, and mask bookkeeping like this node. Worth setting expectations: there's no meaningful README, just the repo title, so nothing here comes from official docs - it's read straight off the node's own input/output definitions.
Install through ComfyUI Manager (search "comfyui-mask-util") or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/longgui0318/comfyui-mask-util
Restart ComfyUI after either method. No models to fetch, no unusual Python dependencies - indexing into a tensor batch is about as lightweight as custom nodes get.
Where it bites: the most common failure with any "pick by index" node is asking for an index that doesn't exist - request index 3 out of a batch that only has one mask in it, and you'll get an out-of-range error rather than a silent empty mask. If your upstream detector sometimes finds nothing and sometimes finds five things, a fixed index is fragile; you're implicitly assuming the count and ordering stay consistent run to run, which isn't guaranteed unless the detector documents it. And remember the max here is 99 - if you're working with a batch that can legitimately run larger than that (unlikely for face/object detection, more plausible for something like per-connected-component splitting on a busy image), this node's ceiling will clip you before your data does.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| index | INT | 00–99 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |