radiomics package

Submodules

radiomics.base module

class radiomics.base.RadiomicsFeaturesBase(inputImage, inputMask, **kwargs)[source]

Bases: object

enableFeatureByName(featureName, enable=True)[source]
enableAllFeatures()[source]
disableAllFeatures()[source]
classmethod getFeatureNames(c)[source]
calculateFeatures()[source]

radiomics.featureextractor module

class radiomics.featureextractor.RadiomicsFeaturesExtractor(*args, **kwargs)[source]

Wrapper class for calculation of a radiomics signature. At and after initialisation various settings can be used to customize the resultant signature. This includes which classes and features to use, as well as what should be done in terms of preprocessing the image and what images (original and/or filtered) should be used as input.

Then a call to computeSignature generates the radiomics signature specified by these settings for the passed image and labelmap combination. This function can be called repeatedly in a batch process to calculate the radiomics signature for all image and labelmap combinations.

It initialisation, a parameters file can be provided containing all necessary settings. This is done by passing the location of the file as the single argument in the initialization call, without specifying it as a keyword argument. If such a file location is provided, any additional kwargs are ignored. Alternatively, at initialisation, the following general settings can be specified in kwargs:

  • verbose [True]: Boolean, set to False to disable status update printing.
  • binWidth [25]: Float, size of the bins when making a histogram and for discretization of the image gray level.
  • resampledPixelSpacing [None]: List of 3 floats, sets the size of the voxel in (x, y, z) plane when resampling.
  • interpolator [sitkBSpline]: Simple ITK constant or string name thereof, sets interpolator to use for resampling. Enumerated value, possible values:
    • sitkNearestNeighbor
    • sitkLinear
    • sitkBSpline
    • sitkGaussian
    • sitkLabelGaussian
    • sitkHammingWindowedSinc
    • sitkCosineWindowedSinc
    • sitkWelchWindowedSinc
    • sitkLanczosWindowedSinc
    • sitkBlackmanWindowedSinc
  • padDistance [5]: Integer, set the number of voxels pad cropped tumor volume with during resampling. Padding occurs in new feature space and is done on all faces, i.e. size increases in x, y and z direction by 2*padDistance. Padding is needed for some filters (e.g. LoG). After application of filters image is cropped again without padding. Value of padded voxels are set to original gray level intensity, padding does not exceed original image boundaries.

N.B. Resampling is disabled when either resampledPixelSpacing or interpolator is set to None

In addition to these general settings, filter or featureclass specific settings can be defined here also. For more information on possible settings, see the respective filters and feature classes.

By default, all features in all feature classes are enabled. By default, only original input image is enabled N.B. for log, the sigma is set to range 0.5-5.0, step size 0.5

addProvenance(provenance_on=True)[source]

Enable or disable reporting of settings used for calculated filters. By default, settings used are added to the dictionary of calculated features as {“settings_<filter>”:<settings>} To disable this, call addProvenance(False)

loadParams(paramsFile)[source]

Parse specified parameters file and use it to update settings in kwargs, enabled feature(Classes) and input images: - kwarg settings not specified in parameters are set to their default value. - enabledFeatures are replaced by those in parameters. If no featureClass parameters were specified, all

featureClasses and features are enabled.
  • inputImages are replaced by those in parameters. If no inputImage parameters were specified, only original image is used for feature extraction, with no additional custom settings

The paramsFile is written according to the YAML-convention (www.yaml.org) and is checked by the code for consistency. Only one yaml document per file is allowed. Settings must be grouped by setting type as mentioned above are reflected in the structure of the document as follows:

<Setting Type>:
  <Setting Name>: <value>
  ...
<Setting Type>:
  ...

Blank lines may be inserted to increase readability, the are ignored by the parser. Additional comments are also possible, these are preceded by an ‘#’ and can be inserted on a blank line, or on a line containing settings:

# This is a line containing only comments
setting: # This is a comment placed after the declaration of the 'setting' group.

Any keyword, such as a setting type or setting name may only be mentioned once. Multiple instances do not raise an error, but only the last encountered one is used.

The three setting types are named as follows:

  • setting: Setting to use for preprocessing and class specific settings (kwargs arguments). if no <value> is specified, the value for this setting is set to None.
  • featureClass: Feature class to enable, <value> is list of strings representing enabled features. If no <value> is specified or <value> is an empty list (‘[]’), all features for this class are enabled.
  • inputImage: input image to calculate features on. <value> is custom kwarg settings (dictionary). if <value> is an empty dictionary (‘{}’), no custom settings are added for this input image.

If supplied params file does not match the requirements, a pykwalify error is raised.

enableAllInputImages()[source]

Enable all possible input images without any custom settings.

disableAllInputImages()[source]

Disable all input images.

enableInputImageByName(inputImage, enabled=True, customArgs=None)[source]

Enable or disable specified input image. If enabling input image, optional custom settings can be specified in customArgs.

