liom_toolkit.segmentation.stats module
- liom_toolkit.segmentation.stats.calculate_density(vessel_mask: ndarray, mask: ndarray, voxel_size: float = 0.65) tuple[float, float, float]
Calculates the areas of the tissue and vessel to compute the density of vessels in a mask.
- Parameters:
vessel_mask (np.ndarray) – The mask of the vessels.
mask (np.ndarray) – The mask of the tissue.
voxel_size (float) – The size of the voxels in the image.
- Returns:
The area of the tissue, the area of the vessels, and the density of the vessels.
- Return type:
tuple[float, float, float]
- liom_toolkit.segmentation.stats.calculate_regional_density(region: ndarray, region_index: int, props_list: list[RegionProperties], output_dir: str, voxel_size: float = 0.65) tuple[float, float, float]
Calculates the density of vessels in a region
- Parameters:
region (np.ndarray) – The region to calculate the density of.
region_index (int) – The computational index of the region.
props_list (list[RegionProperties]) – The list of properties of the regions.
output_dir (str) – The directory to save the region mask to.
voxel_size (float) – The size of the voxels in the image.
- Returns:
The area of the vessels, the area of the region, and the density of the vessels in a specific region.
- Return type:
tuple[float, float, float]
- liom_toolkit.segmentation.stats.compute_average_diameter(mask: ndarray, skeleton: ndarray, voxel_size: float = 0.65) float
Compute the average diameter of the vessels in a mask
- Parameters:
mask (np.ndarray) – The vessel mask.
skeleton (np.ndarray) – The skeleton of the vessels.
voxel_size (float) – The size of the voxels in the image.
- Returns:
The average diameter of the vessels in the mask.
- Return type:
float
- liom_toolkit.segmentation.stats.compute_mask_area(mask: Array | Future) uint64
Compute the area of a mask. Sums the binary masks.
- Parameters:
mask (da.Array | Future) – The mask to compute the area of.
- Returns:
The area of the mask.
- Return type:
np.uint64
- liom_toolkit.segmentation.stats.compute_slice_metrics(output_dir: str, image: ndarray, mask: ndarray, vessel_mask: ndarray, region_map: ndarray, vessel_exclude: ndarray, voxel_size: float = 0.65) None
Compute the metrics for a brain slice. Save the results to disk.
- Parameters:
output_dir (str) – The directory to save the output to
image (np.ndarray) – The image of the brain slice
mask (np.ndarray) – The mask of the tissue in the brain slice
vessel_mask (np.ndarray) – The mask of the vessels in the brain slice
region_map (np.ndarray) – The map of the regions in the brain slice
vessel_exclude (np.ndarray) – The mask of the vessels to exclude from the analysis
voxel_size (float) – The size of the voxels in the image
- liom_toolkit.segmentation.stats.create_filter_image(atlas: Array | Future, region_ids: list[int]) Array
Create a filter image based on the region ids.
- Parameters:
atlas (da.Array | Future) – The atlas containing the region ids.
region_ids (list[int]) – The region ids to filter.
- Returns:
The filter image.
- Return type:
da.Array
- liom_toolkit.segmentation.stats.create_heatmap(image: ndarray, output_dir: str, square_size: int = 150) None
Create and save a heatmap of the vessel density in a brain slice and save it to disk.
- Parameters:
image (np.ndarray) – The image of the brain slice.
output_dir (str) – The directory to save the heatmap to.
square_size (int) – The size of the squares in the heatmap
- liom_toolkit.segmentation.stats.draw_branch_point_circles(skeleton: ndarray, branching_points: ndarray, output_dir: str, filename: str = 'skeleton_circled.png') None
Draw circles around the branching points in a skeleton
- Parameters:
skeleton (np.ndarray) – The skeleton of the vessels.
branching_points (np.ndarray) – The location of the branching points.
output_dir (str) – The directory to save the skeleton to.
filename (str) – The filename to save the skeleton to.
- Returns:
The circled branching point in the skeleton.
- Return type:
np.ndarray
- liom_toolkit.segmentation.stats.filter_image_to_region(image_filter: Array, data: Array | Future) Array
Filter an image to a region based on a filter.
- Parameters:
image_filter (da.Array) – The filter to apply.
data (da.Array | Future) – The data to filter.
- Returns:
The filtered image.
- Return type:
da.Array
- liom_toolkit.segmentation.stats.generate_itk_id_list_of_region(region: str, data_dir='') list[int]
Generate a list of itk ids for a given region. Will reconstruct the structure tree and get the descendants contained within the region
- Parameters:
region (str) – The region to get the ids for.
data_dir (str) – The directory where the atlas and structure tree are saved. Optional.
- Returns:
The list of itk ids for the region and its descendants.
- Return type:
list[int]
- liom_toolkit.segmentation.stats.get_branching_point_count(vessel_mask: ndarray, output_dir: str, filename: str = 'skeleton.tif') tuple[int, ndarray, ndarray]
Get the number of branching points in a vessel mask.
- Parameters:
vessel_mask (np.ndarray) – The mask of the vessels.
output_dir (str) – The directory to save the skeleton to.
filename (str) – The filename to save the skeleton to.
- Returns:
The number of branching points in the vessel mask, the skeleton of the vessel mask, and the location of the branching points.
- Return type:
tuple[int, np.ndarray, np.ndarray]
- liom_toolkit.segmentation.stats.get_branching_points(skeleton: ndarray) ndarray
Get the branching points in a skeleton using predefined structural elements Source: https://stackoverflow.com/questions/43037692/how-to-find-branch-point-from-binary-skeletonize-image
- Parameters:
skeleton (np.ndarray) – The skeleton of the vessels.
- Returns:
The branching points in the skeleton.
- Return type:
np.ndarray
- liom_toolkit.segmentation.stats.get_vessel_region(regions: ndarray, region_index: int, vessel_mask: ndarray) ndarray
Get the vessels in a region.
- Parameters:
regions (np.ndarray) – The regions of the tissue mask.
region_index (int) – The index of the region.
vessel_mask (np.ndarray) – The mask of the vessels.
- Returns:
The vessel within the masked region.
- Return type:
np.ndarray