Nodes/ComfyUI Impact Pack/Decompose (SEGS list)
ComfyUI Node Runs on cloud

Decompose (SEGS list)

Taking a List of SEGS Apart, Element by Element

By ltdrdata·Created 4 years ago·Updated about 15 hours ago· 3,396
Decompose (SEGS list)
  • segs
  • SEGS_HEADER
  • SEG_ELT

SEGS is the container Impact Pack passes detections around in, and it's deliberately opaque: one header holding the image dimensions, and a list of segments inside. Usually that's the right level of abstraction - detectors make SEGS, detailers consume SEGS, nobody opens the box. Eventually you want to touch the individual segments, and Decompose (SEGS list) is the experimental-ish node that lets you - for a list of SEGS, which is a different problem from a single SEGS.

What SEGS actually is

Worth thirty seconds of theory, because these nodes are incomprehensible otherwise. A SEGS is a two-tuple: (width, height), and a list of SEGs. Each SEG carries a crop region, a bbox, a confidence, a label, a cropped mask and sometimes a cropped image. The tuple shape is the SEGS_HEADER; the individual entries are SEG_ELTs.

Two nodes handle the single-SEGS case - DecomposeSEGS and AssembleSEGS - and they're what you want for one SEGS at a time. Decompose (SEGS list) handles the case where several SEGS are travelling as a list, which happens when ComfyUI runs a node once per batch item and hands you the results as a list, or when a node's output is explicitly list-typed. Its job: flatten that whole list into one stream of headers and one stream of elements, while recording which SEGS each piece came from so the round trip can be undone.

That provenance is the whole trick. The node stamps each header and element with its origin - the node's unique id plus the index in the list - not an object reference, but a position. The source has a comment explaining why, and it's a legitimate reason: ComfyUI's cache can re-run a node while elements from the previous run are still being handed downstream, so identity has to be a place rather than a pointer.

Inputs and outputs

  • segs - SEGS, taken as a list (INPUT_IS_LIST is on, so this node is built to receive the whole list in one call).
  • Output SEGS_HEADER - a list, one header per SEGS in the input.
  • Output SEG_ELT - a list, every element from every SEGS, flattened into one stream.

Both outputs are list outputs, which in ComfyUI means downstream nodes execute once per item. That's the point: you can now run an element-level node - Edit SEG_ELT, From SEG_ELT, From SEG_ELT bbox, Dilate Mask (SEG_ELT), whatever - across every element of every SEGS in one go, then put it all back with Assemble (SEGS list).

What you'd use it for

Honestly? Most people never will, and that's fine - this is instrumentation, not a daily driver. The workflows it exists for are the fiddly ones: you've got a list of SEGS (one per frame of a video, one per image in a batch), you want to modify a property across all of them uniformly, and the alternative is a subgraph per SEGS. Or you want to sort, re-label, or reorder elements across SEGS boundaries and then hand the results back in the original grouping. The pack describes this family (SEGS_ELT Manipulation) as experimental, and it earns that label: the nodes work, but the type plumbing is less forgiving than the rest of the pack.

The one thing to internalise: elements keep their origin through the element-level nodes. The decompose marker travels with them by design, so a _replace-style edit or a per-element dilate doesn't lose the thread. But if you rebuild an element from scratch somewhere else, or feed in elements from the plain DecomposeSEGS, you've got elements with no origin and assembly will bail.

Install

Part of Impact Pack - category ImpactPack/Util, no extra dependencies.

cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack
cd ComfyUI-Impact-Pack
pip install -r requirements.txt

Windows portable: ..\..\..\python_embeded\python.exe -m pip install -r requirements.txt, then restart ComfyUI. Manager users: search ComfyUI Impact Pack. First launch writes impact-pack.ini and pulls a default SAM checkpoint into models/sams - put an empty file named skip_download_model in custom_nodes beforehand if you'd rather it didn't.

If it looks wrong

The failure you'll actually hit is pairing: this node's outputs belong with Assemble (SEGS list) and nothing else. Mix them into a plain AssembleSEGS and it has no idea what to do with the extra provenance. Keep the pairs together and the whole thing is boring, which for plumbing is the highest compliment available.

CategoryImpactPack/Util

Inputs (1)

NameTypeDefaultDescription
segsSEGS—

Outputs (2)

NameTypeDescription
SEGS_HEADERSEGS_HEADER—
SEG_ELTSEG_ELT—