SEGS to Rectangle
When a polygon mask should just be a rectangle
- segs
- segs
SEGS to Rectangle is a one-trick node with a boringly specific job: it takes SEGS whose masks are organic, polygon-shaped blobs and rewrites every one of them as a solid rectangle that fills its bounding box. One input, one output, zero knobs to turn. You don't reach for it every day - but when you need it, it's the difference between a workflow that works and one that quietly misbehaves.
The scenario that makes it worth knowing: you've segmented something (say, with this pack's SAM3Segmentation node) and you want to feed the result into inpainting or a crop-and-refine step. Polygon masks are precise, and that's the problem - an inpaint pass driven by a ragged mask can leave artifacts where the fill boundary stops halfway across the object, and some detailer-style nodes want the whole bounding box covered, not a tight silhouette. The README calls the use case "prepare regions for inpainting where full rectangular coverage is needed," and the pack's own example workflow pairs it with MaskOutline around a subject. Precise is great until it isn't; a solid box is what several downstream steps actually want.
Mechanically it's straightforward, and reading the source makes you trust it more. SEGS is Impact Pack's format - a tuple of (shape, list_of_SEG) - where each SEG carries cropped_image, cropped_mask, confidence, crop_region, bbox, label, and a control_net_wrapper. For each SEG the node reads crop_region (the bounding box), builds a full-ones mask at exactly that size, and rebuilds the SEG with everything else - image, confidence, bbox, label - untouched. Only the mask changes. An empty SEGS list passes straight through, and the whole thing is a fast pure-python pass with no model involved.
The one input is segs (SEGS) and the one output is segs (SEGS), so it slots into any Impact-Pack-shaped graph: SAM3Segmentation's segs output → SEGS to Rectangle → a Detailer or inpaint region. It doesn't care where the SEGS came from, as long as they're Impact-compatible. Since SAM3Segmentation explicitly emits SEGS to plug into Impact Pack, this node is the bridge between "organic SAM mask" and "rectangle a detailer will happily eat."
Install. It's part of the ComfyUI SAM3 pack. ComfyUI Manager handles it - search "ComfyUI SAM3" - or clone it:
cd ComfyUI/custom_nodes
git clone https://github.com/wouterverweirder/comfyui_sam3
cd comfyui_sam3
pip install -r requirements.txt
Restart after. One honest gotcha: this node itself needs nothing from SAM3 - no model, no checkpoint, no HuggingFace access - but the pack loads the sam3 library at import time, so the heavy install (timm, decord, pycocotools, triton) still lands, and Triton is the known pain point on Windows. If you only want this little utility, you're still paying for the whole pack's dependency tree.
Troubleshooting. If the output looks identical to the input, that's normal when the SEGS were already rectangles or the list is empty - the node is a pass-through in those cases. If it errors, the SEGS almost certainly didn't come from an Impact-compatible source and lack a proper crop_region. Don't expect this node to exist in a vacuum: it's one half of a two-node utility pair in the SAM3 pack, and it makes the most sense when SAM3Segmentation is feeding Impact Pack upstream of it.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| segs | SEGS | Input SEGS to convert to rectangular masks |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| segs | SEGS | — |