Current possible filters are:

  • original: No filter applied
  • wavelet: Wavelet filtering, yields 8 decompositions per level (all possible combinations of applying either a High or a Low pass filter in each of the three dimensions.
  • log: Laplacian of Gaussian filter, edge enhancement filter. Emphasizes areas of gray level change, where sigma defines how coarse the emphasised texture should be. A low sigma emphasis on fine textures (change over a short distance), where a high sigma value emphasises coarse textures (gray level change over a large distance)
  • square: Takes the square of the image intensities and linearly scales them back to the original range. Negative values in the original image will be made negative again after application of filter.
  • squareroot: Takes the square root of the absolute image intensities and scales them back to original range. Negative values in the original image will be made negative again after application of filter.
  • logarithm: Takes the logarithm of the absolute intensity + 1. Values are scaled to original range and negative original values are made negative again after application of filter.
  • exponential: Takes the the exponential, where filtered intensity is e^(absolute intensity). Values are scaled to original range and negative original values are made negative again after application of filter.

For the mathmetical formulas of square, squareroot, logarithm and exponential, see their respective functions in imageoperations (applySquare(), applySquareRoot(), applyLogarithm() and applyExponential(), respectively).

enableInputImages(**inputImages)[source]

Enable input images, with optionally custom settings, which are applied to the respective input image. Settings specified here override those in kwargs. The following settings are not customizable:

  • interpolator
  • resampledPixelSpacing
  • padDistance

Updates current settings: If necessary, enables input image. Always overrides custom settings specified for input images passed in inputImages. To disable input images, use enableInputImageByName or disableAllInputImages instead.

Parameters:inputImages – dictionary, key is imagetype (original, wavelet or log) and value is custom settings (dictionary)
enableAllFeatures()[source]

Enable all classes and all features.

disableAllFeatures()[source]

Disable all classes.

enableFeatureClassByName(featureClass, enabled=True)[source]

Enable or disable all features in given class.

enableFeaturesByName(**enabledFeatures)[source]

Specify which features to enable. Key is feature class name, value is a list of enabled feature names.

To enable all features for a class, provide the class name with an empty list or None as value. Settings for feature classes specified in enabledFeatures.keys are updated, settings for feature classes not yet present in enabledFeatures.keys are added. To disable the entire class, use disableAllFeatures or enableFeatureClassByName instead.

execute(imageFilepath, maskFilepath, label=None)[source]

Compute radiomics signature for provide image and mask combination. First, image and mask are loaded and resampled if necessary. Next shape features are calculated on a cropped (no padding) version of the original image. Then other featureclasses are calculated on using all specified filters in inputImages. Images are cropped to tumor mask (no padding) after application of filter and before being passed to the feature class. Finally, a dictionary containing all calculated features is returned.

Parameters:
  • imageFilepath – SimpleITK Image, or string pointing to image file location
  • maskFilepath – SimpleITK Image, or string pointing to labelmap file location
  • label – Integer, value of the label for which to extract features. If not specified, last specified label is used. Default label is 1.
Returns:

dictionary containing calculated signature (“<filter>_<featureClass>_<featureName>”:value).

loadImage(ImageFilePath, MaskFilePath)[source]

Preprocess the image and labelmap. If ImageFilePath is a string, it is loaded as SimpleITK Image and assigned to image, if it already is a SimpleITK Image, it is just assigned to image. All other cases are ignored (nothing calculated). Equal approach is used for assignment of mask using MaskFilePath.

If resampling is enabled, both image and mask are resampled and cropped to the tumormask (with additional padding as specified in padDistance) after assignment of image and mask.

getProvenance(imageFilepath, maskFilepath, mask)[source]

Generates provenance information for reproducibility. Takes the original image & mask filepath, as well as the resampled mask which is passed to the feature classes. Returns a dictionary with keynames coded as “general_info_<item>”. For more information on generated items, see generalinfo

computeFeatures(image, mask, inputImageName, **kwargs)[source]

Compute signature using image, mask, **kwargs settings This function computes the signature for just the passed image (original or filtered), does not preprocess or apply a filter to the passed image. Features / Classes to use for calculation of signature are defined in self.enabledFeatures. see also enableFeaturesByName.

generate_original(image, mask, **kwargs)[source]

No filter is applied.

Returns:Yields original image, mask, ‘original’ and kwargs
generate_log(image, mask, **kwargs)[source]

Apply Laplacian of Gaussian filter to input image and compute signature for each filtered image.

Following settings are possible:

  • sigma: List of floats or integers, must be greater than 0. Sigma values to use for the filter (determines coarseness).

N.B. Setting for sigma must be provided. If omitted, no LoG image features are calculated and the function will return an empty dictionary.

Returned filter name reflects LoG settings: log-sigma-<sigmaValue>-3D-<featureName>.

Returns:Yields log filtered image, mask, filter name and kwargs
generate_wavelet(image, mask, **kwargs)[source]

Apply wavelet filter to image and compute signature for each filtered image.

Following settings are possible:

  • start_level [0]: integer, 0 based level of wavelet which should be used as first set of decompositions from which a signature is calculated
  • level [1]: integer, number of levels of wavelet decompositions from which a signature is calculated.
  • wavelet [“coif1”]: string, type of wavelet decomposition. Enumerated value, validated against possible values present in the pyWavelet.wavelist(). Current possible values (pywavelet version 0.4.0) (where an aditional number is needed, range of values is indicated in []):
    • haar
    • dmey
    • sym[2-20]
    • db[1-20]
    • coif[1-5]
    • bior[1.1, 1.3, 1.5, 2.2, 2.4, 2.6, 2.8, 3.1, 3.3, 3.5, 3.7, 3.9, 4.4, 5.5, 6.8]
    • rbio[1.1, 1.3, 1.5, 2.2, 2.4, 2.6, 2.8, 3.1, 3.3, 3.5, 3.7, 3.9, 4.4, 5.5, 6.8]

Returned filter name reflects wavelet type: wavelet[level]-<decompositionName>-<featureName>

N.B. only levels greater than the first level are entered into the name.

Returns:Yields wavelet filtered image, mask, filter name and kwargs
generate_square(image, mask, **kwargs)[source]

Computes the square of the image intensities.

Resulting values are rescaled on the range of the initial original image.

Returns:Yields square filtered image, mask, ‘square’ and kwargs
generate_squareroot(image, mask, **kwargs)[source]

Computes the square root of the absolute value of image intensities.

Resulting values are rescaled on the range of the initial original image and negative intensities are made negative in resultant filtered image.

Returns:Yields square root filtered image, mask, ‘squareroot’ and kwargs
generate_logarithm(image, mask, **kwargs)[source]

Computes the logarithm of the absolute value of the original image + 1.

Resulting values are rescaled on the range of the initial original image and negative intensities are made negative in resultant filtered image.

Returns:Yields logarithm filtered image, mask, ‘logarithm’ and kwargs
generate_exponential(image, mask, **kwargs)[source]

Computes the exponential of the original image.

Resulting values are rescaled on the range of the initial original image.

Returns:Yields exponential filtered image, mask, ‘exponential’ and kwargs
getInputImageTypes()[source]

Returns a list of possible input image types.

classmethod getFeatureClasses()[source]

Iterates over all modules of the radiomics package using pkgutil and subsequently imports those modules.

Return a dictionary of all modules containing featureClasses, with modulename as key, abstract class object of the featureClass as value. Assumes only one featureClass per module

This is achieved by inspect.getmembers. Modules are added if it contains a memeber that is a class, with name starting with ‘Radiomics’ and is inherited from radiomics.base.RadiomicsFeaturesBase.

getFeatureClassNames()[source]
getFeatureNames(featureClassName)[source]

Returns a list of all possible features in provided featureClass

radiomics.generalinfo module

class radiomics.generalinfo.GeneralInfo(imagePath, maskPath, resampledMask, kwargs, inputImages)[source]
execute()[source]

Calculate and return a dictionary containing all general info items. Format is <info_item>:<value>, where any ‘,’ in <value> are replaced by ‘;’ to prevent column alignment errors in csv formatted output.

getBoundingBoxValue()[source]

Calculate and return the boundingbox extracted using the specified label. Elements 0, 1 and 2 are the x, y and z coordinates of the lower bound, respectively. Elements 3, 4 and 5 are the size of the bounding box in x, y and z direction, respectively.

Values are based on the resampledMask.

getGeneralSettingsValue()[source]

Return a string representation of the settings contained in kwargs. Format is {<settings_name>:<value>, ...}.

getImageHashValue()[source]

Returns the sha1 hash of the image. This enables checking whether two images are the same, regardless of the file location.

If the reading of the image fails, an empty string is returned.

getImageSpacingValue()[source]

Returns the original spacing of the image.

If the reading of the image fails, an empty string is returned.

getInputImagesValue()[source]

Return a string representation of the enabled filters and any custom settings for the filter. Format is {<filter_name>:{<setting_name>:<value>, ...}, ...}.

getMaskHashValue()[source]

Returns the sha1 hash of the mask. This enables checking whether two masks are the same, regardless of the file location.

If the reading of the mask fails, an empty string is returned. Uses the original mask, specified in maskPath.

getVersionValue()[source]

Return the current version of this package.

getVolumeNumValue()[source]

Calculate and return the number of zones within the mask for the specified label. A zone is defined as a group of connected neighbours that are segmented with the specified label, and a voxel is considered a neighbour using 26-connectedness for 3D and 8-connectedness for 2D.

Values are based on the resampledMask.

getVoxelNumValue()[source]

Calculate and return the number of voxels that have been segmented using the specified label.

Values are based on the resampledMask.

radiomics.firstorder module

class radiomics.firstorder.RadiomicsFirstOrder(inputImage, inputMask, **kwargs)[source]

Bases: radiomics.base.RadiomicsFeaturesBase

First-order statistics describe the distribution of voxel intensities within the image region defined by the mask through commonly used and basic metrics.

Let:

\(\textbf{X}\) denote the three dimensional image matrix with \(N\) voxels

\(\textbf{P}(i)\) the first order histogram with \(N_l\) discrete intensity levels, where \(l\) is defined by the number of levels is calculated based on the binWidth parameter of the constructor.

\(p(i)\) be the normalized first order histogram and equal to \(\frac{\textbf{P}(i)}{\sum{\textbf{P}(i)}}\)

Following addiotional settings are possible:

  • voxelArrayShift [2000]: This amount is added to the gray level intensity in Energy, Total Energy and RMS, this is to prevent negative values from occuring when using CT data.
getEnergyFeatureValue()[source]

Calculate the Energy of the image array.

\(energy = \displaystyle\sum^{N}_{i=1}{\textbf{X}(i)^2}\)

Energy is a measure of the magnitude of voxel values in an image. A larger values implies a greater sum of the squares of these values.

getTotalEnergyFeatureValue()[source]

Calculate the Total Energy of the image array.

\(total\ energy = V_{voxel}\displaystyle\sum^{N}_{i=1}{\textbf{X}(i)^2}\)

Total Energy is the value of Energy feature scaled by the volume of the voxel in cubic mm.

getEntropyFeatureValue()[source]

Calculate the Entropy of the image array.

\(entropy = -\displaystyle\sum^{N_l}_{i=1}{p(i)\log_2\big(p(i)+\epsilon\big)}\)

Entropy specifies the uncertainty/randomness in the image values. It measures the average amount of information required to encode the image values.

getMinimumFeatureValue()[source]

Calculate the Minimum Value in the image array.

get10PercentileFeatureValue()[source]

Calculate the 10th percentile in the image array.

get90PercentileFeatureValue()[source]

Calculate the 90th percentile in the image array.

getMaximumFeatureValue()[source]

Calculate the Maximum Value in the image array.

getMeanFeatureValue()[source]

Calculate the Mean Value for the image array.

\(mean = \frac{1}{N}\displaystyle\sum^{N}_{i=1}{\textbf{X}(i)}\)

getMedianFeatureValue()[source]

Calculate the Median Value for the image array.

getInterquartileRangeFeatureValue()[source]

Calculate the interquartile range of the image array.

\(interquartile\ range = \textbf{P}_{75} - \textbf{P}_{25}\), where \(\textbf{P}_{25}\) and \(\textbf{P}_{75}\) are the 25th and 75th percentile of the image array, respectively.

getRangeFeatureValue()[source]

Calculate the Range of Values in the image array.

\(range = \max(\textbf{X}) - \min(\textbf{X})\)

getMeanAbsoluteDeviationFeatureValue()[source]

Calculate the Mean Absolute Deviation for the image array.

\(mean\ absolute\ deviation = \frac{1}{N}\displaystyle\sum^{N}_{i=1}{|\textbf{X}(i)-\bar{X}|}\)

Mean Absolute Deviation is the mean distance of all intensity values from the Mean Value of the image array.

getRobustMeanAbsoluteDeviationFeatureValue()[source]

Calculate the Robust Mean Absolute Deviation for the image array.

\(robust\ mean\ absolute\ deviation = \frac{1}{N_{10-90}}\displaystyle\sum^{N_{10-90}}_{i=1}{|\textbf{X}_{10-90}(i)-\bar{X}_{10-90}|}\)

Robust Mean Absolute Deviation is the mean distance of all intensity values from the Mean Value calculated on the subset of image array with gray levels in between, or equal to the 10th and 90th percentile.

getRootMeanSquaredFeatureValue()[source]

Calculate the Root Mean Squared of the image array.

\(RMS = \sqrt{\frac{1}{N}\sum^{N}_{i=1}{\textbf{X}(i)^2}}\)

RMS is the square-root of the mean of all the squared intensity values. It is another measure of the magnitude of the image values.

getStandardDeviationFeatureValue()[source]

Calculate the Standard Deviation of the image array.

\(standard\ deviation = \sqrt{\frac{1}{N}\sum^{N}_{i=1}{(\textbf{X}(i)-\bar{X})^2}}\)

Standard Deviation measures the amount of variation or dispersion from the Mean Value.

getSkewnessFeatureValue(axis=0)[source]

Calculate the Skewness of the image array.

\(skewness = \displaystyle\frac{\mu_3}{\sigma^3} = \frac{\frac{1}{N}\sum^{N}_{i=1}{(\textbf{X}(i)-\bar{X})^3}} {\left(\sqrt{\frac{1}{N}\sum^{N}_{i=1}{(\textbf{X}(i)-\bar{X})^2}}\right)^3}\)

Where \(\mu_3\) is the 3rd central moment.

Skewness measures the asymmetry of the distribution of values about the Mean value. Depending on where the tail is elongated and the mass of the distribution is concentrated, this value can be positive or negative.

Related links:

https://en.wikipedia.org/wiki/Skewness

getKurtosisFeatureValue(axis=0)[source]

Calculate the Kurtosis of the image array.

\(kurtosis = \displaystyle\frac{\mu_4}{\sigma^4} = \frac{\frac{1}{N}\sum^{N}_{i=1}{(\textbf{X}(i)-\bar{X})^4}} {\left(\frac{1}{N}\sum^{N}_{i=1}{(\textbf{X}(i)-\bar{X}})^2\right)^2}\)

Where \(\mu_4\) is the 4th central moment.

Kurtosis is a measure of the ‘peakedness’ of the distribution of values in the image ROI. A higher kurtosis implies that the mass of the distribution is concentrated towards the tail(s) rather than towards the mean. A lower kurtosis implies the reverse: that the mass of the distribution is concentrated towards a spike near the Mean value.

Related links:

https://en.wikipedia.org/wiki/Kurtosis

getVarianceFeatureValue()[source]

Calculate the Variance in the image array.

\(variance = \sigma^2 = \frac{1}{N}\displaystyle\sum^{N}_{i=1}{(\textbf{X}(i)-\bar{X})^2}\)

Variance is the the mean of the squared distances of each intensity value from the Mean value. This is a measure of the spread of the distribution about the mean.

getUniformityFeatureValue()[source]

Calculate the Uniformity of the image array.

\(uniformity = \displaystyle\sum^{N_l}_{i=1}{p(i)^2}\)

Uniformity is a measure of the sum of the squares of each intensity value. This is a measure of the heterogeneity of the image array, where a greater uniformity implies a greater heterogeneity or a greater range of discrete intensity values.

radiomics.glcm module

class radiomics.glcm.RadiomicsGLCM(inputImage, inputMask, **kwargs)[source]

Bases: radiomics.base.RadiomicsFeaturesBase

A Gray Level Co-occurrence Matrix (GLCM) of size \(N_g \times N_g\) describes the second-order joint probability function of an image region constrained by the mask and is defined as \(\textbf{P}(i,j|\delta,\alpha)\). The \((i,j)\)th element of this matrix represents the number of times the combination of levels \(i\) and \(j\) occur in two pixels in the image, that are separated by a distance of \(\delta\) pixels in direction \(\alpha\), and \(N_g\) is the number of discrete gray level intensities. The distance \(\delta\) from the center voxel is defined as the distance according to the infinity norm. For \(\delta=1\), this assumes 26-connectivity in 3D and for \(\delta=2\) a 98-connectivity.

Note that pyradiomics by default computes symmetrical GLCM!

As a two dimensional example, let the following matrix \(\textbf{I}\) represent a 5x5 image, having 5 discrete grey levels:

\[\begin{split}\textbf{I} = \begin{bmatrix} 1 & 2 & 5 & 2 & 3\\ 3 & 2 & 1 & 3 & 1\\ 1 & 3 & 5 & 5 & 2\\ 1 & 1 & 1 & 1 & 2\\ 1 & 2 & 4 & 3 & 5 \end{bmatrix}\end{split}\]

For distance \(\delta = 1\) (considering pixels with a distance of 1 pixel from each other) in directions \(\alpha=0^\circ\) and opposite \(\alpha=180^\circ\) (i.e., to the left and right from the pixel with the given value), the following symmetrical GLCM is obtained:

\[\begin{split}\textbf{P} = \begin{bmatrix} 6 & 4 & 3 & 0 & 0\\ 4 & 0 & 2 & 1 & 3\\ 3 & 2 & 0 & 1 & 2\\ 0 & 1 & 1 & 0 & 0\\ 0 & 3 & 2 & 0 & 2 \end{bmatrix}\end{split}\]

Let:

\(\textbf{P}(i,j)\) be the co-occurence matrix for an arbitrary \(\delta\) and \(\alpha\)

\(p(i,j)\) be the normalized co-occurence matrix and equal to \(\frac{\textbf{P}(i,j)}{\sum{\textbf{P}(i,j)}}\)

\(N_g\) be the number of discrete intensity levels in the image

\(p_x(i) = \sum^{N_g}_{j=1}{P(i,j)}\) be the marginal row probabilities

\(p_y(j) = \sum^{N_g}_{i=1}{P(i,j)}\) be the marginal column probabilities

\(\mu_x\) be the mean gray level intensity of \(p_x\) and defined as \(\mu_x = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{p(i,j)i}\)

\(\mu_y\) be the mean gray level intensity of \(p_y\) and defined as \(\mu_x = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{p(i,j)j}\)

\(\sigma_x\) be the standard deviation of \(p_x\)

\(\sigma_y\) be the standard deviation of \(p_y\)

\(p_{x+y}(k) = \sum^{N_g}_{i=1}\sum^{N_g}_{j=1}{p(i,j)},\text{ where }i+j=k,\text{ and }k=2,3,\dots,2N_g\)

\(p_{x-y}(k) = \sum^{N_g}_{i=1}\sum^{N_g}_{j=1}{p(i,j)},\text{ where }|i-j|=k,\text{ and }k=0,1,\dots,N_g-1\)

\(HX = -\sum^{N_g}_{i=1}{p_x(i)\log_2\big(p_x(i)+\epsilon\big)}\) be the entropy of \(p_x\)

\(HY = -\sum^{N_g}_{j=1}{p_y(j)\log_2\big(p_y(j)+\epsilon\big)}\) be the entropy of \(p_y\)

\(HXY = -\sum^{N_g}_{i=1}\sum^{N_g}_{j=1}{p(i,j)\log_2\big(p(i,j)+\epsilon\big)}\) be the entropy of \(p(i,j)\)

\(HXY1 = -\sum^{N_g}_{i=1}\sum^{N_g}_{j=1}{p(i,j)\log_2\big(p_x(i)p_y(j)+\epsilon\big)}\)

\(HXY2 = -\sum^{N_g}_{i=1}\sum^{N_g}_{j=1}{p_x(i)p_y(j)\log_2\big(p_x(i)p_y(j)+\epsilon\big)}\)

By default, the value of a feature is calculated on the GLCM for each angle separately, after which the mean of these values is returned. If distance weighting is enabled, GLCM matrices are weighted by weighting factor W and then summed and normalised. Features are then calculated on the resultant matrix. Weighting factor W is calculated for the distance between neighbouring voxels by:

\(W = e^{-\|d\|^2}\), where d is the distance for the associated angle according to the norm specified in setting ‘weightingNorm’.

The following class specific settings are possible:

  • symmetricalGLCM [True]: boolean, indicates whether co-occurrences should be assessed in two directions per angle, which results in a symmetrical matrix, with equal distributions for \(i\) and \(j\).

  • weightingNorm [None]: string, indicates which norm should be used when applying distance weighting. Enumerated setting, possible values:

    • ‘manhattan’: first order norm
    • ‘euclidean’: second order norm
    • ‘infinity’: infinity norm.
    • ‘no_weighting’: GLCMs are weighted by factor 1 and summed
    • None: Applies no weighting, mean of values calculated on separate matrices is returned.

    In case of other values, an warning is logged and GLCMs are all weighted by factor 1 and summed.

References

getAutocorrelationFeatureValue()[source]

Using the i and j arrays, calculate and return the mean Autocorrelation.

\(autocorrelation = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{p(i,j)ij}\)

Autocorrelation is a measure of the magnitude of the fineness and coarseness of texture.

getAverageIntensityFeatureValue()[source]

Return the mean gray level intensity of the \(i\) distribution.

\(\mu_x = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{p(i,j)i}\)

N.B. As this formula represents the average of the distribution of \(i\), it is independent from the distribution of \(j\). Therefore, only use this formula if the GLCM is symmetrical, where both distrubutions are equal.

getClusterProminenceFeatureValue()[source]

Using coefficients i, j, ux, uy, calculate and return the mean Cluster Prominence.

\(cluster\ prominence = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{\big( i+j-\mu_x(i)-\mu_y(j)\big)^4p(i,j)}\)

Cluster Prominence is a measure of the skewness and asymmetry of the GLCM. A higher values implies more asymmetry about the mean while a lower value indicates a peak near the mean value and less variation about the mean.

getClusterShadeFeatureValue()[source]

Using coefficients i, j, ux, uy, calculate and return the mean Cluster Shade.

\(cluster\ shade = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{\big(i+j-\mu_x(i)-\mu_y(j)\big)^3p(i,j)}\)

Cluster Shade is a measure of the skewness and uniformity of the GLCM. A higher cluster shade implies greater asymmetry about the mean.

getClusterTendencyFeatureValue()[source]

Using coefficients i, j, ux, uy, calculate and return the mean Cluster Tendency.

\(cluster\ prominence = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{\big(i+j-\mu_x(i)-\mu_y(j)\big)^2p(i,j)}\)

Cluster Tendency is a measure of groupings of voxels with similar gray-level values.

getContrastFeatureValue()[source]

Using coefficients i, j, calculate and return the mean Contrast.

\(contrast = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{(i-j)^2p(i,j)}\)

Contrast is a measure of the local intensity variation, favoring \(P(i,j)\) values away from the diagonal \((i = j)\). A larger value correlates with a greater disparity in intensity values among neighboring voxels.

getCorrelationFeatureValue()[source]

Using coefficients i, j, ux, uy, sigx, sigy, calculate and return the mean Correlation.

\(correlation = \frac{\sum^{N_g}_{i=1}\sum^{N_g}_{j=1}{p(i,j)ij-\mu_x(i)\mu_y(j)}}{\sigma_x(i)\sigma_y(j)}\)

Correlation is a value between 0 (uncorrelated) and 1 (perfectly correlated) showing the linear dependency of gray level values to their respective voxels in the GLCM.

getDifferenceAverageFeatureValue()[source]

Using coefficients pxMiny, kValuesDiff, calculate and return the mean Difference Average.

\(Difference\ average = \displaystyle\sum^{N_g-1}_{k=0}{k\textbf{P}_{x-y}(k)}\)

Difference Average measures the relationship between occurrences of pairs with similar intensity values and occurrences of pairs with differing intensity values.

getDifferenceEntropyFeatureValue()[source]

Using coefficients pxSuby, eps, calculate and return the mean Difference Entropy.

\(difference\ entropy = \displaystyle\sum^{N_g-1}_{k=0}{p_{x-y}(k)\log_2\big(p_{x-y}(k)\big)}\)

Difference Entropy is a measure of the randomness/variability in neighborhood intensity value differences.

getDifferenceVarianceFeatureValue()[source]

Using coefficients pxSuby, kValuesDiff, DifferenceAverage calculate and return the mean Difference Variance.

\(Difference\ variance = \displaystyle\sum^{N_g-1}_{k=0}{(1-DA)^2\textbf{P}_{x-y}(k)}\)

Difference Variance is a measure of heterogeneity that places higher weights on differing intensity level pairs that deviate more from the mean.

getDissimilarityFeatureValue()[source]

Using coefficients i, j, calculate and return the mean Dissimilarity.

\(dissimilarity = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{|i-j|p(i,j)}\)

Dissimilarity is a measure of local intensity variation. A larger value correlates with a greater disparity in intensity values among neighboring voxels.

getEnergyFeatureValue()[source]

Using P_glcm, calculate and return the mean Energy.

\(energy = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{\big(p(i,j)\big)^2}\)

Energy (or Angular Second Moment)is a measure of homogeneous patterns in the image. A greater Energy implies that there are more instances of intensity value pairs in the image that neighbor each other at higher frequencies.

getEntropyFeatureValue()[source]

Using coefficients eps, calculate and return the mean Entropy.

\(entropy = -\displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{p(i,j)\log_2\big(p(i,j)+\epsilon\big)}\)

Entropy is a measure of the randomness/variability in neighborhood intensity values.

getHomogeneity1FeatureValue()[source]

Using coefficients i, j, calculate and return the mean Homogeneity 1.

\(homogeneity\ 1 = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{\frac{p(i,j)}{1+|i-j|}}\)

Homogeneity 1 is a measure of the similarity in intensity values for neighboring voxels. It is a measure of local homogeneity that increases with less contrast in the window.

getHomogeneity2FeatureValue()[source]

Using coefficients i, j, calculate and return the mean Homogeneity 2.

\(homogeneity\ 2 = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{\frac{p(i,j)}{1+|i-j|^2}}\)

Homogeneity 2 is a measure of the similarity in intensity values for neighboring voxels.

getImc1FeatureValue()[source]

Using coefficients HX, HY, HXY, HXY1, calculate and return the mean Informal Measure of Correlation 1.

\(IMC\ 1 = \frac{HXY-HXY1}{\max\{HX,HY\}}\)

getImc2FeatureValue()[source]

Using coefficients HXY, HXY2, calculate and return the mean Informal Measure of Correlation 2.

\(IMC\ 2 = \sqrt{1-e^{-2(HXY2-HXY)}}\)

getIdmFeatureValue()[source]

Using coefficients i, j, calculate and return the mean Inverse Difference Moment.

\(IDM = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{ \frac{\textbf{P}(i,j)}{1+|i-j|^2} }\)

IDM (inverse difference moment) is a measure of the local homogeneity of an image. IDM weights are the inverse of the Contrast weights (decreasing exponentially from the diagonal i=j in the GLCM).

getIdmnFeatureValue()[source]

Using coefficients i, j, Ng, calculate and return the mean Inverse Difference Moment Normalized.

\(IDMN = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{ \frac{p(i,j)}{1+\left(\frac{|i-j|^2}{N_g^2}\right)} }\)

IDMN (inverse difference moment normalized) is a measure of the local homogeneity of an image. IDMN weights are the inverse of the Contrast weights (decreasing exponentially from the diagonal \(i=j\) in the GLCM). Unlike Homogeneity2, IDMN normalizes the square of the difference between neighboring intensity values by dividing over the square of the total number of discrete intensity values.

getIdFeatureValue()[source]

Using coefficients i, j, Ng, calculate and return the mean Inverse Difference.

\(ID = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{ \frac{\textbf{P}(i,j)}{1+|i-j|} }\)

ID (inverse difference) is another measure of the local homogeneity of an image. With more uniform gray levels, the denominator will remain low, resulting in a higher overall value.

getIdnFeatureValue()[source]

Using coefficients i, j, Ng, calculate and return the mean Inverse Difference Normalized.

\(IDN = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{ \frac{p(i,j)}{1+\left(\frac{|i-j|}{N_g}\right)} }\)

IDN (inverse difference normalized) is another measure of the local homogeneity of an image. Unlike Homogeneity1, IDN normalizes the difference between the neighboring intensity values by dividing over the total number of discrete intensity values.

getInverseVarianceFeatureValue()[source]

Using the i, j coeffients, calculate and return the mean Inverse Variance.

\(inverse\ variance = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{\frac{p(i,j)}{|i-j|^2}}, i \neq j\)

getMaximumProbabilityFeatureValue()[source]

Using P_glcm, calculate and return the mean Maximum Probability.

\(maximum\ probability = \max\big(p(i,j)\big)\)

Maximum Probability is occurrences of the most predominant pair of neighboring intensity values.

getSumAverageFeatureValue()[source]

Using coefficients pxAddy, kValuesSum, calculate and return the mean Sum Average.

\(sum\ average = \displaystyle\sum^{2N_g}_{k=2}{p_{x+y}(k)k}\)

Sum Average measures the relationship between occurrences of pairs with lower intensity values and occurrences of pairs with higher intensity values.

getSumEntropyFeatureValue()[source]

Using coefficients pxAddy, eps, calculate and return the mean Sum Entropy.

\(sum\ entropy = \displaystyle\sum^{2N_g}_{k=2}{p_{x+y}(k)\log_2\big(p_{x+y}(k)+\epsilon\big)}\)

Sum Entropy is a sum of neighborhood intensity value differences.

getSumVarianceFeatureValue()[source]

Using coefficients pxAddy, kValuesSum, SumEntropy calculate and return the mean Sum Variance.

\(sum\ variance = \displaystyle\sum^{2N_g}_{k=2}{(k-SE)^2p_{x+y}(k)}\)

Sum Variance is a measure of heterogeneity that places higher weights on neighboring intensity level pairs that deviate more from the mean.

getSumVariance2FeatureValue()[source]

Using coefficients pxAddy, kValuesSum, SumAvarage calculate and return the mean Sum Variance.

\(sum\ variance\ 2 = \displaystyle\sum^{2N_g}_{k=2}{(k-SA)^2p_{x+y}(k)}\)

Sum Variance is a measure of heterogeneity that places higher weights on neighboring intensity level pairs that deviate more from the mean.

This formula differs from SumVariance in that instead of subtracting the SumEntropy from the intensity, it subtracts the SumAvarage, which is the mean of intensities and not its entropy

getSumSquaresFeatureValue()[source]

Using coefficients i and ux, calculate and return the mean Sum of Squares (also known as Variance).

\(sum\ squares = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_g}_{j=1}{(i-\mu_x)^2p(i,j)}\)

