SegmentToMaskByPoint-badger
Click a thing, get its mask — SAM in a single node
- img
- sam_ckpt
- mask0
- mask1
- mask2
The whole idea of Segment Anything is that you don't need a segmentation model trained for your specific object - you click on a thing and the model figures out its outline. SegmentToMaskByPoint-badger wraps exactly that in one node: give it an image, an (X, Y) coordinate, and a SAM checkpoint, and it hands back three candidate masks for whatever is at that point.
How it works under the hood is textbook SAM. It feeds your X and Y as a single foreground point into SAM's SamPredictor with multimask_output=True, which makes SAM return its three candidate segmentations - typically the whole object, a prominent part, and an alternative region. Each mask gets binarized and then dilated by your dilate value using OpenCV's cv2.dilate, which expands the mask outward by a square kernel of that size. That dilation is why the default of 15 exists: raw SAM masks hug contours tightly, and a little expansion gives you clean edges for compositing or a safer inpaint region.
The inputs that matter:
- img - the IMAGE to segment.
- X, Y - floats, the click point in pixel coordinates. Yes, floats for a coordinate - that's what the schema says, so just treat them as pixel positions.
- dilate - int, default 15, how much to expand the mask (0 turns dilation off).
- sam_ckpt - a
SAM_MODELinput. This is where you plug in a loaded SAM checkpoint.
The outputs are three MASK tensors: mask0, mask1, mask2. Wire all three into mask previews and pick the one that matches what you clicked - that "pick a mask" step is the whole game with multimask output. If you're using the mask for inpainting, mask-based inpainting still has a real place even in the era of instruction-edit models: it leaves everything outside the mask pixel-identical, which edit models struggle with.
Here's the critical gotcha, and it's the thing that trips everyone up: SAM_MODEL is not a core ComfyUI type. It's defined by a SAM loader pack - Impact Pack's SAM module or the standalone ComfyUI-SAM - and this pack's own requirements.txt does not install segment_anything. So the node won't even load unless you already have one of those packs installed, and a SAM checkpoint in models/sams (like sam_vit_h_4b8939.pth or sam_vit_b_01ec64.pth). Install order matters: SAM pack + checkpoint first, then this node.
There's also a nice in-pack pairing. findCenterOfMask-badger outputs X and Y floats for the centroid of any mask - feed that into this node's X and Y and you've got a "mask one thing, auto-click its center, get a finer mask" loop without touching the coordinates by hand.
Install the pack the usual way:
cd ComfyUI/custom_nodes
git clone https://github.com/AbyssYuan0/ComfyUI_BadgerTools
or search ComfyUI_BadgerTools in ComfyUI Manager, restart. This node is the heavyweight of the pack - it pulls in a real SAM model and runs it on every execution, so it's slower and hungrier than its siblings. But for one-click object masking, it's hard to beat.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| img | IMAGE | — | |
| X | FLOAT | 0.00–4096 | — |
| Y | FLOAT | 0.00–4096 | — |
| dilate | INT | 150–4096 | — |
| sam_ckpt | SAM_MODEL | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| mask0 | MASK | — |
| mask1 | MASK | — |
| mask2 | MASK | — |