AIM-Harvard / pyradiomics

Open-source python package for the extraction of Radiomics features from 2D and 3D images and binary masks. Support: https://discourse.slicer.org/c/community/radiomics
http://pyradiomics.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.14k stars 492 forks source link

Hardcoded label in shape.py #266

Closed haarburger closed 7 years ago

haarburger commented 7 years ago

If I do something like

extractor = RadiomicsFeaturesExtractor(...)
extractor.execute(image, mask, label=2)

I get the following error

Calculating features with label: 2
Loading image and mask
Applying resampling from spacing [ 0.5859375  0.5859375  3.       ] and size [512 512  33] to spacing [ 1.  1.  1.] and size [24, 29, 24]
Adding additional extraction information
Computing shape
FAILED: Traceback (most recent call last):
  File "/Applications/miniconda3/envs/lfbradiomics/lib/python3.5/site-packages/pyradiomics-1.2.0.post5+g0c0d2fd-py3.5-macosx-10.7-x86_64.egg/radiomics/base.py", line 125, in calculateFeatures
    self.featureValues[feature] = getattr(self, 'get%sFeatureValue' % feature)()
  File "/Applications/miniconda3/envs/lfbradiomics/lib/python3.5/site-packages/pyradiomics-1.2.0.post5+g0c0d2fd-py3.5-macosx-10.7-x86_64.egg/radiomics/shape.py", line 384, in getMajorAxisFeatureValue
    return numpy.sqrt(self.lssif.GetPrincipalMoments(1)[2]) * 4
  File "/Applications/miniconda3/envs/lfbradiomics/lib/python3.5/site-packages/SimpleITK/SimpleITK.py", line 42343, in GetPrincipalMoments
    return _SimpleITK.LabelShapeStatisticsImageFilter_GetPrincipalMoments(self, label)
RuntimeError: Exception thrown in SimpleITK LabelShapeStatisticsImageFilter_GetPrincipalMoments: /scratch/dashboards/SimpleITK-OSX10.6-intel-pkg/SimpleITK-build/ITK-prefix/include/ITK-4.11/itkLabelMap.hxx:164:
itk::ERROR: LabelMap(0x7faed6c9cff0): No label object with label 1.

FAILED: Traceback (most recent call last):
  File "/Applications/miniconda3/envs/lfbradiomics/lib/python3.5/site-packages/pyradiomics-1.2.0.post5+g0c0d2fd-py3.5-macosx-10.7-x86_64.egg/radiomics/base.py", line 125, in calculateFeatures
    self.featureValues[feature] = getattr(self, 'get%sFeatureValue' % feature)()
  File "/Applications/miniconda3/envs/lfbradiomics/lib/python3.5/site-packages/pyradiomics-1.2.0.post5+g0c0d2fd-py3.5-macosx-10.7-x86_64.egg/radiomics/shape.py", line 384, in getMajorAxisFeatureValue
    return numpy.sqrt(self.lssif.GetPrincipalMoments(1)[2]) * 4
  File "/Applications/miniconda3/envs/lfbradiomics/lib/python3.5/site-packages/SimpleITK/SimpleITK.py", line 42343, in GetPrincipalMoments
    return _SimpleITK.LabelShapeStatisticsImageFilter_GetPrincipalMoments(self, label)
RuntimeError: Exception thrown in SimpleITK LabelShapeStatisticsImageFilter_GetPrincipalMoments: /scratch/dashboards/SimpleITK-OSX10.6-intel-pkg/SimpleITK-build/ITK-prefix/include/ITK-4.11/itkLabelMap.hxx:164:
itk::ERROR: LabelMap(0x7faed6c9cff0): No label object with label 1.

FAILED: Traceback (most recent call last):
  File "/Applications/miniconda3/envs/lfbradiomics/lib/python3.5/site-packages/pyradiomics-1.2.0.post5+g0c0d2fd-py3.5-macosx-10.7-x86_64.egg/radiomics/base.py", line 125, in calculateFeatures
    self.featureValues[feature] = getattr(self, 'get%sFeatureValue' % feature)()
  File "/Applications/miniconda3/envs/lfbradiomics/lib/python3.5/site-packages/pyradiomics-1.2.0.post5+g0c0d2fd-py3.5-macosx-10.7-x86_64.egg/radiomics/shape.py", line 406, in getLeastAxisFeatureValue
    return numpy.sqrt(self.lssif.GetPrincipalMoments(1)[0]) * 4
  File "/Applications/miniconda3/envs/lfbradiomics/lib/python3.5/site-packages/SimpleITK/SimpleITK.py", line 42343, in GetPrincipalMoments
    return _SimpleITK.LabelShapeStatisticsImageFilter_GetPrincipalMoments(self, label)
RuntimeError: Exception thrown in SimpleITK LabelShapeStatisticsImageFilter_GetPrincipalMoments: /scratch/dashboards/SimpleITK-OSX10.6-intel-pkg/SimpleITK-build/ITK-prefix/include/ITK-4.11/itkLabelMap.hxx:164:
itk::ERROR: LabelMap(0x7faed6c9cff0): No label object with label 1.
...

For label = 1 everything works fine. The label 2 definitely exists since all other features (statistics, glcm, ...) are calculated correctly.

It seems that in in radiomics.shape.py, lssif.GetPrincipalMoments() is always called with label=1. From my understanding it should be called with self.label instead.

Update: I just created a PR

Environment: macOS 10.12.5 Python: 3.5.3 (anaconda) pyradiomics 1.2.0.post5+g0c0d2fd SimpleITK 1.0.0

JoostJM commented 7 years ago

Superseded by changes made in #264