Nodes/ComfyUI/Layers From Bounding Boxes
ComfyUI Node Runs on cloud

Layers From Bounding Boxes

When your layers arrive as a batch

By Comfy-Org·Created 4 years ago·Updated about 5 hours ago· 128,055
Layers From Bounding Boxes
  • image
  • bboxes
  • mask
  • layers
  • LAYERS
crop_to_contenttrue
canvas_width0
canvas_height0

Layers From Bounding Boxes is the compositor's import path. It takes an image batch plus a matching set of bounding boxes and turns them into a real layer stack - one layer per frame, each placed by its own box. The official description says it best: use it when a node emits layers as a batch, because a batch carries a single placement for every frame and the individual positions would otherwise be lost.

When would that happen? Real-world example: the Seedream Layer Separation partner node returns a subject cut out against the background as a batch of frames with per-region boxes. Feed that into this node and instead of one flattened result you get separate editable layers sitting where the model detected them. Core object detectors work too - Create Bounding Boxes, RT-DETR, or SAM3 all emit the BOUNDING_BOX type this node eats. It's the bridge between "the model found the objects" and "I can reposition them by hand."

How it works. The mapping is index-aligned: the nth box places the nth frame. Each box's width and height scale the layer to fit it, and frames without a matching box land at the origin. Boxes can arrive as proper BOUNDING_BOX objects, an ARRAY, or a JSON string - the node accepts all three. Two details matter if you're feeding it detector output: normalized elements (a dict with a bbox key in 0–1 coordinates) need canvas_width/canvas_height to resolve to pixels, and if those are 0 the node throws instead of guessing. And when a box carries metadata - name (or desc) becomes the layer name, z_index sets stacking, content_rect defines the real content within a padded frame - the node honors it.

The inputs that matter.

  • image and bboxes are both required and must line up index-for-index.
  • mask - per-frame transparency, 1 = transparent (the LoadImage convention).
  • layers - append onto an existing stack instead of starting fresh.
  • crop_to_content - on by default. When a frame has a content_rect, it crops to that rect and places the content at the box position plus the rect offset, so padded frames land at their true spot.
  • canvas_width / canvas_height - explicit document size; 0 derives it from the placed layers.

Output. A single LAYERS output, ready for Create Layered Image. From there you can hand-adjust each layer in the editor, exactly as if you'd built the stack with AddLayer.

Getting it. It ships with ComfyUI core - nothing to install, it updates with ComfyUI itself. Like the rest of the compositor, it's experimental and new (landed around August 2026), so treat its behavior as a moving target.

Where people get burned. Index alignment is the whole game: if your boxes and frames fall out of sync, layers land at wrong positions and nothing tells you why. Normalized boxes silently error out if canvas dims aren't set, so when a detector gives you 0–1 coordinates, set canvas_width/canvas_height explicitly rather than leaving them at 0. And remember crop_to_content shifts where content lands - for frames that are already tight, you may want it off to avoid surprise cropping.

Categoryimage

Inputs (7)

NameTypeDefaultDescription
imageIMAGEImage batch; each frame becomes one layer.
bboxesBOUNDING_BOX,ARRAY,STRINGPlacement boxes, index-aligned with the image batch. Accepts bounding boxes (x, y, width, height), normalized elements (with a 'bbox' - these need canvas_width/canvas_height to resolve to pixels), or a JSON string of either. Frames without a matching box are placed at the origin. A box's width/height scales the layer to fit it. metadata.name (or desc) and metadata.z_index are used when present, and metadata.content_rect (frame-relative) crops the frame to its real content.
maskoptMASKPer-frame transparency, index-aligned with the image batch (1 = transparent, LoadImage convention).
layersoptLAYERSLayer stack to append to. Leave unconnected to start a new stack.
crop_to_contentoptBOOLEANtrueCrop each frame to metadata.content_rect where present and place the content at the box position plus the rect offset. Leave on for batches whose frames are padded - it keeps only the real content at its true spot.
canvas_widthoptINT00–16384Document canvas width. 0 derives it from the placed layers.
canvas_heightoptINT00–16384Document canvas height. 0 derives it from the placed layers.

Outputs (1)

NameTypeDescription
LAYERSLAYERSThe layer stack, ready for Create Layered Image.