Coordinate_fromMask
Turning a mask region into an actual x/y coordinate
- mask
- coordinates
- bbox
- norm_x
- norm_y
- px_x
- px_y
Masks tell you where something is as a field of white pixels, but plenty of downstream tools want a single number - an x, a y, a bounding box - not a whole tensor. Coordinate_fromMask is the bridge: feed it a mask, get a coordinate out.
What it is and why you'd reach for it
This sits in ComfyUI-Apt_Preset's ImgCoordinate family, a set of nodes built around passing point/region data as plain numbers or JSON instead of image tensors. The natural use case: you've generated a mask some other way - a detector, a segmentation model, one of Apt_Preset's own shape-mask nodes - and now you need its location as a coordinate to drive something else: a crop, a point-based conditioning input, or one of this pack's own coordinate-consuming nodes like Coordinate_MarkRender.
How it works
You give it a mask and pick a coordinate_align - one of nine anchor points (the four corners, the four edge-midpoints, or center, the default). That's the point within the mask's bounding region the node reports back. index (default 0) matters if your mask has multiple disconnected blobs - it's how you pick which one, presumably ordered however the node finds them, so if you're expecting the second region and get the first, try bumping the index. ignore_threshold (0–2048, default 0) reads like a minimum-size filter: small stray white pixels or noise below that pixel threshold get ignored so they don't get mistaken for a real region.
Inputs and outputs that matter
mask(required) - the mask you're extracting a location from.coordinate_align(required, enum) - which anchor point of the region to report:center,top_left,bottom_right, and so on.index(required, default 0) - which mask region to target, if there's more than one.ignore_threshold(required, default 0) - filters out regions smaller than this many pixels.
Outputs: coordinates (a JSON string, in the same format the rest of the ImgCoordinate family uses), bbox (the region's bounding box), and the same point given four separate ways - norm_x/norm_y (0–1 floats) and px_x/px_y (pixel ints) - so you can wire directly into whichever a downstream node wants without a conversion step.
Installing it
Through ComfyUI Manager: search ComfyUI-Apt_Preset, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git
Run install.bat on Windows for dependencies; on Linux/Mac there's no bundled installer, so grab the requirements yourself. No model downloads required - this is geometry on an existing mask, not inference.
Common issues
If coordinates/bbox come back empty or the node throws on an all-black mask, that's expected - there's no region to find. Raise ignore_threshold if you're getting a spurious tiny region picked up from JPEG noise or anti-aliasing artifacts around a "real" mask edge instead of the mask you actually care about.
The index here is 0-based (starts at 0), which is worth remembering if you're also using Coordinate_SplitIndex elsewhere in the same graph - that node's index is 1-based. Mixing the two up is an easy way to silently grab the wrong point.
As with the rest of this pack: it's large and actively developed, and at least one user has hit an IMPORT FAILED error at ComfyUI startup after installing it. If Apt_Preset nodes aren't appearing at all, check the startup console log first - it'll usually name the missing dependency rather than leaving you guessing.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| coordinate_align | COMBO | center | 9 options: top_left, top_right, bottom_left, bottom_right, center, top_center, +3 |
| index | INT | 00–99 | — |
| ignore_threshold | INT | 00–2048 | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| coordinates | STRING | — |
| bbox | BOUNDING_BOX | — |
| norm_x | FLOAT | — |
| norm_y | FLOAT | — |
| px_x | INT | — |
| px_y | INT | — |