Coordinates
Coordinate convention handling for converting between annotation, numpy, and shapely coordinate systems.
nimbusimage.coordinates
Coordinate convention handling for NimbusImage annotations.
Three coordinate systems: 1. Annotation: {'x': pixel_x, 'y': pixel_y} — x horizontal, y vertical 2. Numpy: array[row, col] = array[y, x] 3. Shapely: Point(x, y) — x horizontal, y vertical
Convention in this package: - Shapely x = annotation x = image column (horizontal) - Shapely y = annotation y = image row (vertical) - No x/y swap for shapely conversions - For numpy masks: row = annotation y, col = annotation x - 0.5 offset: annotation coords are at pixel top-left corners; scikit-image draws at pixel centers
annotation_to_polygon(coordinates)
Convert annotation coordinate dicts to a shapely Polygon.
No x/y swap — annotation x maps to shapely x (horizontal).
annotation_to_point(coordinates)
Convert annotation coordinate dicts to a shapely Point.
For single-coordinate annotations, returns that point. For multi-coordinate (polygons), returns the centroid.
polygon_to_coordinates(polygon)
Convert a shapely Polygon to annotation coordinate dicts.
Strips the duplicate closing point that shapely adds.
point_to_coordinates(point)
Convert a shapely Point to annotation coordinate dicts.
coordinates_to_mask(coordinates, shape)
Convert annotation coordinates to a boolean mask.
Applies the 0.5 offset: annotation coords are at pixel top-left corners, but rasterization uses pixel centers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coordinates
|
list[dict]
|
List of {'x': ..., 'y': ...} dicts. |
required |
shape
|
tuple[int, int]
|
(height, width) of the output mask. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Boolean numpy array of the given shape. |
mask_to_coordinates(mask)
Convert a boolean mask to annotation coordinates.
Uses contour finding and adds the 0.5 offset back.
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of {'x': ..., 'y': ...} dicts forming the polygon boundary. |