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.11k stars 485 forks source link

Feature extraction failed #789

Open helenabartels91 opened 1 year ago

helenabartels91 commented 1 year ago

I am trying to extract radiomic features in Jupyter notebook. This is my code for extraction. The images and masks are NRRD files extracted from 3D slicer.

path = (r'/Users/helen/Library/CloudStorage/OneDrive-Personal/Documents/Research/PAS Radiomics research/Radiomic feature extraction Pyradiomics') params = os.path.join(path, 'PAS.yaml')

inputCSV = os.path.join(path, 'PAS_superior_pathway_codes.csv') outputCSV = os.path.join(path, 'PAS_superior_Radiomic features.csv')

try: flists = pd.read_csv(inputCSV, sep=',').T except Exception: print('CSV READ FAILED') exit(-1)

extractor = featureextractor.RadiomicsFeatureExtractor(params)

results = pd.DataFrame()

imageFilepath = flists[entry]['Image'] maskFilepath = flists[entry]['Mask'] label = flists[entry].get('Label', None)

if str(label).isdigit(): label = int(label) else: label = None

featureVector = flists[entry]  # This is a pandas Series
featureVector['Image'] = os.path.basename(imageFilepath)
featureVector['Mask'] = os.path.basename(maskFilepath)

  result = pd.Series(extractor.execute(imageFilepath, maskFilepath, label))
  #featureVector = featureVector.append(result)
  featureVector = featureVector.concat((result), axis=0)
except Exception:
  print('FEATURE EXTRACTION FAILED:')

featureVector.name = entry
results = results.join(featureVector, how='outer')  # If feature extraction failed, results will be all NaN

results.T.to_csv(outputCSV,sep=';', index=False, na_rep='NaN')

I keep getting a message of "FEATURE EXTRACTION FAILED" Anyone see how to solve the problem?

Thank you

JoostJM commented 1 year ago

If you enable logging, PyRadiomics should output the reason why the feature extraction is failing. Try to use the commandline interface, this has the necessary code for enabling logging already there.