Skip to content

Commit

Permalink
DOCS: Update documentation in base.py
Browse files Browse the repository at this point in the history
Clarify that variables mentioned in the base class are variables instantiated by the base class, not possible settings for customization (also add redirect to customization documentation).

Update the documentation to reflect changes made to the structure of the base class, more specifically the initialization of a feature class.

Add documentation for the "Label" parameter to the customization documentation.
  • Loading branch information
JoostJM committed Oct 6, 2017
1 parent f268b92 commit 0acccfe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
4 changes: 3 additions & 1 deletion docs/customization.rst
Expand Up @@ -131,7 +131,7 @@ Feature Extractor Level
- resampledPixelSpacing [None]: List of 3 floats (>= 0), sets the size of the voxel in (x, y, z) plane when resampling.
A value of 0 is replaced with the spacing for that dimension as it is in the original (non-resampled) mask, thereby
enabling only in-plane resampling, for example.
- interpolator [sitkBSpline]: Simple ITK constant or string name thereof, sets interpolator to use for resampling.
- interpolator [sitkBSpline]: SimpleITK constant or string name thereof, sets interpolator to use for resampling.
Enumerated value, possible values:

- sitkNearestNeighbor (= 1)
Expand Down Expand Up @@ -216,6 +216,8 @@ Filter Level
Feature Class Level
+++++++++++++++++++

- Label [1]: Integer, label value of Region of Interest (ROI) in labelmap.

*Image discretization*

- binWidth [25]: Float, > 0, size of the bins when making a histogram and for discretization of the image gray level.
Expand Down
52 changes: 36 additions & 16 deletions radiomics/base.py
Expand Up @@ -8,6 +8,7 @@

from radiomics import getProgressReporter, imageoperations


class RadiomicsFeaturesBase(object):
"""
This is the abstract class, which defines the common interface for the feature classes. All feature classes inherit
Expand All @@ -19,23 +20,42 @@ class RadiomicsFeaturesBase(object):
initialization fails and a warning is logged (does not raise an error).
Logging is set up using a child logger from the parent 'radiomics' logger. This retains the toolbox structure in
the generated log.
the generated log. The child logger is named after the module containing the feature class (e.g. 'radiomics.glcm').
Any pre calculations needed before the feature functions are called can be added by overriding the
``_initSegmentBasedCalculation`` function, which prepares the input for feature extraction. If image discretization is
needed, this can be implemented by adding a call to ``_applyBinning`` to this initialization function, which also
instantiates coefficients holding the maximum ('Ng') and unique ('GrayLevels') that can be found inside the ROI after
binning. This function also instantiates the `matrix` variable, which holds the discretized image (the `imageArray`
variable will hold only original gray levels).
The following variables are instantiated at initialization:
- kwargs: dictionary holding all customized settings passed to this feature class.
- binWidth: bin width, as specified in ``**kwargs``. If key is not present, a default value of 25 is used.
- label: label value of Region of Interest (ROI) in labelmap. If key is not present, a default value of 1 is used.
- verbose: boolean indication whether or not to provide progress reporting to the output.
- featureNames: list containing the names of features defined in the feature class. See :py:func:`getFeatureNames`
- inputImage: Simple ITK image object of the input image
- inputMask: Simple ITK image object of the input labelmap
- imageArray: numpy array of the gray values in the input image
- maskArray: numpy array with elements set to 1 where labelmap = label, 0 otherwise
- matrix: numpy array of the gray values in the input image (with gray values inside ROI discretized when necessary in
the texture feature classes).
- matrixCoordinates: tuple of 3 numpy arrays containing the z, x and y coordinates of the voxels included in the ROI,
respectively. Length of each array is equal to total number of voxels inside ROI.
- targetVoxelArray: flattened numpy array of gray values inside ROI.
- inputImage: SimpleITK image object of the input image (dimensions x, y, z)
The following variables are instantiated by the ``_initSegmentBasedCalculation`` function:
- inputMask: SimpleITK image object of the input labelmap (dimensions x, y, z)
- imageArray: numpy array of the gray values in the input image (dimensions z, y, x)
- maskArray: numpy boolean array with elements set to ``True`` where labelmap = label, ``False`` otherwise,
(dimensions z, y, x).
- labelledVoxelCoordinates: tuple of 3 numpy arrays containing the z, x and y coordinates of the voxels included in
the ROI, respectively. Length of each array is equal to total number of voxels inside ROI.
- boundingBoxSize: tuple of 3 integers containing the z, x and y sizes of the ROI bounding box, respectively.
- matrix: copy of the imageArray variable, with gray values inside ROI discretized using the specified binWidth.
This variable is only instantiated if a call to ``_applyBinning`` is added to an override of
``_initSegmentBasedCalculation`` in the feature class.
.. note::
Although some variables listed here have similar names to customization settings, they do *not* represent all the
possible settings on the feature class level. These variables are listed here to help developers develop new feature
classes, which make use of these variables. For more information on customization, see
:ref:`radiomics-customization-label`, which includes a comprehensive list of all possible settings, including
default values and explanation of usage.
"""

def __init__(self, inputImage, inputMask, **kwargs):
Expand Down Expand Up @@ -69,11 +89,11 @@ def _initSegmentBasedCalculation(self):
self.boundingBoxSize = numpy.max(self.labelledVoxelCoordinates, 1) - numpy.min(self.labelledVoxelCoordinates, 1) + 1

def _applyBinning(self):
self.matrix, self.binEdges = imageoperations.binImage(self.binWidth,
self.imageArray,
self.maskArray)
self.coefficients['grayLevels'] = numpy.unique(self.matrix[self.maskArray])
self.coefficients['Ng'] = int(numpy.max(self.coefficients['grayLevels'])) # max gray level in the ROI
self.matrix, self.binEdges = imageoperations.binImage(self.binWidth,
self.imageArray,
self.maskArray)
self.coefficients['grayLevels'] = numpy.unique(self.matrix[self.maskArray])
self.coefficients['Ng'] = int(numpy.max(self.coefficients['grayLevels'])) # max gray level in the ROI

def enableFeatureByName(self, featureName, enable=True):
"""
Expand Down

0 comments on commit 0acccfe

Please sign in to comment.