featureVector = extractor.execute(image, mask) returns a blank feature dict for 2D images

629 views
Skip to first unread message

SK

unread,
Oct 5, 2018, 8:08:02 PM10/5/18
to pyradiomics
Hi, 

I am testing out feature extraction for 2D slice images. I followed suggestions in this link: https://github.com/Radiomics/pyradiomics/issues/339 to make the 2D slice compatible with pyradiomics. Plus I followed the example notebooks to ensure that I was calling the extractor correctly. 

I have attached my python notebook on what I have. Here is the snippet of the code which is causing problems: 

# Instantiate extractor
# extractor = featureextractor.RadiomicsFeaturesExtractor(paramPath)  # optional supply parameter file)
extractor = featureextractor.RadiomicsFeaturesExtractor()  # Default settings 

extractor.disableAllFeatures()
extractor.disableAllImageTypes()

extractor.enableAllFeatures()
extractor.enableImageTypeByName('Original',enabled=True)

print('Extraction Parameters:\n\t', extractor.settings)
print(f'Enabled Filters: \n\t {extractor._enabledImagetypes}')
print(f'Enable Features: \n\t {extractor._enabledFeatures}')
print('--'*30)
print("Calculating features")
featureVector = extractor.execute(im, ma)

for featureName in featureVector.keys():
  print("Computed %s: %s" % (featureName, featureVector[featureName]))


When I try to extract all the features for the original image after pre-processing the 2D image, the dictionary is empty. However when I call each of the feature extractors separately on the original image, it runs fine and I get outputs. 

Eventually I want to be able to enable all the image types (i.e. those which are 2D capable) and run the features on all of them. I could do them individually per feature type but I am hoping to make the above option work. 

Any suggestions on how to get this to work. 

Regards, 
Kashyap 

extract_2D_image_features.html

SK

unread,
Oct 8, 2018, 12:14:36 AM10/8/18
to pyradiomics
Hi Folks,

It turns out the mask was of type double and that's why the all features were not being computed. Using the sitk cast image filter solved it. Here is the snippet of code which I modified.
# Build full mask
im_arr = sitk.GetArrayFromImage(im)
print(im_arr.shape)
ma_arr
= np.ones(im_arr.shape)
ma
= sitk.GetImageFromArray(ma_arr)
ma
.CopyInformation(im)

im
= sitk.Cast(im, sitk.sitkFloat32)
ma
= sitk.Cast(ma, sitk.sitkInt64 )



extractor
= featureextractor.RadiomicsFeaturesExtractor()  # Default settings

# Enable just first order
extractor.disableAllFeatures()
extractor
.disableAllImageTypes()

extractor
.enableAllFeatures()
extractor
.enableImageTypeByName('Original',enabled=True)

print('--'*30)
print("Calculating features")
featureVector
= extractor.execute(im, ma)

Thanks,
Kashyap

Joost van Griethuysen

unread,
Oct 8, 2018, 4:06:19 AM10/8/18
to pyradiomics
Dear SK,

This was a known bug and has since been corrected in the current master branch of PyRadiomics (PR #431), though it is not yet part of the latest release.
Additionally, when the preprocessing fails, a ValueError is now raised (instead of returning the empty feature vector). This change has been made in PR 420 and is part of the 2.1 release.

Kind regards,

Joost

Op maandag 8 oktober 2018 06:14:36 UTC+2 schreef SK:

SK

unread,
Oct 8, 2018, 12:22:57 PM10/8/18
to pyradiomics
Hi Joost,

Thanks for the reply. Good to know.

Regards,
Kashyap
Reply all
Reply to author
Forward
0 new messages