numpyradiomics.glcm#
- numpyradiomics.glcm(image, mask, binWidth=25, distances=[1], symmetricalGLCM=True, weightingNorm=None)[source]#
Compute 24 Pyradiomics-style GLCM (Gray Level Co-occurrence Matrix) features.
The GLCM describes the second-order joint probability function of an image region, constrained by the mask. It counts how often pairs of voxels with specific gray levels and specific spatial relationships occur.
- 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) – Width of bins for discretization. Default is 25.
distances (list, optional) – List of integer distances (offsets) to compute GLCMs for. Default is [1].
symmetricalGLCM (bool, optional) – If True, counts co-occurrences in both directions (i->j and j->i). If False, only counts i->j. Default is True.
weightingNorm (str, optional) – Method to weight GLCMs if multiple distances are used. Options: None, ‘manhattan’, ‘euclidean’, ‘infinity’. Default is None.
- Returns:
- Dictionary containing the 24 GLCM features:
Autocorrelation: Magnitude of the fineness and coarseness of texture.
ClusterProminence: Asymmetry of the GLCM.
ClusterShade: Skewness of the matrix.
ClusterTendency: Grouping of voxels with similar gray-level values.
Contrast: Local intensity variation (favors contributions away from the diagonal).
Correlation: Linear dependency of gray levels to their neighbors.
DifferenceAverage: Mean of the difference distribution.
DifferenceEntropy: Randomness/variability in neighborhood intensity differences.
DifferenceVariance: Variance of the difference distribution.
JointAverage: Mean gray level intensity of the $i$ distribution.
JointEnergy: Homogeneity of the texture (sum of squared elements).
JointEntropy: Randomness/variability in neighborhood intensity values.
Id: Inverse Difference (homogeneity 1).
Idm: Inverse Difference Moment (homogeneity 2).
Idmn: Normalized Inverse Difference Moment.
Idn: Normalized Inverse Difference.
Imc1: Informational Measure of Correlation 1.
Imc2: Informational Measure of Correlation 2.
InverseVariance: Inverse variance of the difference distribution.
MCC: Maximal Correlation Coefficient.
MaximumProbability: Occurrence of the most predominant pair of neighboring intensity values.
SumAverage: Mean of the sum distribution.
SumEntropy: Sum of entropies.
SumSquares: Variance of the distribution (Cluster Tendency is a specific case of this).
- Return type:
Example
>>> import numpyradiomics as npr >>> # Generate a noisy ellipsoid >>> img, mask = npr.dro.noisy_ellipsoid(radii_mm=(10, 10, 10), intensity_range=(0, 100)) >>> >>> # Compute GLCM features (distance=1) >>> feats = npr.glcm(img, mask, binWidth=10, distances=[1]) >>> >>> print(f"Contrast: {feats['Contrast']:.4f}") Contrast: 12.4501