Mask to SAM3 Box
Feed SAM3 the boxes it wants, straight from a mask you already have
- mask
- sam3_box
SAM3 has a quirky input format. It doesn't want raw pixel coordinates - it wants boxes as normalized cx, cy, width, height values (fractions of the image), paired with a positive/negative label, packed into a SAM3_BOXES_PROMPT. Hand-typing that for every box is miserable, which is why Mask to SAM3 Box (1hew_MaskToSam3Box) exists: draw or generate a mask, and it converts it into exactly the prompt SAM3's nodes expect.
SAM3 is the current high-water mark for interactive segmentation - the KB's own take is that it's the masking tier of 2026, the thing people now use to build inpainting masks instead of painting them by hand. This node lets you skip the "click on the object" step entirely: if you can produce a mask some other way (YOLO detection, manual paint, another segmentation pass), this converts it into SAM3's language.
How it works
It binarizes the mask at 0.5, then finds the box (or boxes) covering the white pixels. In merge mode, every white pixel is wrapped in one single bounding box. In separate mode, connected components are split apart (via scikit-image's region labeling) so each blob becomes its own box - think "every person in a group photo gets a box."
Each box is then converted to normalized cx, cy, bw, bh (center and size as fractions of the image), and the condition combo tags every box as positive or negative. Positive boxes say "segment this," negative boxes say "make sure this is not the object" - useful for telling SAM3 to ignore a background region that's confusing it. The result is a sam3_box output of type SAM3_BOXES_PROMPT that plugs straight into SAM3 nodes.
Inputs and outputs
- mask - the selection you're converting.
- condition -
positive(default) ornegative, applied to all boxes in the batch. - output_mode -
merge(one box) orseparate(per connected region). - sam3_box - the SAM3 prompt object.
Installing it
It's part of the 1hewNodes pack:
cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes
or via ComfyUI Manager ("1hewNodes"), then restart. It needs scikit-image, which the pack's requirements already install.
The workflow it unlocks
The obvious pipeline: detect people with the pack's Detect Yolo, feed the resulting masks in here with output_mode: separate and condition: positive, and hand the boxes to a SAM3 inpainting setup - automated "mask every person, then edit them individually." If your mask is noisy, merge mode is the safe default because a single tight box is more robust than a scattering of blobs. One honest caveat: condition applies the same label to all boxes in the output. For mixed positive/negative prompts you'd run the node twice and merge, which is clunkier than it should be but rare in practice. For the "mask I already drew → SAM3 box" case, this is the cleanest adapter around.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| condition | COMBO | positive | 2 options: positive, negative |
| output_mode | COMBO | merge | 2 options: merge, separate |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| sam3_box | SAM3_BOXES_PROMPT | — |