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

[FEAT EXTRACTION] All first order values are 0 (except uniformity) #784

Closed margotridderikhoff closed 2 years ago

margotridderikhoff commented 2 years ago

Hi, I have a (very simple) question, but I can't figure it out. Hope you can help!

Describe the bug I'm trying to compute features from a masked numpy array (which I converted to a Simple ITK image and mask), but all my first order features are 0 except for uniformity (=1) and entropy (=-3.20e-16). I really don't understand what is causing this. I've followed this pyradiomics example, which loads Simple ITK images and computes the first order features. Running the example works for me, but all values are zero when I plug in my values. As example, I've a raster which I've called test_r which is a masked numpy array. I have replaced the nan values of the data by zeros, and multiplied my values (which are in the range of 20 to 28) by 1000 converted them to np.int16, since this is the same data type I got when I converted the example to an array. The mask had data type np.int32, so I also convert that one. I saw a similar issue here, but for me changing the bin width did not change the output.

PyRadiomics configuration So my code looks like this:

image_arr = np.nan_to_num(test_r.data) * 1000
image_arr = image_arr.astype(np.int16)
image = sitk.GetImageFromArray(image_arr)
mask_arr = test_r.mask.astype(np.int32)
mask = sitk.GetImageFromArray(mask_arr)

# Setting for the feature calculation.
settings = {'binWidth': 10}

# Show the first order feature calculations
firstOrderFeatures = firstorder.RadiomicsFirstOrder(image, mask, **settings)
firstOrderFeatures.enableAllFeatures()

print('Calculating first order features...')
results = firstOrderFeatures.execute()
print('done')

print('Calculated first order features: ')
for (key, val) in six.iteritems(results):
  print('  ', key, ':', val)

Version (please complete the following information):

Additional context Below I added the image and mask plots from the example and my own.

Example image & mask: Figure 2022-09-03 161314 (0) Figure 2022-09-03 161314 (3)

My image & mask: Figure 2022-09-03 161314 (1) Figure 2022-09-03 161314 (2)

I hope you can help, thank you in advance!