Morphology Features API
pictologics.features.morphology
Morphology Feature Extraction Module
This module provides functions for calculating Morphological (Shape and Size) features from medical images. It implements the Image Biomarker Standardisation Initiative (IBSI) compliant algorithms.
Key Features:
- Voxel-based: Volume (voxel counting).
- Mesh-based: Surface Area, Volume (mesh), Compactness, Sphericity.
- PCA-based: Major/Minor/Least Axis Length, Elongation, Flatness.
- Convex Hull: Volume, Area, Max 3D Diameter.
- Bounding Box: Oriented (OMBB) and Axis-Aligned (AABB) Bounding Boxes.
- Minimum Volume Enclosing Ellipsoid (MVEE): Volume, Area.
- Intensity-Weighted: Center of Mass Shift, Integrated Intensity.
Optimization:
Uses numba for optimizing the Khachiyan algorithm for MVEE calculation.
Example
Calculate morphology features from a mask:
import numpy as np
from pictologics.loader import Image
from pictologics.features.morphology import calculate_morphology_features
# Create dummy mask
mask_arr = np.zeros((50, 50, 50), dtype=np.uint8)
mask_arr[10:40, 10:40, 10:40] = 1
mask = Image(mask_arr, spacing=(1.0, 1.0, 1.0), origin=(0,0,0))
# Calculate features
features = calculate_morphology_features(mask)
print(features["volume_voxel_counting_YEKZ"])
calculate_morphology_features(mask, image=None, intensity_mask=None, roi_bbox=None)
Calculate morphological features from the ROI mask. Includes both voxel-based and mesh-based features (IBSI compliant).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Image
|
Image object containing the morphological mask. Nonzero values are treated as ROI membership. |
required |
image
|
Optional[Image]
|
Optional Image object containing intensity data (required for some features). |
None
|
intensity_mask
|
Optional[Image]
|
Optional Image object containing the intensity mask (e.g. after outlier filtering).
If provided, used for intensity-weighted features (99N0, KLMA).
If None, defaults to |
None
|
roi_bbox
|
Optional[tuple[slice, slice, slice]]
|
Optional precomputed tight bounding box of the mask's nonzero voxels (tuple of slices, as returned by an internal bbox scan). Skips rescanning the full mask volume. If None, computed internally. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary of calculated features. |
Example
import numpy as np
from pictologics.loader import Image
from pictologics.features.morphology import calculate_morphology_features
mask_arr = np.zeros((50, 50, 50), dtype=np.uint8)
mask_arr[10:40, 10:40, 10:40] = 1
mask = Image(array=mask_arr, spacing=(1.0, 1.0, 1.0), origin=(0.0, 0.0, 0.0))
features = calculate_morphology_features(mask)
print(round(features["volume_voxel_counting_YEKZ"], 1))
# 27000.0
print(round(features["sphericity_QCFX"], 2))
# 0.82
Source code in pictologics/features/morphology.py
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 | |