ComfyUI Node

Mask From List

Grab items 3 through 5 out of a mask list

By tom-m-2020·Created about a month ago·Updated 7 days ago· 1
Mask From List
  • masks
  • MASK
◄start0►
◄length1►

Mask From List is a small, unglamorous node that does one job: it takes a genuine Comfy list of masks and returns a contiguous slice of it. Mask number two through mask number five, say, because you're fixing faces in an order and only the middle ones need work.

The reason a node like this needs to exist at all is the list-versus-batch confusion, which is the single most common source of "why is my node returning one thing" in ComfyUI. A MASK that carries four masks as a tensor batch is one value with an inner dimension; a list of four masks is four separate values travelling down one wire. They look similar in the graph and behave nothing alike. masking-detection-detailing.md calls this out for SEGS, and the same split applies here: batches are for things that run together, lists are for things that run one at a time. This node only speaks list.

Inputs and output

  • masks - the MASK list. Note that the node is declared as a list-input node, so ComfyUI delivers the whole incoming list to the function in one go. If the upstream output is a plain tensor batch rather than a list, this is the wrong node - split it first with something like the pack's Image Batch To Image List, or check what you've got with List / Batch Inspector.
  • start - zero-based index, default 0, no upper bound.
  • length - how many items to take, default 1, minimum 1.

The output is a single MASK-typed socket marked as a list, named MASK. That's what you wire into a per-item consumer.

The clamping behaviour, which is the whole personality of this node

There is no error path. It clamps instead, in this order: length is capped at the list size, start is capped at the last index, then length is capped again so the range can't run past the end. So a start of 40 on a 3-item list gives you item 2, silently. A length of 100 gives you everything from start onwards. An empty list gives you an empty list.

Clamping is friendlier than throwing, and it's also a trap: a mistyped start doesn't fail, it just quietly hands you the last mask, and if that mask happens to be a plausible-looking thing you may not notice for a while. Check the output count when you're setting this up for the first time.

Where it fits

The natural pairing is a list of masks coming off a batch - one mask per frame of a video, one per detected region, one per subject in a group shot - feeding a loop or an ordered chain of inpaints where you want a specific run of them. In the detection/detailing world this is the "keep only these regions" step: the detection layer emits a set, filters and ordering nodes reorder it, and this picks the range you actually want to spend render time on.

One output ordering note: reordering a list happens upstream, not here. If your masks aren't in the order you expected, that's the detector or a sorter's doing; this node just counts.

Install

Manager: search ComfyUI Utility Suite (publisher tom-m), install, restart. Manual, the usual:

cd ComfyUI/custom_nodes
git clone https://github.com/tom-m-2020/ComfyUI-Utility-Suite

No model files, nothing to download. The pack's one dependency is opencv-python-headless, and this node doesn't touch it - pure Python. Do note the pack targets ComfyUI's newer V3 node API, so an outdated ComfyUI will import the folder and register zero nodes; update first if you can't find it in the menu.

Troubleshooting

Type mismatch on connect. You're feeding a tensor batch to a list input. Batch and list are different types here; split the batch first.

It returns one mask when you expected four. length defaults to 1. Set it.

It returns a truncated range. Either start plus length runs past the end of the list, or the upstream list is shorter than you think. Clamping, again - no warning, no error.

CategoryUtility Suite/Mask

Inputs (3)

NameTypeDefaultDescription
masksMASK—
startINT0—
lengthINT1—

Outputs (1)

NameTypeDescription
MASKMASK—