Sum of Squares or Variance is a measure in the distribution of neigboring intensity level pairs about the mean intensity level in the GLCM.

N.B. This formula represents the variance of the distribution of \(i\) and is independent from the distribution of \(j\). Therefore, only use this formula if the GLCM is symmetrical, where VAR(i) to be equal to VAR(j).

radiomics.glszm module

class radiomics.glszm.RadiomicsGLSZM(inputImage, inputMask, **kwargs)[source]

Bases: radiomics.base.RadiomicsFeaturesBase

A Gray Level Size Zone (GLSZM) quantifies gray level zones in an image. A gray level zone is defined as a the number of connected voxels that share the same gray level intensity. A voxel is considered connected if the distance is 1 according to the infinity norm. This yields a 26-connected region in a 3D image, and an 8-connected region in a 2D image. In a gray level size zone matrix \(P(i,j)\) the \((i,j)\)th element describes the number of times a gray level zone with gray level \(i\) and size \(j\) appears in image.

As a two dimensional example, consider the following 5x5 image, with 5 discrete gray levels:

\[\begin{split}\textbf{I} = \begin{bmatrix} 5 & 2 & 5 & 4 & 4\\ 3 & 3 & 3 & 1 & 3\\ 2 & 1 & 1 & 1 & 3\\ 4 & 2 & 2 & 2 & 3\\ 3 & 5 & 3 & 3 & 2 \end{bmatrix}\end{split}\]

The GLSZM then becomes:

\[\begin{split}\textbf{P} = \begin{bmatrix} 0 & 0 & 0 & 1 & 0\\ 1 & 0 & 0 & 0 & 1\\ 1 & 0 & 1 & 0 & 1\\ 1 & 1 & 0 & 0 & 0\\ 3 & 0 & 0 & 0 & 0 \end{bmatrix}\end{split}\]

Let:

\(\textbf{P}(i,j)\) be the size zone matrix

\(p(i,j)\) be the normalized size zone matrix, defined as \(p(i,j) = \frac{\textbf{P}(i,j)}{\sum{\textbf{P}(i,j)}}\)

\(N_g\) be the number of discreet intensity values in the image

\(N_s\) be the number of discreet zone sizes in the image

\(N_p\) be the number of voxels in the image

getSmallAreaEmphasisFeatureValue()[source]

Calculate and return the Small Area Emphasis (SAE) value.

\(SAE = \frac{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\frac{\textbf{P}(i,j)}{j^2}}}{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)}}\)

A measure of the distribution of small size zones, with a greater value indicative of more smaller size zones and more fine textures.

getLargeAreaEmphasisFeatureValue()[source]

Calculate and return the Large Area Emphasis (LAE) value.

\(LAE = \frac{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)j^2}}{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)}}\)

