Manual Point to SAM2 (JSON)
Point SAM2 At the Right Spot Without the JSON Headache
- STRING
SAM2 works by the point. You click on the thing you want to segment, it figures out the rest. But inside ComfyUI, that click gets turned into a JSON string of coordinates, and hand-typing [{"x": 512, "y": 256}] into a widget is exactly the kind of friction that makes people give up on segmentation nodes entirely. ManualPointToSAM2 is the node that generates that JSON for you - and it's smarter than a static coordinate pair, because it can spray a seeded cluster of points around a location, which is often what actually gets SAM2 to latch onto the right object.
It's part of AnotherUtils (marcoc2/ComfyUI-AnotherUtils), the image/video utility pack by marcoags. Pure math, no models, no dependencies - you could do this in your head for one point, but the node makes the messy cases (multiple points, randomized jitter) reproducible and seedable.
How it works
Give it an x and y and it emits a JSON array of points. The interesting part is num_points and radius. When both are above their minimums, instead of one point it generates num_points coordinates scattered uniformly inside a circle of that radius around your click - using the r = radius * sqrt(random()) trick so the points are evenly distributed across the disk rather than piling up in the center. The distribution is seeded by seed, so the same inputs give you the same points every run. That determinism matters: in a segmentation workflow you want the exact same point cloud when you re-run, or your masks drift and you can't debug anything.
Set num_points to 1 (or radius to 0) and it just returns your single x, y as a one-element list.
The inputs that matter
x/y- your target pixel coordinates in the image.num_points- how many points to generate around that target. More points = SAM2 gets a stronger hint, but too many can pull the mask toward whatever else is in the radius.radius- the scatter radius in pixels. Zero disables the scattering.seed- the reproducibility knob. This is the one you'll actually fiddle with if the point cloud doesn't look right.
What comes out
A single STRING output holding JSON like [{"x": 333, "y": 333}]. That string plugs directly into the coordinates_positive input of AnotherSAM2VideoAddPoints (the video-tracking initializer in the same pack), which is the intended downstream use. You can also feed it to a SAM2 single-image node that accepts JSON point prompts, or chain it after the pack's AnotherBBoxToPoints / SEGStoSAM2Points nodes if you'd rather derive points from YOLO detections than type coordinates.
Installing it
Same as the rest of the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/marcoc2/ComfyUI-AnotherUtils.git
Restart ComfyUI, or search "AnotherUtils" in ComfyUI Manager. No models, no pip packages.
Where people get burned
The usual failure is coordinates out of range - the input caps at 8192, but if you type something bigger than your actual image, SAM2 just gets a point in the void and segments nothing. Keep x/y inside your real pixel bounds. The other trap is over-asking: with a big radius and high num_points you can accidentally include background in the cloud, and SAM2 treats every positive point as "this is my object." Start with one point, verify, then add scatter. Oh, and don't forget the seed - without it locked, "same point every time" becomes a lie.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| x | INT | 3330–8192 | — |
| y | INT | 3330–8192 | — |
| num_points | INT | 11–100 | — |
| radius | INT | 00–500 | — |
| seed | INT | 00–18446744073709550000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |