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

pyradiomics and extractor.execute cannot work for Indexerror #592

Closed
lindw-hub opened this issue Jun 22, 2020 · 5 comments · Fixed by #594
Closed

pyradiomics and extractor.execute cannot work for Indexerror #592

lindw-hub opened this issue Jun 22, 2020 · 5 comments · Fixed by #594
Assignees
Labels

Comments

@lindw-hub
Copy link

Describe the bug
pyradiomics did not work for Indexerror.

PyRadiomics configuration
PyRadiomincs software was installed by runpython -m pip install pyradiomics in Mac terminal.

type in Mac terminal app:
pyradiomics brain1_image.nrrd brain1_label.nrrd
then, it stoped for Indexerror.
PyRadiomics log file

Traceback (most recent call last):
File "/Users/adm/test7/venv/lib/python3.7/site-packages/radiomics/scripts/segment.py", line 70, in _extractFeatures

feature_vector.update(extractor.execute(imageFilepath, maskFilepath, label, label_channel))

File "/Users/adm/test7/venv/lib/python3.7/site-packages/radiomics/featureextractor.py", line 327, in execute

featureVector.update(self.computeFeatures(inputImage, inputMask, imageTypeName, **inputKwargs))

File "/Users/adm/test7/venv/lib/python3.7/site-packages/radiomics/featureextractor.py", line 514, in computeFeatures

for (featureName, featureValue) in six.iteritems(featureClass.execute()):

File "/Users/adm/test7/venv/lib/python3.7/site-packages/radiomics/base.py", line 185, in execute

self._calculateSegment()

File "/Users/adm/test7/venv/lib/python3.7/site-packages/radiomics/base.py", line 222, in _calculateSegment

for success, featureName, featureValue in self._calculateFeatures():

File "/Users/adm/test7/venv/lib/python3.7/site-packages/radiomics/base.py", line 229, in _calculateFeatures

self._initCalculation(voxelCoordinates)

File "/Users/adm/test7/venv/lib/python3.7/site-packages/radiomics/glcm.py", line 111, in _initCalculation

self.P_glcm = self._calculateMatrix(voxelCoordinates)

File "/Users/adm/test7/venv/lib/python3.7/site-packages/radiomics/glcm.py", line 148, in _calculateMatrix

P_glcm = numpy.delete(P_glcm, emptyGrayLevels - 1, 1)

File "<array_function internals>", line 6, in delete

File "/Users/adm/test7/venv/lib/python3.7/site-packages/numpy/lib/function_base.py", line 4406, in delete

keep[obj,] = False

IndexError: arrays used as indices must be of integer (or boolean) type

Case-1_Image: /Users/adm/test7/pyradiomics-master/data/brain1_image.nrrd

Case-1_Mask: /Users/adm/test7/pyradiomics-master/data/brain1_label.nrrd

Version (please complete the following information):

  • OS: Mac OS 10.15.6
  • Python version: 3.7.4
  • PyRadiomics version v3.0

Additional context
when I run it on my windows, it still reported the same error.
it seemed that featureVector = extractor.execute(imageName, maskName) did not work

@lindw-hub lindw-hub added the bug label Jun 22, 2020
@JoostJM
Copy link
Collaborator

JoostJM commented Jun 22, 2020

I'll have to investigate a bit further, but it appears that the discretization does not cast to integer datatype (needed to use gray levels as indices). I thought I changed that a while back, but I can't seem to find it, so maybe it got lost. I'll try to fix this asap (quite a simple fix really). If you want to try for yourself, go to imageoperations.binImage and change line 158 (return discretizedParameterMatrix, binEdges) into (return discretizedParameterMatrix.astype('int'), binEdges

@lindw-hub
Copy link
Author

thank you a lot! it works now~

@MStarmans91
Copy link

MStarmans91 commented Jun 26, 2020

The solution you provided unfortunately does not always solve the mentioned issue. If all possible gray levels are present in the discretized image, the discretizedParameterMatrix variable in the imageoperations script, and thereby also the emptyGrayLevels variable in the glcm script, becomes an empty list. The mentioned error is than raised as well: simply changing the type will not solve the issue.

A solution could be to in the glcm script, before the P_glcm = numpy.delete(P_glcm, emptyGrayLevels - 1, 1) line, simply insert a conditional if list(emptyGrayLevels):. Note that this issue can also occur in all other gray level matrix based features, e.g. the glrlm, gldm, thus this fix would need to be implemented in all those scripts.

@JoostJM
Copy link
Collaborator

JoostJM commented Jul 2, 2020

I'll write a second update to add the additional check

@JoostJM
Copy link
Collaborator

JoostJM commented Jul 2, 2020

Addressed by #602.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants