Nodes/ComfyUI-StableLayers/Merge Layer Range
ComfyUI Node

Merge Layer Range

Merge Layer Range — when the model hands you a figure in three pieces

By tggo·Created about a month ago·Updated about a month ago· 3
Merge Layer Range
  • layers
  • merged
  • layers_with_merge
start1
end64

The Stable-Layers adapter is a splitter with opinions. Run it at its shipped strength and it doesn't just pull a person off a background - it can hand you that person as torso, legs, and arms in separate layers. Sometimes that's exactly the depth you want, each limb getting its own parallax factor in a 2.5D animation. Other times it's just noise, and you wanted one clean cutout. Merge Layer Range is the "put it back together" node, and it lives entirely in the Stable-Layers pack so you don't have to build the composite math yourself.

What it does

You feed it the layer stack straight out of Split Layer Stack's layers output, plus a start and end index. It composites every layer in that range - inclusive, back-to-front - into a single RGBA image, and leaves everything outside the range untouched. The z-order stays intact: layers below the range, then your merged result, then the layers above it. So merging torso+legs+arms into "person" doesn't scramble the stack order relative to the sofa behind and the table in front.

The math is a plain straight-alpha composite (top over bottom, unpremultiplied) done in torch, with a fallback that treats any layer lacking an alpha channel as fully opaque. Nothing clever, which is the right call - the node is a utility, not a feature.

The inputs that matter

Only three, and only two you'll touch:

  • layers - the IMAGE stack from Split Layer Stack. That's the whole point of the node.
  • start / end - the range to merge. Defaults are 1 and 64, i.e. "merge nearly everything" unless you narrow it. Remember the stack is back-to-front, so index 0 is the background plate; keep start at 0 if you want the merge to include it, or bump it past 0 to leave the background separate.

The two outputs are merged (just the composited range, as a single image) and layers_with_merge (the full stack with the range collapsed to one layer, ready to feed downstream compositing or Save Layers RGBA).

Why you'd reach for it

Two real scenarios. First, cleanup: you wanted one subject, the adapter gave you three layers, so merge them. Second, the parallax trick done backwards - if you do want per-part depth but only for one region, merge everything except the range you're animating. The other way to avoid the fragmentation entirely is dropping the LoRA strength to 0.75 in StableLayersLoraLoader, which keeps a single subject whole at generation time. Merge Layer Range is the after-the-fact version of that knob, and it's the one that works on already-rendered stacks.

Installing the pack

This is part of ComfyUI-StableLayers, so install the pack once:

cd ComfyUI/custom_nodes
git clone https://github.com/tggo/ComfyUI-StableLayers

or grab it from ComfyUI Manager by searching for ComfyUI-StableLayers, then restart ComfyUI. No extra Python deps for this node - huggingface_hub is only needed by the auto-download LoRA loader.

Gotchas

Merge Layer Range composites what the model actually emitted - it does not magically fill in what's missing. If a limb came back 40–60% transparent, the merged result stays translucent, so chain it into SolidifyAlpha if you want a solid silhouette. And don't expect the merged region to match the background plate seamlessly; the model paints occluded content back in at layer 0, and merging over that is a composite, not a reconstruction.

CategoryStable Layers

Inputs (3)

NameTypeDefaultDescription
layersIMAGE
startINT10–64
endINT640–64

Outputs (2)

NameTypeDescription
mergedIMAGE
layers_with_mergeIMAGE