Coverage for src/abm_shape_collection/get_shape_properties.py: 100%
6 statements
« prev ^ index » next coverage.py v7.1.0, created at 2024-09-25 19:34 +0000
« prev ^ index » next coverage.py v7.1.0, created at 2024-09-25 19:34 +0000
1import numpy as np
2from skimage.measure import regionprops_table
5def get_shape_properties(array: np.ndarray, properties: list[str]) -> dict:
6 """
7 Calculate shape properties for binary image array.
9 Shape properties must be value properties from skimage.measure.regionprops.
10 Image is projected along the first axis.
12 Parameters
13 ----------
14 array
15 Binary image array.
16 properties
17 List of shape properties to calculate.
19 Returns
20 -------
21 :
22 Dictionary of calculated shape properties.
23 """
25 flattened_array = array.max(axis=0)
27 properties_dict = regionprops_table(flattened_array, properties=properties)
28 return {key: value[0] for key, value in properties_dict.items()}