A measure of the distribution of large area size zones, with a greater value indicative of more larger size zones and more coarse textures.

getIntensityVariabilityFeatureValue()[source]

Calculate and return the Intensity Variability (IV) value.

\(IV = \frac{\sum^{N_g}_{i=1}\left(\sum^{N_s}_{j=1}{\textbf{P}(i,j)}\right)^2}{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)}}\)

Measures the variability of gray-level intensity values in the image, with a lower value indicating more homogeneity in intensity values.

getIntensityVariabilityNormalizedFeatureValue()[source]

Calculate and return the Intensity Variability Normalized (IVN) value.

\(IVN = \frac{\sum^{N_g}_{i=1}\left(\sum^{N_s}_{j=1}{\textbf{P}(i,j)}\right)^2}{\sum^{N_g}_{i=1}\sum^{N_d}_{j=1}{\textbf{P}(i,j)}^2}\)

Measures the variability of gray-level intensity values in the image, with a lower value indicating a greater similarity in intensity values. This is the normalized version of the IV formula.

getSizeZoneVariabilityFeatureValue()[source]

Calculate and return the Size-Zone Variability (SZV) value.

\(SZV = \frac{\sum^{N_s}_{j=1}\left(\sum^{N_g}_{i=1}{\textbf{P}(i,j)}\right)^2}{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)}}\)

Measures the variability of size zone volumes in the image, with a lower value indicating more homogeneity in size zone volumes.

getSizeZoneVariabilityNormalizedFeatureValue()[source]

Calculate and return the Size-Zone Variability Normalized (SZVN) value.

\(SZVN = \frac{\sum^{N_s}_{j=1}\left(\sum^{N_g}_{i=1}{\textbf{P}(i,j)}\right)^2}{\sum^{N_g}_{i=1}\sum^{N_d}_{j=1}{\textbf{P}(i,j)}^2}\)

Measures the variability of size zone volumes throughout the image, with a lower value indicating more homogeneity among zone size volumes in the image. This is the normalized version of the SZVN formula.

getZonePercentageFeatureValue()[source]

Calculate and return the Zone Percentage (ZP) value.

\(ZP = \sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\frac{\textbf{P}(i,j)}{N_p}}\)

Measures the homogeneity of the distribution of zone size volumes in an image among the observed gray-levels.

getGrayLevelVarianceFeatureValue()[source]

Calculate and return the Gray Level Variance (GLV) value.

\(GLV = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_s}_{j=1}{p(i,j)(i - \mu)^2}\), where

\(\mu = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_s}_{j=1}{p(i,j)i}\)

Measures the variance in gray level intensities for the zones.

getZoneVarianceFeatureValue()[source]

Calculate and return the Zone Variance (ZV) value.

\(ZV = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_s}_{j=1}{p(i,j)(j - \mu)^2}\), where

\(\mu = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_s}_{j=1}{p(i,j)j}\)

Measures the variance in zone size volumes for the zones.

getZoneEntropyFeatureValue()[source]

Calculate and return the Zone Entropy (ZE) value.

\(ZE = -\displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_s}_{j=1}{p(i,j)\log_{2}(p(i,j)+\epsilon)}\)

getLowIntensityEmphasisFeatureValue()[source]

Calculate and return the Low Intensity Emphasis (LIE) value.

\(LIE = \frac{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\frac{\textbf{P}(i,j)}{i^2}}}{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)}}\)

Measures the distribution of lower gray-level size zones, with a higher value indicating a greater proportion of lower gray-level values and size zones in the image.

getHighIntensityEmphasisFeatureValue()[source]

Calculate and return the High Intensity Emphasis (HIE) value.

\(HIE = \frac{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)i^2}}{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)}}\)

Measures the distribution of the higher gray-level values, with a higher value indicating a greater proportion of higher gray-level values and size zones in the image.

getLowIntensitySmallAreaEmphasisFeatureValue()[source]

Calculate and return the Low Intensity Small Area Emphases (LISAE) value.

\(LISAE = \frac{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\frac{\textbf{P}(i,j)}{i^2j^2}}}{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)}}\)

Measures the proportion in the image of the joint distribution of smaller size zones with lower gray-level values.

getHighIntensitySmallAreaEmphasisFeatureValue()[source]

Calculate and return the High Intensity Small Area Emphases (HISAE) value.

\(HISAE = \frac{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\frac{\textbf{P}(i,j)i^2}{j^2}}}{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)}}\)

Measures the proportion in the image of the joint distribution of smaller size zones with higher gray-level values.

getLowIntensityLargeAreaEmphasisFeatureValue()[source]

Calculate and return the Low Intensity Large Area Emphases (LILAE) value.

\(LILAE = \frac{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\frac{\textbf{P}(i,j)j^2}{i^2}}}{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)}}\)

Measures the proportion in the image of the joint distribution of larger size zones with lower gray-level values.

getHighIntensityLargeAreaEmphasisFeatureValue()[source]

Calculate and return the High Intensity Large Area Emphases (HILAE) value.

\(HILAE = \frac{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)i^2j^2}}{\sum^{N_g}_{i=1}\sum^{N_s}_{j=1}{\textbf{P}(i,j)}}\)

Measures the proportion in the image of the joint distribution of larger size zones with higher gray-level values.

radiomics.glrlm module

class radiomics.glrlm.RadiomicsGLRLM(inputImage, inputMask, **kwargs)[source]

Bases: radiomics.base.RadiomicsFeaturesBase

A Gray Level Run Length Matrix (GLRLM) quantifies gray level runs in an image. A gray level run is defined as the length in number of pixels, of consecutive pixels that have the same gray level value. In a gray level run length matrix \(\textbf{P}(i,j|\theta)\), the \((i,j)\)th element describes the number of times a gray level \(i\) appears consecutively \(j\) times in the direction specified by \(\theta\).

As a two dimensional example, consider the following 5x5 image, with 5 discrete gray levels:

\[\begin{split}\textbf{I} = \begin{bmatrix} 5 & 2 & 5 & 4 & 4\\ 3 & 3 & 3 & 1 & 3\\ 2 & 1 & 1 & 1 & 3\\ 4 & 2 & 2 & 2 & 3\\ 3 & 5 & 3 & 3 & 2 \end{bmatrix}\end{split}\]

The GLRLM for \(\theta = 0\), where 0 degrees is the horizontal direction, then becomes:

\[\begin{split}\textbf{P} = \begin{bmatrix} 1 & 0 & 1 & 0 & 0\\ 3 & 0 & 1 & 0 & 0\\ 4 & 1 & 1 & 0 & 0\\ 1 & 1 & 0 & 0 & 0\\ 3 & 0 & 0 & 0 & 0 \end{bmatrix}\end{split}\]

Let:

\(\textbf{P}(i,j|\theta)\) be the run length matrix for an arbitrary direction \(\theta\)

\(p(i,j|\theta)\) be the normalized run length matrix, defined as \(p(i,j|\theta) = \frac{\textbf{P}(i,j|\theta)}{\sum{\textbf{P}(i,j|\theta)}}\)

\(N_g\) be the number of discreet intensity values in the image

\(N_r\) be the number of discreet run lengths in the image

\(N_p\) be the number of voxels in the image

By default, the value of a feature is calculated on the GLRLM for each angle separately, after which the mean of these values is returned. If distance weighting is enabled, GLRLMs are weighted by the distance between neighbouring voxels and then summed and normalised. Features are then calculated on the resultant matrix. The distance between neighbouring voxels is calculated for each angle using the norm specified in ‘weightingNorm’.

The following class specific settings are possible:

  • weightingNorm [None]: string, indicates which norm should be used when applying distance weighting. Enumerated setting, possible values:

    • ‘manhattan’: first order norm
    • ‘euclidean’: second order norm
    • ‘infinity’: infinity norm.
    • ‘no_weighting’: GLCMs are weighted by factor 1 and summed
    • None: Applies no weighting, mean of values calculated on separate matrices is returned.

    In case of other values, an warning is logged and GLCMs are all weighted by factor 1 and summed.

References

  • Galloway MM. 1975. Texture analysis using gray level run lengths. Computer Graphics and Image Processing 4:172-179.
  • Tang X. 1998. Texture information in run-length matrices. IEEE Transactions on Image Processing 7(11):1602-1609.
getShortRunEmphasisFeatureValue()[source]

Calculate and return the mean Short Run Emphasis (SRE) value for all GLRLMs.

\(SRE = \frac{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\frac{\textbf{P}(i,j|\theta)}{i^2}}}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}}\)

A measure of the distribution of short run lengths, with a greater value indicative of shorter run lengths and more fine textural textures.

getLongRunEmphasisFeatureValue()[source]

Calculate and return the mean Long Run Emphasis (LRE) value for all GLRLMs.

\(LRE = \frac{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)j^2}}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}}\)

A measure of the distribution of long run lengths, with a greater value indicative of longer run lengths and more coarse structural textures.

getGrayLevelNonUniformityFeatureValue()[source]

Calculate and return the mean Gray Level Non-Uniformity (GLN) value for all GLRLMs.

\(GLN = \frac{\sum^{N_g}_{i=1}\left(\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}\right)^2}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}}\)

Measures the similarity of gray-level intensity values in the image, where a lower GLN value correlates with a greater similarity in intensity values.

getGrayLevelNonUniformityNormalizedFeatureValue()[source]

Calculate and return the Gray Level Non-Uniformity Normalized (GLNN) value.

\(GLNN = \frac{\sum^{N_g}_{i=1}\left(\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}\right)^2}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}^2}\)

Measures the similarity of gray-level intensity values in the image, where a lower GLNN value correlates with a greater similarity in intensity values. This is the normalized version of the GLN formula.

getRunLengthNonUniformityFeatureValue()[source]

Calculate and return the mean Run Length Non-Uniformity (RLN) value for all GLRLMs.

\(RLN = \frac{\sum^{N_r}_{j=1}\left(\sum^{N_g}_{i=1}{\textbf{P}(i,j|\theta)}\right)^2}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}}\)

Measures the similarity of run lengths throughout the image, with a lower value indicating more homogeneity among run lengths in the image.

getRunLengthNonUniformityNormalizedFeatureValue()[source]

Calculate and return the mean Run Length Non-Uniformity Normalized (RLNN) value for all GLRLMs.

\(RLNN = \frac{\sum^{N_r}_{j=1}\left(\sum^{N_g}_{i=1}{\textbf{P}(i,j|\theta)}\right)^2}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}}\)

Measures the similarity of run lengths throughout the image, with a lower value indicating more homogeneity among run lengths in the image. This is the normalized version of the RLN formula.

getRunPercentageFeatureValue()[source]

Calculate and return the mean Run Percentage (RP) value for all GLRLMs.

\(RP = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_r}_{j=1}{\frac{\textbf{P}(i,j|\theta)}{N_p}}\)

Measures the homogeneity and distribution of runs of an image.

getGrayLevelVarianceFeatureValue()[source]

Calculate and return the Gray Level Variance (GLV) value.

\(GLV = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_r}_{j=1}{p(i,j|\theta)(i - \mu)^2}\), where

\(\mu = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_r}_{j=1}{p(i,j|\theta)i}\)

Measures the variance in gray level intensity for the runs.

getRunVarianceFeatureValue()[source]

Calculate and return the Run Variance (RV) value.

\(RV = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_r}_{j=1}{p(i,j|\theta)(j - \mu)^2}\), where

\(\mu = \displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_r}_{j=1}{p(i,j|\theta)j}\)

Measures the variance in runs for the run lengths.

getRunEntropyFeatureValue()[source]

1 Calculate and return the Run Entropy (RE) value.

\(RE = -\displaystyle\sum^{N_g}_{i=1}\displaystyle\sum^{N_r}_{j=1}{p(i,j|\theta)\log_{2}(p(i,j|\theta)+\epsilon)}\)

getLowGrayLevelRunEmphasisFeatureValue()[source]

Calculate and return the mean Low Gray Level Run Emphasis (LGLRE) value for all GLRLMs.

\(LGLRE = \frac{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\frac{\textbf{P}(i,j|\theta)}{i^2}}}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}}\)

Measures the distribution of low gray-level values, with a higher value indicating a greater concentration of low gray-level values in the image.

getHighGrayLevelRunEmphasisFeatureValue()[source]

Calculate and return the mean High Gray Level Run Emphasis (HGLRE) value for all GLRLMs.

\(HGLRE = \frac{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)i^2}}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}}\)

Measures the distribution of the higher gray-level values, with a higher value indicating a greater concentration of high gray-level values in the image.

getShortRunLowGrayLevelEmphasisFeatureValue()[source]

Calculate and return the mean Short Run Low Gray Level Emphasis (SRLGLE) value for all GLRLMs.

\(SRLGLE = \frac{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\frac{\textbf{P}(i,j|\theta)}{i^2j^2}}}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}}\)

Measures the joint distribution of shorter run lengths with lower gray-level values.

getShortRunHighGrayLevelEmphasisFeatureValue()[source]

Calculate and return the mean Short Run High Gray Level Emphasis (SRHGLE) value for all GLRLMs.

\(SRHGLE = \frac{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\frac{\textbf{P}(i,j|\theta)i^2}{j^2}}}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}}\)

Measures the joint distribution of shorter run lengths with higher gray-level values.

getLongRunLowGrayLevelEmphasisFeatureValue()[source]

Calculate and return the mean Long Run Low Gray Level Emphasis (LRLGLE) value for all GLRLMs.

\(LRLGLRE = \frac{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\frac{\textbf{P}(i,j|\theta)j^2}{i^2}}}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}}\)

Measures the joint distribution of long run lengths with lower gray-level values.

getLongRunHighGrayLevelEmphasisFeatureValue()[source]

Calculate and return the mean Long Run High Gray Level Emphasis (LRHGLE) value for all GLRLMs.

\(LRHGLRE = \frac{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)i^2j^2}}{\sum^{N_g}_{i=1}\sum^{N_r}_{j=1}{\textbf{P}(i,j|\theta)}}\)

Measures the joint distribution of long run lengths with higher gray-level values.

radiomics.shape module

class radiomics.shape.RadiomicsShape(inputImage, inputMask, **kwargs)[source]

Bases: radiomics.base.RadiomicsFeaturesBase

In this group of features we included descriptors of the three-dimensional size and shape of the tumor region. Let in the following definitions denote \(V\) the volume and \(A\) the surface area of the volume of interest.

getVolumeFeatureValue()[source]

Calculate the volume of the tumor region in cubic millimeters.

getSurfaceAreaFeatureValue()[source]

Calculate the surface area of the tumor region in square millimeters.

\(A = \displaystyle\sum^{N}_{i=1}{\frac{1}{2}|\textbf{a}_i\textbf{b}_i \times \textbf{a}_i\textbf{c}_i|}\)

Where:

\(N\) is the number of triangles forming the surface of the volume

\(a_ib_i\) and \(a_ic_i\) are the edges of the \(i\)th triangle formed by points \(a_i\), \(b_i\) and \(c_i\)

getSurfaceVolumeRatioFeatureValue()[source]

Calculate the surface area to volume ratio of the tumor region

\(surface\ to\ volume\ ratio = \frac{A}{V}\)

getCompactness1FeatureValue()[source]

Calculate the compactness (1) of the tumor region.

\(compactness\ 1 = \frac{V}{\sqrt{\pi}A^{\frac{2}{3}}}\)

Compactness 1 is a measure of how compact the shape of the tumor is relative to a sphere (most compact). It is a dimensionless measure, independent of scale and orientation. Compactness 1 is defined as the ratio of volume to the \(\sqrt{\text{surface area}^3}\). This is a measure of the compactness of the shape of the image ROI

getCompactness2FeatureValue()[source]

Calculate the Compactness (2) of the tumor region.

\(compactness\ 2 = 36\pi\frac{V^2}{A^3}\)

Compactness 2 is a measure of how compact the shape of the tumor is relative to a sphere (most compact). It is a dimensionless measure, independent of scale and orientation. This is a measure of the compactness of the shape of the image ROI.

getMaximum3DDiameterFeatureValue()[source]

Calculate the largest pairwise euclidean distance between tumor surface voxels. Also known as Feret Diameter.

getMaximum2DDiameterSliceFeatureValue()[source]

Calculate the largest pairwise euclidean distance between tumor surface voxels in the row-column plane.

getMaximum2DDiameterColumnFeatureValue()[source]

Calculate the largest pairwise euclidean distance between tumor surface voxels in the row-slice plane.

getMaximum2DDiameterRowFeatureValue()[source]

Calculate the largest pairwise euclidean distance between tumor surface voxels in the column-slice plane.

getSphericalDisproportionFeatureValue()[source]

Calculate the Spherical Disproportion of the tumor region.

\(spherical\ disproportion = \frac{A}{4\pi R^2}\)

Where \(R\) is the radius of a sphere with the same volume as the tumor.

Spherical Disproportion is the ratio of the surface area of the tumor region to the surface area of a sphere with the same volume as the tumor region.

getSphericityFeatureValue()[source]

Calculate the Sphericity of the tumor region.

\(sphericity = \frac{\pi^{\frac{1}{3}}(6V)^{\frac{2}{3}}}{A}\)

Sphericity is a measure of the roundness of the shape of the tumor region relative to a sphere. This is another measure of the compactness of a tumor.

getElongationFeatureValue()[source]
getFlatnessFeatureValue()[source]
getRoundnessFeatureValue()[source]

radiomics.imageoperations module

radiomics.imageoperations.getHistogram(binwidth, parameterValues)[source]
radiomics.imageoperations.binImage(binwidth, parameterMatrix, parameterMatrixCoordinates)[source]
radiomics.imageoperations.generateAngles(size, maxDistance=1)[source]

Generate all possible angles from distance 1 until maxDistance in 3D. E.g. for d = 1, 13 angles are generated (representing the 26-connected region). For d = 2, 13 + 49 = 62 angles are generated (representing the 26 connected region for distance 1, and the 98 connected region for distance 2)

Impossible angles (where ‘neighbouring’ voxels will always be outside delineation) are deleted.

Parameters:
  • size – dimensions (z, x, y) of the bounding box of the tumor mask.
  • maxDistance – [1] Maximum distance between center voxel and neighbour
Returns:

numpy array with shape (N, 3), where N is the number of unique angles

radiomics.imageoperations.cropToTumorMask(imageNode, maskNode, label=1, boundingBox=None)[source]

Create a sitkImage of the segmented region of the image based on the input label.

Create a sitkImage of the labelled region of the image, cropped to have a cuboid shape equal to the ijk boundaries of the label.

Returns both the cropped version of the image and the cropped version of the labelmap, as well as the computed bounding box. The bounding box is returned as a tuple of indices: (L_x, U_x, L_y, U_y, L_z, U_z), where ‘L’ and ‘U’ are lower and upper bound, respectively, and ‘x’, ‘y’ and ‘z’ the three image dimensions.

This can be used in subsequent calls to this function for the same images. This improves computation time, as it will reduce the number of calls to SimpleITK.LabelStatisticsImageFilter().

Parameters:
  • label – [1], value of the label, onto which the image and mask must be cropped.
  • boundingBox – [None], during a subsequent call, the boundingBox of a previous call can be passed here, removing the need to recompute it. During a first call to this function for a image/mask with a certain label, this value must be None or omitted.
Returns:

Cropped image and mask (SimpleITK image instances) and the bounding box generated by SimpleITK LabelStatisticsImageFilter.

radiomics.imageoperations.resampleImage(imageNode, maskNode, resampledPixelSpacing, interpolator=3, label=1, padDistance=5)[source]

Resamples image or label to the specified pixel spacing (The default interpolator is Bspline)

‘imageNode’ is a SimpleITK Object, and ‘resampledPixelSpacing’ is the output pixel spacing. Enumerator references for interpolator: 0 - sitkNearestNeighbor 1 - sitkLinear 2 - sitkBSpline 3 - sitkGaussian

radiomics.imageoperations.applyLoG(inputImage, sigmaValue=0.5)[source]
radiomics.imageoperations.applyThreshold(inputImage, lowerThreshold, upperThreshold, insideValue=None, outsideValue=0)[source]
radiomics.imageoperations.swt3(inputImage, wavelet='coif1', level=1, start_level=0)[source]
radiomics.imageoperations.applySquare(inputImage)[source]

Computes the square of the image intensities.

Resulting values are rescaled on the range of the initial original image and negative intensities are made negative in resultant filtered image.

\(x_f = (cx_i)^2,\text{ where } c=\displaystyle\frac{1}{\sqrt{\max(x_i)}}\)

Where \(x_i\) and \(x_f\) are the original and filtered intensity, respectively.

radiomics.imageoperations.applySquareRoot(inputImage)[source]

Computes the square root of the absolute value of image intensities.

Resulting values are rescaled on the range of the initial original image and negative intensities are made negative in resultant filtered image.

\(x_f = \left\{ {\begin{array}{lcl} \sqrt{cx_i} & \mbox{for} & x_i \ge 0 \\ -\sqrt{-cx_i} & \mbox{for} & x_i < 0\end{array}} \right.,\text{ where } c=\max(x_i)\)

Where \(x_i\) and \(x_f\) are the original and filtered intensity, respectively.

radiomics.imageoperations.applyLogarithm(inputImage)[source]

Computes the logarithm of the absolute value of the original image + 1.

Resulting values are rescaled on the range of the initial original image and negative intensities are made negative in resultant filtered image.

\(x_f = \left\{ {\begin{array}{lcl} c\log{(x_i + 1)} & \mbox{for} & x_i \ge 0 \\ -c\log{(-x_i + 1)} & \mbox{for} & x_i < 0\end{array}} \right.,\text{ where } c=\displaystyle\frac{\max(x_i)}{\max(x_f)}\)

Where \(x_i\) and \(x_f\) are the original and filtered intensity, respectively.

radiomics.imageoperations.applyExponential(inputImage)[source]

Computes the exponential of the original image.

Resulting values are rescaled on the range of the initial original image.

\(x_f = e^{cx_i},\text{ where } c=\displaystyle\frac{\log(\max(x_i))}{\max(x_i)}\)

Where \(x_i\) and \(x_f\) are the original and filtered intensity, respectively.

Module contents

radiomics.debug(debug_on=True)[source]

Set up logging system for the whole package. By default, module hierarchy is reflected in log, as child loggers are created by module This is achieved by the following line in base.py: self.logger = logging.getLogger(self.__module__) To use same instance in each module, set self.logger=logging.getLogger('radiomics').

At command line, turn on debugging for all pyradiomics functions with:

import radiomics

radiomics.debug()

Turn off debugging with:

radiomics.debug(False)