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 493 forks source link

Regarding urgent debugging problem of data format debugging #465

Closed shong95 closed 5 years ago

shong95 commented 5 years ago

Hello I have a inquiry regarding urgent debugging problem of data format debugging.

shong95 commented 5 years ago

Hello, I'm getting trouble regarding data format...

# Instantiate the extractor
params = os.path.join(os.getcwd(), '..', 'examples', 'exampleSettings', 'Params.yaml')

print(DC_img_1.GetSize())
print(DC_roi_1.GetSize())

# result = extractor.execute(imagePath, maskPath)
extractor = featureextractor.RadiomicsFeaturesExtractor(params)
DC_result_1 = extractor.execute(DC_img_1, DC_roi_1[2,:,:])
# PC_result_1 = extractor.execute(PC_img_1, PC_roi_1[2,:,:])`

The results of errors are like this:

(976, 1976)
(288, 432, 3)

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-57-2572afd595f0> in <module>
      7 # result = extractor.execute(imagePath, maskPath)
      8 extractor = featureextractor.RadiomicsFeaturesExtractor(params)
----> 9 DC_result_1 = extractor.execute(DC_img_1, DC_roi_1[2,:,:])
     10 # PC_result_1 = extractor.execute(PC_img_1, PC_roi_1[2,:,:])

~/anaconda3/envs/venv_py3/lib/python3.6/site-packages/radiomics/featureextractor.py in execute(self, imageFilepath, maskFilepath, label, voxelBased)
    391     # 1. Load the image and mask
    392     featureVector = collections.OrderedDict()
--> 393     image, mask = self.loadImage(imageFilepath, maskFilepath)
    394 
    395     # 2. Check whether loaded mask contains a valid ROI for feature extraction and get bounding box

~/anaconda3/envs/venv_py3/lib/python3.6/site-packages/radiomics/featureextractor.py in loadImage(self, ImageFilePath, MaskFilePath)
    507       # Do not include the image here, as the overlap between image and mask have not been checked
    508       # It is therefore possible that image and mask do not align, or even have different sizes.
--> 509       self.generalInfo.addMaskElements(None, mask, label)
    510 
    511     # This point is only reached if image and mask loaded correctly

~/anaconda3/envs/venv_py3/lib/python3.6/site-packages/radiomics/generalinfo.py in addMaskElements(self, image, mask, label, prefix)
    112     lssif.Execute(mask)
    113 
--> 114     self.generalInfo[self.generalInfo_prefix + 'Mask-' + prefix + '_BoundingBox'] = lssif.GetBoundingBox(label)
    115     self.generalInfo[self.generalInfo_prefix + 'Mask-' + prefix + '_VoxelNum'] = lssif.GetNumberOfPixels(label)
    116 

~/anaconda3/envs/venv_py3/lib/python3.6/site-packages/SimpleITK/SimpleITK.py in GetBoundingBox(self, label)
  42674 
  42675         """
> 42676         return _SimpleITK.LabelShapeStatisticsImageFilter_GetBoundingBox(self, label)
  42677 
  42678 

RuntimeError: Exception thrown in SimpleITK LabelShapeStatisticsImageFilter_GetBoundingBox: /opt/miniconda2/conda-bld/simpleitk_1520542297279/work/build/ITK-prefix/include/ITK-4.13/itkLabelMap.hxx:164:
itk::ERROR: LabelMap(0x3c367d0): No label object with label 1.`

I hope your kind advice really...

JoostJM commented 5 years ago

@shong95, as you can read from the error message No label object with label 1, your mask does not contain a segmented region with label (=value of the pixels) 1. Using the following code, you can detect the labels present in your ROI:

lssif = sitk.LabelShapeStatisticsImageFilter()
lssif.Execute(DC_roi_1)

print(lssif.GetLabels())

On a side note. Be careful with slicing on a SimpleITK image. Slicing the occurs in [x, y, z] order.

Finally, even after fixing this error, your extraction will not work, as your input image is 2D. We are currently in the process of making PyRadiomics support N-Dimensional extraction, but this is not yet done.

Checkout the google groups and the other issues on pointer how to deal with 2D input for now.