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.16k stars 500 forks source link

Slicer radiomics error[BUG] #690

Closed selmanca closed 3 years ago

selmanca commented 3 years ago

Describe the bug In Slicer Radiomics after choosing input volume and segmentation and pushing "Apply" button. These errors are encountered:

Initializing output table
Starting RadiomicsCLI for Segmentation_segment_LAnt
......Done
[2021-04-14 20:29:04] I: radiomics.script: Starting PyRadiomics (version: v3.0.1.post3+g0c53d1d)
[2021-04-14 20:29:04] I: radiomics.script: Processing input...
[2021-04-14 20:29:05] I: radiomics.featureextractor: Loading parameter file C:/Users/selma/AppData/Local/Temp/Slicer\RadiomicsLogicParams.json
[2021-04-14 20:29:05] I: radiomics.featureextractor: Applying custom setting overrides: {'label': 1, 'correctMask': True}
[2021-04-14 20:29:05] I: radiomics.script: Input valid, starting sequential extraction from 1 case(s)...
[2021-04-14 20:29:05] I: radiomics.script: Processing case 1
[2021-04-14 20:29:05] I: radiomics.featureextractor: Calculating features with label: 1
[2021-04-14 20:29:05] I: radiomics.featureextractor: Loading image and mask
[2021-04-14 20:29:05] E: radiomics.script: Feature extraction failed!
Traceback (most recent call last):
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\scripts\segment.py", line 70, in _extractFeatures
    feature_vector.update(extractor.execute(imageFilepath, maskFilepath, label, label_channel))
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\featureextractor.py", line 272, in execute
    image, mask = self.loadImage(imageFilepath, maskFilepath, generalInfo, **_settings)
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\featureextractor.py", line 382, in loadImage
    raise ValueError('Error reading mask Filepath or SimpleITK object')
ValueError: Error reading mask Filepath or SimpleITK object
[2021-04-14 20:29:05] I: radiomics.script: Processing results...
[2021-04-14 20:29:05] I: radiomics.script: Finished segment-based extraction successfully...

Starting RadiomicsCLI for Segmentation_segment_LPost
......Done
[2021-04-14 20:29:06] I: radiomics.script: Starting PyRadiomics (version: v3.0.1.post3+g0c53d1d)
[2021-04-14 20:29:06] I: radiomics.script: Processing input...
[2021-04-14 20:29:06] I: radiomics.featureextractor: Loading parameter file C:/Users/selma/AppData/Local/Temp/Slicer\RadiomicsLogicParams.json
[2021-04-14 20:29:06] I: radiomics.featureextractor: Applying custom setting overrides: {'label': 1, 'correctMask': True}
[2021-04-14 20:29:06] I: radiomics.script: Input valid, starting sequential extraction from 1 case(s)...
[2021-04-14 20:29:06] I: radiomics.script: Processing case 1
[2021-04-14 20:29:06] I: radiomics.featureextractor: Calculating features with label: 1
[2021-04-14 20:29:06] I: radiomics.featureextractor: Loading image and mask
[2021-04-14 20:29:06] E: radiomics.script: Feature extraction failed!
Traceback (most recent call last):
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\scripts\segment.py", line 70, in _extractFeatures
    feature_vector.update(extractor.execute(imageFilepath, maskFilepath, label, label_channel))
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\featureextractor.py", line 272, in execute
    image, mask = self.loadImage(imageFilepath, maskFilepath, generalInfo, **_settings)
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\featureextractor.py", line 382, in loadImage
    raise ValueError('Error reading mask Filepath or SimpleITK object')
ValueError: Error reading mask Filepath or SimpleITK object
[2021-04-14 20:29:06] I: radiomics.script: Processing results...
[2021-04-14 20:29:06] I: radiomics.script: Finished segment-based extraction successfully...

Starting RadiomicsCLI for Segmentation_segment_MAnt
......Done
[2021-04-14 20:29:07] I: radiomics.script: Starting PyRadiomics (version: v3.0.1.post3+g0c53d1d)
[2021-04-14 20:29:07] I: radiomics.script: Processing input...
[2021-04-14 20:29:07] I: radiomics.featureextractor: Loading parameter file C:/Users/selma/AppData/Local/Temp/Slicer\RadiomicsLogicParams.json
[2021-04-14 20:29:07] I: radiomics.featureextractor: Applying custom setting overrides: {'label': 1, 'correctMask': True}
[2021-04-14 20:29:07] I: radiomics.script: Input valid, starting sequential extraction from 1 case(s)...
[2021-04-14 20:29:07] I: radiomics.script: Processing case 1
[2021-04-14 20:29:07] I: radiomics.featureextractor: Calculating features with label: 1
[2021-04-14 20:29:07] I: radiomics.featureextractor: Loading image and mask
[2021-04-14 20:29:07] E: radiomics.script: Feature extraction failed!
Traceback (most recent call last):
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\scripts\segment.py", line 70, in _extractFeatures
    feature_vector.update(extractor.execute(imageFilepath, maskFilepath, label, label_channel))
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\featureextractor.py", line 272, in execute
    image, mask = self.loadImage(imageFilepath, maskFilepath, generalInfo, **_settings)
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\featureextractor.py", line 382, in loadImage
    raise ValueError('Error reading mask Filepath or SimpleITK object')
ValueError: Error reading mask Filepath or SimpleITK object
[2021-04-14 20:29:07] I: radiomics.script: Processing results...
[2021-04-14 20:29:07] I: radiomics.script: Finished segment-based extraction successfully...

Starting RadiomicsCLI for Segmentation_segment_MPost
......Done
[2021-04-14 20:29:08] I: radiomics.script: Starting PyRadiomics (version: v3.0.1.post3+g0c53d1d)
[2021-04-14 20:29:08] I: radiomics.script: Processing input...
[2021-04-14 20:29:08] I: radiomics.featureextractor: Loading parameter file C:/Users/selma/AppData/Local/Temp/Slicer\RadiomicsLogicParams.json
[2021-04-14 20:29:08] I: radiomics.featureextractor: Applying custom setting overrides: {'label': 1, 'correctMask': True}
[2021-04-14 20:29:08] I: radiomics.script: Input valid, starting sequential extraction from 1 case(s)...
[2021-04-14 20:29:08] I: radiomics.script: Processing case 1
[2021-04-14 20:29:08] I: radiomics.featureextractor: Calculating features with label: 1
[2021-04-14 20:29:08] I: radiomics.featureextractor: Loading image and mask
[2021-04-14 20:29:08] E: radiomics.script: Feature extraction failed!
Traceback (most recent call last):
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\scripts\segment.py", line 70, in _extractFeatures
    feature_vector.update(extractor.execute(imageFilepath, maskFilepath, label, label_channel))
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\featureextractor.py", line 272, in execute
    image, mask = self.loadImage(imageFilepath, maskFilepath, generalInfo, **_settings)
  File "C:\Users\selma\AppData\Local\NA-MIC\Slicer 4.13.0-2021-04-12\NA-MIC\Extensions-29830\SlicerRadiomics\Lib\site-packages\radiomics\featureextractor.py", line 382, in loadImage
    raise ValueError('Error reading mask Filepath or SimpleITK object')
ValueError: Error reading mask Filepath or SimpleITK object
[2021-04-14 20:29:08] I: radiomics.script: Processing results...
[2021-04-14 20:29:08] I: radiomics.script: Finished segment-based extraction successfully...

Extraction complete
Cleaning up...

PyRadiomics configuration Slicer Radiomics

Version (please complete the following information):

Thanks for the attention.

pieper commented 3 years ago

I just tried this with the MRHead sample data and a test segmentation and it worked fine on mac with the 2021-04-12 build. Is there anything unique about your data or workflow? Did it work before? Can you replicate the issue with sample data?

selmanca commented 3 years ago

I am adding screenshots. These are segmentation volume nodes and T2 map images of knee.

Screenshot_1 Screenshot_2 Screenshot_3 Screenshot_4

It still raises the "ValueError: Error reading mask Filepath or SimpleITK object"

Edit: I tried it on Chest CT volumes and it works perfectly there. But it doesn't work here. I am adding volume and segmentation.

https://drive.google.com/file/d/1XJt_negn4WeNaqC8A9L-f8wdfXAXe87V/view?usp=sharing https://drive.google.com/file/d/1f6Bh-8xSFTGInF5EL7pGDcx74tmFlIvV/view?usp=sharing

JoostJM commented 3 years ago

Can you try to convert one to a label map and try again? I recently had some issue with reading a segmentation node in slicer to simpleitk.

JoostJM commented 3 years ago

The issue is that for some reason, the sitk readable path doesn't work for segmentation

selmanca commented 3 years ago

Thank you! It works perfectly with segmentation label map.

pieper commented 3 years ago

Thanks for reporting and testing @selmanca 👍

@JoostJM do you know what's wrong with segmentations? Is it that SimpleITK doesn't understand .seg.nrrd and we need to do the conversion in SlicerRadiomics when the user picks a SegmentationNode?

fedorov commented 3 years ago

I haven't had a chance to investigate, but in the past it was working with both segmentations and labelmaps. There was a related thread somewhere where Joost discussed some fixes he did, but I don't know where it was.

JoostJM commented 3 years ago

In #688 I talked about some fixes. However, they were a bit different what is described here.

I have to investigate further, but what I know for now is that sitkUtils.GetSlicerITKReadWriteAddress() does not yield an address that is readable by SimpleITK for segmentation nodes, though it does for labelmap nodes.

pieper commented 3 years ago

sitkUtils.GetSlicerITKReadWriteAddress() does not yield an address that is readable by SimpleITK for segmentation nodes, though it does for labelmap nodes

That could be due to the way segmentation nodes support overlapping segments. When that happens there are multiple labelmaps that aren't one-to-one with an sitk image. Best long-term if we want to support overlap would be to extract the segments one-by-one and run the radiomics on each exported label. For now we might just export the labelmap and warn the user is the segments overlap (should be able to ask the segmentation node).

JoostJM commented 3 years ago

I have to investigate why it's going wrong in the extension, as I recently made an update that only forwards labelmaps to the CLI of radiomics (i.e. extracts each individual segment as a labelmap, see #688 and the link provided).

fedorov commented 3 years ago

Best long-term if we want to support overlap would be to extract the segments one-by-one and run the radiomics on each exported label.

I believe that's how I implemented it originally.

JoostJM commented 3 years ago

I believe that's how I implemented it originally.

True, though that implementation started failing, as it started to return the al segments coded with different labels instead of just the selected segment with label 1.

By the way, when Slicer stores a segmentation in .seg.nrrd, it is stored as a 4D volume, supporting overlap. SimpleITK can read that, and PyRadiomics can parse that.