Mask to Center Point
Turn any mask into the exact center coordinates your SAM2/SeC nodes are begging for
- mask
- segs
- coordinates
- x
- y
- debug
Segmentation gives you a blob; a lot of the things you feed that blob into want a point. SAM2-style prompting, the SeC video-segmentation nodes, any node that seeds a mask from coordinates - they want "where is the thing," not a 50,000-pixel outline. Mask to Center Point is the tiny bridge between the two: hand it a mask or Impact Pack SEGS and it hands you the geometric center as a JSON list of {"x":…, "y":…} plus the first X/Y as plain integers. It's not glamorous, and that's the point - it's the node you slot in when you're tired of wiring math nodes just to find a centroid.
The author built it as the companion to their own Comfyui-SecNodes pack, which is the honest tell for what this is for: video and animation workflows where you mask frame one, get the center, and use that coordinate to seed tracking across the rest. It does exactly that and nothing else.
How it works
Under the hood it's scipy, not an AI model. scipy.ndimage.center_of_mass computes the intensity-weighted centroid of the mask, and scipy.ndimage.label finds physically disconnected regions. That's the whole trick, and it means the node is instant and has zero VRAM footprint - pure CPU math on tensors that are already in memory.
The mode dropdown decides which flavor of "center" you get:
- Combined: treats every mask (or SEGS, rebuilt onto one canvas) as a single blob and returns one center. Good when a segmented object is actually one thing, even if it's oddly shaped.
- Separate Regions: labels each disconnected component and returns a center per region. Feed it a mask with two separate people and you get two coordinates.
It also handles mask batches properly - it iterates every mask in the batch individually, which is exactly what you want for frame-by-frame video work. And if you connect both mask and segs, the segs input wins; the mask is silently ignored. That's documented, but it has tripped up more than one person who assumed the opposite.
Inputs and outputs that matter
- mode - Combined or Separate Regions, described above.
- min_area (default 0) - minimum pixel count for a region to be processed. The killer setting for ignoring specks and noise that segmentation loves to leave behind. Dial it up when you get junk coordinates.
- mask (optional MASK) and segs (optional SEGS) - either one is fine, both is
segs-wins. SEGS must come from an Impact Pack-compatible node; the pack checks the tuple format and warns if it's wrong.
Outputs are four: coordinates (a JSON string like [{"x": 100, "y": 150}, ...]), x and y (integers of the first point only - not an average, just the first one found), and debug (a plain-text log of every region found, its area, and whether it was skipped).
Installing it
Install via ComfyUI Manager (search "ComfyUI Mask to Center Point Nodes"), or clone it manually:
cd ComfyUI/custom_nodes
git clone https://github.com/9nate-drake/ComfyUI-MaskCenter
cd ComfyUI-MaskCenter
pip install -r requirements.txt
Then restart ComfyUI. Requirements are just numpy and scipy - no model downloads, no torch versions to babysit, and you almost certainly already have both. This is about as dependency-light as a custom node gets.
Where people get burned
- The
segs-beats-maskpriority - if you wire both and your mask keeps getting ignored, that's why. - Silent zeroes. If nothing qualifies (mask is empty, or every region is under
min_area), you get an empty[]andx/ycome back as0, 0. Wire those straight into a SAM2 point prompt and you'll prompt the top-left corner of your image. When in doubt, read thedebugoutput - it tells you exactly what was found and skipped. - Separate Regions is only for disconnected blobs. If two things are touching, they're one region. That's exactly what the pack's other node, Detect Mask Sub-Masses, exists for.
It's a small node, but it's the right tool for a genuinely common annoyance. If you've ever wanted to hand a coordinate to a SAM2-style prompt and found yourself building a mini math pipeline to get it, this is the shortcut.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| mode | COMBO | 2 options: Combined, Separate Regions | |
| min_area | INT | 00–99999 | — |
| maskopt | MASK | — | |
| segsopt | SEGS | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| coordinates | STRING | — |
| x | INT | — |
| y | INT | — |
| debug | STRING | — |