Closed abhinandanbatra closed 5 years ago
sitk::ERROR: The file "C06920110818Image.nii" does not exist.
This indicates that the file does not exist. The error is due to the fact that you list files in path
, but then try to load just the file name. use sitk.ReadImage(os.path.join(path, files))
instead
Thank you so much for the help. I am able to locate the Cases and loop through them. I am running into another issue. When I run the analysis by looping through Cases I am getting the following error
"ValueError: Image/Mask datatype or size mismatch. Potential fix: enable correct mask, see Documentation:Usage:Customizing the Extraction:Settings:correctMask for more information"
But when I run each Case separately I am able to get the results. Here is the code I am using for looping through cases based on your suggestion earlier
for Case_id in range(1,6): path = '/Users/abhinandanbatra/Desktop/pyradiomics/Converted/Case{}/'.format(Case_id) print(path) for image in os.listdir(path): if fnmatch.fnmatch(image,'*Image.nii'): print(image) image=sitk.ReadImage(os.path.join(path,image)) for mask in os.listdir(path): if fnmatch.fnmatch(mask,'*label.nii'): print(mask) mask=sitk.ReadImage(os.path.join(path,mask)) result = extractor.execute(image, mask) print('Result type:', type(result)) # result is returned in a Python ordered dictionary) print('') print('Calculated features for Case {}:'.format(Case_id)) for key, value in six.iteritems(result): print('\t', key, ':', value)
I would appreciate your help
@abhinandanbatra The error you are seeing should also happen for the case separately. It indicates there is a difference in size/direction/origin (i.e. geometry) of the image and mask. This does could indicate that the wrong mask is used, but is also the case when the mask represents a cropped area of the image (3D slicer does this to preserve space).
PyRadiomics can handle this, you only need to specify correctMask: True
in the configuration.
On a side note, PyRadiomics does support parallel processing of a batch of cases, where you can provide the settings in a handy yaml-structured config-file (see examples and documentation of config file and command line usage)
Yes, you are right, one case had that an issue. I am really sorry but I am running into another issue when I loop through cases I get the result for the first case but when it loops through the second I get the error
ValueError: Error reading image Filepath or SimpleITK object
I am using the same code as I sent you earlier. Sorry I am new to python
@abhinandanbatra No problem. The most likely cause for that particular error is that it can't find the image file or the format is wrong. What happens if you try to load it using 3d Slicer (or a similar program)?
To be precise: PyRadiomics first checks if image is a string (representing a path), and if so, loads it as an sitk image. If not, it checks if it's an SimpleITK image, and uses it if so. If not, the error you're seeing is shown.
If you are new to python, the commandline interface may be easier to use. It only requires you to build a CSV file as input, and contains error handling and optimalization steps.
I don't get the error when I run the case separately or load them in 3d slicer. I only get the above error when I am looping through the cases. Here is the whole error, you can see the code was able to analyze the first case but gave an error when looping through the second
/Users/abhinandanbatra/Desktop/pyradiomics/Converted/Case1/ C60620120618Image.nii C60620120618label.nii Result type: <class 'collections.OrderedDict'>
ValueError Traceback (most recent call last)
Also, can you please let me know the code for the corrected mask to set it to True. here is what I came up with based on command line and your examples `settings = {} print(settings) settings['binWidth'] = 25 settings['resampledPixelSpacing'] = None
settings['interpolator'] = 'sitkBSpline' settings['correctMask'] = True
interpolator = settings.get('interpolator') resampledPixelSpacing = settings.get('resampledPixelSpacing') extractor = featureextractor.RadiomicsFeaturesExtractor() extractor.disableAllFeatures() extractor.enableFeatureClassByName('firstorder') extractor.getFeatureNames('firstorder') print('Enabled features:\n\t', extractor._enabledFeatures)
print('Active features:') for cls, features in six.iteritems(extractor._enabledFeatures): if len(features) == 0: features = [f for f, deprecated in six.iteritems(extractor.getFeatureNames(cls)) if not deprecated] for f in features: print(f) `
Unfortunately, I still run into that issue maybe I am writing the code wrong :).
Sorry for bugging you so much
extractor = featureextractor.RadiomicsFeaturesExtractor()
should be
extractor = featureextractor.RadiomicsFeaturesExtractor(**settings)
I.e. you need to pass the settings in order for the extractor to use them. the **
means they are unpacked as keyword arguments (i.e. extractor = featureextractor.RadiomicsFeaturesExtractor(correctMask=True)
would also work (only setting correct mask is applied here, rest is default of course)
what is printed out if you add print(type(image))
just before result = extractor.execute(image, mask)
This is the part of feature extractor that loads your image and is raising an error in your case:
if isinstance(ImageFilePath, six.string_types) and os.path.isfile(ImageFilePath):
image = sitk.ReadImage(ImageFilePath)
elif isinstance(ImageFilePath, sitk.SimpleITK.Image):
image = ImageFilePath
else:
raise ValueError('Error reading image Filepath or SimpleITK object')
Thank you so much. I really appreciate it. It's working now. One of the .nii files was corrupt (as it did not convert properly from dicom to nifti) so it was creating an issue. Also, can you suggest any tool for converting dicom to nifti.
I am really thankful for all your help on this
@abhinandanbatra I myself use a python script I put together. Aside from that, checkout this issue: #383.
Hi, I am having an issue reading multiple files by looping over different cases in pyradiomics. I am using following code
for Case_id in range(1,6): path = '/Users/abhinandanbatra/Desktop/pyradiomics/Converted/Case{}/'.format(Case_id) for files in os.listdir(path): if fnmatch.fnmatch(files,'*Image.nii'): print(files) image= sitk.ReadImage(files) for mask in os.listdir(path): if fnmatch.fnmatch(mask,'*lable.nii'): print(mask) mask=sitk.ReadImage(mask) features[case_id] = extractor.execute(image, mask)
I am getting following error:
RuntimeError Traceback (most recent call last)