json2bbox

tomni.transformers.json2bbox(scf_object: dict) tuple[source]

Convert a standard AxionBio format object (polygon, ellipse, or circle) into bounding box coordinates (x_min, y_min, x_max, y_max). All bounding box values are rounded using Python’s internal ‘round’ function (https://wiki.c2.com/?BankersRounding).

Parameters

scf_object (Dict[str, any]) – A single annotation in standard AxionBio format. Allowed types are polygon, ellipse, or circle.

Returns

Bounding box coordinates in the format (x_min, y_min, x_max, y_max).

Return type

Tuple[int, int, int, int]

Note

  • The angle of rotation for an ellipse is taken into account.

Raises

ValueError – If the type of the object is not supported.

Example:

object = {
    "type": "polygon",
    "points": [{'x': 0, 'y': 0}, {'x': 20, 'y': 0}, {'x': 20, 'y': 30}, {'x': 0, 'y': 30}]
}
bbox = json2bbox(object)
print(bbox)
(0, 0, 20, 30)