Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve glcm performance (voxel-based features extraction) #882

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions radiomics/glcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,14 @@ def _calculateMatrix(self, voxelCoordinates=None):
self.logger.debug('Process calculated matrix')

# Delete rows and columns that specify gray levels not present in the ROI
NgVector = range(1, Ng + 1) # All possible gray values
GrayLevels = self.coefficients['grayLevels'] # Gray values present in ROI
emptyGrayLevels = numpy.array(list(set(NgVector) - set(GrayLevels)), dtype=int) # Gray values NOT present in ROI

P_glcm = numpy.delete(P_glcm, emptyGrayLevels - 1, 1)
P_glcm = numpy.delete(P_glcm, emptyGrayLevels - 1, 2)
P_glcm = P_glcm[:, GrayLevels - 1, :, :]
P_glcm = P_glcm[:, :, GrayLevels - 1, :]

# Optionally make GLCMs symmetrical for each angle
if self.symmetricalGLCM:
self.logger.debug('Create symmetrical matrix')
# Transpose and copy GLCM and add it to P_glcm. Numpy.transpose returns a view if possible, use .copy() to ensure
# a copy of the array is used and not just a view (otherwise erroneous additions can occur)
P_glcm += numpy.transpose(P_glcm, (0, 2, 1, 3)).copy()
P_glcm = P_glcm + numpy.transpose(P_glcm, (0, 2, 1, 3))

# Optionally apply a weighting factor
if self.weightingNorm is not None:
Expand Down