Conversion functions
- class tomni.annotation_manager.main.AnnotationManager(annotations: List[tomni.annotation_manager.annotations.annotation.main.Annotation])[source]
Bases:
object
- to_binary_mask(shape: Tuple[int, int]) numpy.ndarray [source]
Transform an AnnotationManager object to a binary mask.
This method generates a binary mask from the annotations stored in the AnnotationManager object. Supported annotation types for conversion are polygon and ellipse.
- Parameters
shape (Tuple[int, int]) – The shape (width, height) of the new binary mask.
- Returns
A binary mask where annotated regions are represented by 1 (True) and non-annotated regions are represented by 0 (False).
- Return type
np.ndarray
Note
This method supports annotations of type Polygon and Ellipse for conversion to a binary mask.
The binary mask represents annotated regions with 1 and non-annotated regions with 0.
- to_contours() List[numpy.ndarray] [source]
Transform an AnnotationManager object to a collection of OpenCV-style contours.
This method generates a collection of contours from the annotations stored in the AnnotationManager object. Supported annotation type for conversion is ‘Polygon’. Each contour is represented as a NumPy array of shape (N, 1, 2), where N is the number of points in the contour, and each point has (x, y) coordinates.
- Raises
ValueError – If any annotation in the AnnotationManager is not of type ‘Polygon’.
- Returns
A collection of contours, where each contour is represented as a NumPy array.
- Return type
List[np.ndarray]
Note
This method supports only annotations of type ‘Polygon’ for conversion to contours.
Each contour is represented as a NumPy array of shape (N, 1, 2), where N is the number of points in the contour, and each point has (x, y) coordinates.
- to_dict(decimals: int = 2, mask_json: Optional[List[dict]] = None, min_overlap: float = 0.9, features: Optional[List[str]] = None, metric_unit: str = '', feature_multiplier: float = 1, **kwargs) List[Dict] [source]
Transform the AnnotationManager object into a collection of data in AxionBio format.
- Parameters
decimals (int, optional) – The number of decimals to use when rounding. Defaults to 2.
mask_json (Union[dict, None], optional) – The dictionary mask that indicates the area to include in the output dictionary. Defaults to None.
min_overlap (float, optional) – Minimum overlap required between the polygon and the mask, expressed as a value between 0 and 1. Defaults to 0.9.
features (Union[List[str], None], optional) – The features you want to calculate and add to the dictionary objects. Defaults to None, which returns all features.
metric_unit (str, optional) – The suffix to add to the dictionary keys’ names in camelCasing. Defaults to “”.
feature_multiplier (float, optional) – A multiplier used during feature calculation, e.g., 1/742. Defaults to 1.
Note
If a mask_json is provided, the method filters annotations based on their overlap with the mask.
Only annotations meeting the specified min_overlap criteria are included in the output.
If no mask_json is provided, all annotations are included in the output.
- Returns
Output is a list of dictionaries in AxionBio format.
- Return type
List[Dict]
- to_labeled_mask(shape: Tuple[int, int]) numpy.ndarray [source]
Transform an Annotation Manager object to a labeled mask. This method generates a labeled mask from the annotations stored in the AnnotationManager object. Supported annotation types for conversion are polygon and ellipse.
- Parameters
shape (Tuple[int, int]) – The shape (width, height) of the new labeled mask.
- Returns
A new labeled mask where each labeled region corresponds to an annotation.
- Return type
np.ndarray
- Raises
TypeError – If the AnnotationManager contains annotations of unsupported types.
Note
This method supports annotations of type Polygon and Ellipse for conversion to a labeled mask.
Each labeled region in the generated mask corresponds to an annotation, and the regions are labeled with unique integer values starting from 1.