Add Center

tomni.json_operations.add_center(json_object: dict)[source]

Calculate and add the center coordinates to a JSON annotation object.

This function takes a JSON object representing an annotation in standard AxionBio format (ellipse or polygon), calculates the center coordinates of the object, and adds them as the “center” 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:

# Define a sample JSON annotation object in AxionBio format (polygon)
sample_json_object = {
    "type": "polygon",
    "points": [[100, 100], [200, 100], [200, 200], [100, 200]]
}

# Call the add_center function to calculate and add the center coordinates
add_center(sample_json_object)

# The updated JSON object will contain the added "center" key
# Updated JSON Object:
updated_json_object = {
    'type': 'polygon',
    'points': [[100, 100], [200, 100], [200, 200], [100, 200]],
    'center': {'x': 150.0, 'y': 150.0}
}

Note

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

  • For ellipses, no action is taken as the center is already included in the JSON object.

  • For polygons, the center coordinates are calculated using the get_center function from the contour_operations module.