numpyradiomics.texture#
- numpyradiomics.texture(image, mask, binWidth=25, distances=[1], distance=1, alpha=0, levels=None, connectivity=None, symmetricalGLCM=True, weightingNorm=None)[source]#
Wrapper to compute all texture features (GLCM, GLDM, GLRLM, GLSZM, NGTDM) in a single call.
This function aggregates the 5 standard texture matrices, handling the prefixing of keys (e.g., ‘Contrast’ becomes ‘glcm_Contrast’, ‘gldm_Contrast’, etc.) to avoid name collisions.
- Parameters:
image (np.ndarray) – 3D image array containing voxel intensities.
mask (np.ndarray) – 3D mask array (same shape as image), where non-zero values indicate the ROI.
binWidth (float, optional) – Bin width for discretization (used by all matrices). Default is 25.
distances (list, optional) – List of pixel distances for GLCM. Default is [1].
distance (int, optional) – Integer pixel distance for NGTDM. Default is 1.
alpha (int, optional) – Alpha cutoff for GLDM dependence. Default is 0.
levels (int, optional) – Manual number of levels (overrides binWidth if set). Default is None.
connectivity (int, optional) – Connectivity kernel for GLSZM (e.g., 6, 18, 26). Default is None (26).
symmetricalGLCM (bool, optional) – Whether to symmetrize the GLCM. Default is True.
weightingNorm (str, optional) – GLCM weighting norm (‘manhattan’, ‘euclidean’, ‘infinity’). Default is None.
- Returns:
- Combined dictionary of all texture features (~75 features) with standard prefixes:
glcm_: Features from Gray Level Co-occurrence Matrix.
gldm_: Features from Gray Level Dependence Matrix.
glrlm_: Features from Gray Level Run Length Matrix.
glszm_: Features from Gray Level Size Zone Matrix.
ngtdm_: Features from Neighborhood Gray Tone Difference Matrix.
- Return type:
Example
>>> import numpyradiomics as npr >>> # Generate a noisy ellipsoid >>> img, mask = npr.dro.noisy_ellipsoid(radii_mm=(15, 15, 15), intensity_range=(0, 100)) >>> >>> # Compute all texture features >>> feats = npr.texture(img, mask, binWidth=10) >>> >>> print(f"GLCM Contrast: {feats['glcm_Contrast']:.4f}") GLCM Contrast: 12.4501 >>> print(f"GLSZM Zone %: {feats['glszm_ZonePercentage']:.4f}") GLSZM Zone %: 0.8912