SEGS to BBOX
Pull the coordinates out, no pixels read
- segs
- xyxy
- xywh
- bounding_box
SEGS already know where their regions are. Each entry carries a bbox and a crop region, and until you can get those numbers out as plain values, they're locked inside the detection layer - you can render with them, but you can't crop with them, or drive a rectangle-shaped input with them. SEGS to BBOX is the extrude step: coordinates in, three flavours of rectangle out.
What it returns
Three list outputs, all index-aligned with the SEGS entries, each containing one rectangle per region:
xyxy-(x1, y1, x2, y2)in the SEGS' own convention, which is Impact's: exclusive end, meaningx2/y2is one pixel past the box rather than inside it. This matters if you feed the numbers to anything that expects inclusive coordinates.xywh-(x, y, width, height), computed asx2 - x1andy2 - y1. Same rectangle, the form most crop and composite nodes want.bounding_box- the newerBOUNDING_BOXstructure ComfyUI core uses for its region primitives, carryingx,y,widthandheightas named fields. Wire this into anything that takes a rectangle primitive instead of four loose integers.
Nothing is measured from pixels. The node reads the bbox field straight off each segment, checks it has exactly four integer coordinates, and raises on reversed ones - x2 < x1 or y2 < y1 is a hard error rather than something it quietly normalises.
The distinction that matters
Here's the trap, and it's a good one to understand because it comes up in any workflow mixing detectors and masks: a segment's bbox is not the same thing as the bounding box of its pixels. For a YOLO-style detector the bbox is the box the detector proposed in source coordinates, possibly a little generous, while the mask inside it is the actual region. For SEGS that this pack's own MASK to Tile SEGS produced, the roles are inverted - crop_region is the tile and bbox is the content bounds within that tile, measured from nonzero mask pixels.
So if you want "the tightest box around the actual mask pixels", that's Mask to Bounding Box, which runs torch.nonzero over the mask. SEGS to BBOX gives you the detector's or producer's own metadata, unexamined. Both are correct answers to different questions, and picking the wrong one is how you end up with a crop that's 40px too wide.
Where you'd use it
Any place a coordinate needs to become a widget-driven value rather than a wire: cropping the source image to a detected region, feeding a rectangle primitive into core crop/paste nodes, writing coordinates into a filename, or driving an outpainting canvas. It's also the cheap way to sanity-check a detector - print the boxes and see whether the fourth one is the rock formation the detailer was about to spend GPU time on.
Paired with Reorder SEGS there's a small thing to remember: reordering reorders the entries, so the box lists reorder with them. If you're matching boxes to indices you generated before the reorder, rematch them after.
Install
Manager: search ComfyUI Utility Suite (publisher tom-m) → install → restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/tom-m-2020/ComfyUI-Utility-Suite
No model files, nothing heavy; the pack's single dependency is opencv-python-headless, and this node doesn't use it - it's pure metadata manipulation. You'll need something upstream that emits SEGS: this pack's MASK to Tile SEGS, or the Impact-Pack detector stack. The pack duck-types the SEGS shape rather than importing Impact, so either source works. It's built on ComfyUI's V3 node API, which is also where the BBOX and BOUNDING_BOX types come from, so keep ComfyUI reasonably current.
Troubleshooting
"expects SEGS shaped as (source_size, segment_entries)." You're feeding it something that only looks like SEGS. List / Batch Inspector is the pack's tool for finding out what you're actually holding.
"bbox has reversed coordinates." A malformed region - sign of hand-built or converted SEGS rather than a detector. Fix the producer rather than working around it.
Boxes are a couple of pixels off compared to what you measured yourself. Exclusive-end coordinates. Add one to the bottom-right values if your downstream tool expects the last pixel to be inside the box.
Only the first box came through. The outputs are lists, so they carry one rectangle per region. Connect it to something that reads lists, or select one entry with SEG From SEGS first.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| segs | SEGS | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| xyxy | BBOX | — |
| xywh | BBOX | — |
| bounding_box | BOUNDING_BOX | — |