Nodes/BrainDead Nodes/BD Mask Batch Index
ComfyUI Node

BD Mask Batch Index

Pull one mask out of a batch — the two-minute bridge for SAM3 outputs

By BizaNator·Created 8 months ago·Updated 3 days ago· 15
BD Mask Batch Index
  • masks
  • mask
  • info
index0
invertfalse

BD Mask Batch Index does one thing: it takes a batch of masks (N, H, W) and pulls out the one at the index you pick. That's the whole node, and it exists because segmentation models in ComfyUI return batches while half the downstream nodes want a single mask.

The concrete case that this node was built for is BD SAM3 Multi Prompt. That node (and the SAM3 Segment chain generally) outputs per_prompt_masks - one mask per prompt, all stacked in a single batch. Meanwhile BD Pack Channels, BD Remove Background, BD Mask Color Fill, and a bunch of others accept one MASK at a time. Without a selector, you'd be doing gymnastics to feed "just the eyes" or "just the shirt" into those single-mask inputs. This node is that selector, in about ten seconds.

How it works

Everything hangs off two inputs:

  • masks - the batch. Feed it per_prompt_masks from SAM3, or any (N, H, W) mask batch.
  • index - 0-based position to extract. Here's the part people like: negative indices count from the end, so -1 grabs the last mask without you knowing how many there are. Out-of-range values are clamped to [0, N-1] rather than erroring, which is friendlier than you'd expect from a utility node.

There's one optional: invert, which flips the selected mask before output. Handy when a downstream node expects "keep" as white but your mask is "remove" as white - you can flip it inline instead of bolting on a separate Invert Mask node.

The second output, info, is a small kindness: it's a "index/total" string like "2/5", so when you're wiring a chain and something's off, you can glance at the value (or wire it to a text preview) and confirm you selected mask 3 of 5 and not mask 2 of 4. That "which mask am I even looking at" confusion is the real time-sink with batched outputs, and this output exists specifically to kill it.

The one thing to watch

Ordering. per_prompt_masks come back in the order you listed your prompts, so index 0 is prompt 0 - but that's only true if you keep prompt order stable. If you reorder prompts in BD SAM3 Multi Prompt, your indexes silently mean different things, and the info output (which tells you the count, not the label) won't catch it. Label your prompts, keep the order in one place, and treat the index as "position in that exact list."

Installing

Standard for this pack:

cd ComfyUI/custom_nodes
git clone https://github.com/BizaNator/ComfyUI-BrainDead
cd ComfyUI-BrainDead
pip install -r requirements.txt

Restart, and it's under 🧠BrainDead/Segmentation. Or ComfyUI Manager → search "BrainDead" → install. Keep ComfyUI current since these are all V3 API nodes.

That's the whole review: it's a 30-second node that unblocks a workflow pattern (SAM3 batch → single-mask consumers) that otherwise costs you three or four custom nodes or a chunk of patience. Index it, wire it, forget it.

Category🧠BrainDead/Segmentation

Inputs (3)

NameTypeDefaultDescription
masksMASKMask batch (N,H,W) — e.g. per_prompt_masks from BD_SAM3MultiPrompt.
indexINT0-64–640-based index of the mask to extract. Negative counts from end. Clamped to [0, N-1] if out of range.
invertoptBOOLEANfalseInvert the selected mask before output.

Outputs (2)

NameTypeDescription
maskMASKSingle (1,H,W) mask at the selected index.
infoSTRING'index/total' — e.g. '2/5' confirms which mask was selected.