Extract Mask
Take one layer out of a mask batch, cleanly
- masks
- mask
Masks in ComfyUI are stored as batches - a [count, height, width] tensor where each slice is one mask. That's great when you want them all at once, and quietly annoying when you want one. The pack's compositors and many mask-producing nodes hand you a whole batch ordered by layer, and every downstream node you actually care about wants a single mask. UC_ExtractMask is the two-socket answer: masks in, index in, one mask out.
The input tooltip spells out the ordering assumption: "Mask batch ordered by the producing node, such as compositor layer order." That's the key to using it well. When the pack's UC_StagedIndividualComposites or a layered compositor returns a mask batch, index 0 is the first layer, index 1 the second, and so on. Extract by index and you get exactly the layer you need to inpaint, feather, or composite on its own.
The mechanism is bounds-checking plus a slice: it validates the input is actually a 3-D mask batch ([count, height, width]), confirms your index is in range, and returns masks[index:index + 1] - keeping the batch dimension of 1 so the output is still a proper MASK tensor, not a weird squeezed shape that breaks the next node. The failure messages are the useful part: an out-of-range index tells you how many masks were actually found, and a wrongly-shaped input (say, an RGBA image batch, which is 4-D) raises a clear "requires a [count, height, width] mask batch" instead of silently doing something wrong.
Where this earns its place is any workflow that treats a subject as separate editable regions - the KB's masking-detection-detailing material leans hard on region isolation for inpainting and detail passes, and per-layer extraction is the mechanical step that makes region isolation possible from a batch. Grab the face mask, inpaint it; grab the background mask, upscale it; keep the rest of the batch untouched. It's also the natural partner to the pack's UC_ExtractImage: one takes layer N out of an image list, the other takes layer N out of a mask batch, and both use the same layer ordering, so they stay in sync.
The one thing to keep straight: this indexes a batch of masks, not a mask batch's channels. A single RGBA-like mask with per-channel data is a different shape and this node won't touch it. And remember the ordering is the producer's business - if the producing node reorders layers between runs, your index follows its order, not your memory of it.
Install is pack-standard: Manager search "ComfyUI-UtilsCollection" or cd ComfyUI/custom_nodes && git clone https://github.com/silveroxides/ComfyUI-UtilsCollection then restart. No models, no downloads. Three inputs' worth of plumbing that quietly unblocks every per-layer mask workflow.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | Mask batch ordered by the producing node, such as compositor layer order. | |
| index | INT | 00–9223372036854776000 | Index of the mask to extract. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |