Add Area

tomni.json_operations.add_area(json_object: dict) None[source]

Calculate and add the area of a geometric object to a JSON annotation object.

This function takes a JSON object representing a geometric annotation in standard AxionBio format (ellipse, polygon, or circle), calculates the area of the object, and adds it as the “area” key in the JSON object.

Parameters

json_object (dict) – A JSON object following the standard AxionBio format.

Raises

ValueError – If the type of the annotation in the JSON object is not supported.

Example:

circle_json = {
    "type": "circle",
    "center": {"x": 10, "y": 10},
    "radiusX": 5
}
add_area(circle_json)
print(circle_json)
{
    "type": "circle",
    "center": {"x": 10, "y": 10},
    "radiusX": 5,
    "area": 78.53981633974483
}

Note

  • Supported annotation types are “circle,” “ellipse,” and “polygon.”

  • The area is calculated based on the properties of the geometric object: - For circles, it uses the formula: π * (radiusX^2) - For ellipses, it uses the formula: π * radiusX * radiusY - For polygons, it calculates the area using OpenCV’s cv2.contourArea function.