Mask to SEGS
Turn any mask into Impact Pack SEGS, so it can feed a Detailer
- mask
- segs
Most detailing workflows start with a detector: a YOLO finds faces, a SAM segments an object, and out comes SEGS - the Impact Pack data type that a Detailer node iterates over to re-render each detected region. But what if your "detection" is already a mask - a manual paint-in, a mask from a segmentation model, a difference mask from video? You don't need to detect anything; you need to package the mask so the Detailer machinery will eat it. Mask to SEGS is the bridge: a MASK tensor in, a SEGS out.
It's this pack's answer to Impact Pack's own mask-to-segs helpers, implemented directly against the SEGS format (the same SEG namedtuple structure, with the crop-region logic taken from Impact's own utilities). Nothing about it is AI - it's pure geometry: find contours in the mask, compute bounding boxes, crop, package.
How it works
Each connected region in the mask becomes a SEG entry. It finds the blob's bounding box, expands it by crop_factor (default 3 - the multiplier on the box size that gives the detailer breathing room), crops the mask to that region, and wraps it as a SEG with cropped_mask, bbox, crop_region, and a label of "A". If a mask has multiple disjoint regions, you get multiple SEGs, and a downstream DetailerForEach will process each one - same flow as detector-driven detailing, just with your mask standing in for the detector.
The inputs that tune the geometry:
combined- false by default (each blob = one SEG). Flip it true to treat the whole mask as a single bounding box, which is what you want for "one big region, please."crop_factor- how much padding around the box. 3 is a sane default; too small and the detailer chokes on edge context, too big and it's sampling a mostly-empty crop.drop_size- minimum contour size to keep (default 10). Drops the dust specks from a noisy mask.bbox_fillandcontour_fill- fill the box or the contour solid in the cropped mask, useful when you want the detailer to see a filled region rather than an outline.
Why bother instead of using a detector
Detectors are fast and fine for faces and people. Masks are better when your target is arbitrary - a specific costume element, a hand-drawn shape, a region that changes per frame in a video pipeline. The KB's detailing doc frames it well: the whole value of SEGS is that once anything produces the container, everything downstream works the same. This node lets you be the detector.
Install
Part of ComfyUI_Eclipse (r-vage). ComfyUI Manager, search ComfyUI_Eclipse, or:
cd ComfyUI/custom_nodes
git clone https://github.com/r-vage/ComfyUI_Eclipse
Restart ComfyUI. It uses opencv-python for the contour work, which is in the pack's requirements - ComfyUI usually has it, but if you get an ImportError: cv2, install it into ComfyUI's Python. It expects Impact Pack's SEGS type to exist for the downstream nodes; you don't need Impact Pack installed for this node (it bundles its own fallback SEG definition), but you'll want it for the Detailer that consumes the output.
Common issues
Empty SEGS when you expected regions: your mask is all-noise or the regions are smaller than drop_size - lower it. Detailer cropping weirdly: crop_factor too small gives truncated subjects, too large wastes steps; 3 is the floor for most faces. And the classic gotcha - mask shape. If your mask is a full-resolution tensor but the image you're detailing is downscaled elsewhere, the bboxes land in the wrong coordinate space. Do the mask and image conversions at the same resolution, and SEGS Preview (this pack has one) will show you the regions before you waste a detail pass on garbage.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | Input mask tensor. | |
| combined | BOOLEAN | false | Combine all masks into one bounding box. |
| crop_factor | FLOAT | 3.01β100 | Crop factor around bounding box. |
| bbox_fill | BOOLEAN | false | Fill bounding box with 1.0 in cropped mask. |
| drop_size | INT | 101β8192 | Minimum contour size to keep. |
| contour_fill | BOOLEAN | false | Fill contours completely. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| segs | SEGS | β |