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

[FEAT EXTRACTION] Are non- voxel-based features supposed to be the average of all voxel-based features? #811

Open ackbar03 opened 1 year ago

ackbar03 commented 1 year ago

Hi, a question regarding the relationship between voxel-based and non-voxel-based features.

I assumed that if I averaged the voxel-based features, I would get the extracted feature value without usingvoxelBased=True . However, this does not seem to be the case.

For example, if I try to get

extractor.enableFeaturesByName(firstorder=['Median'])
result = extractor.execute(imageName, maskName, voxelBased=True)
z = result['original_firstorder_Median']

msk_ref = sitk.ReadImage(maskName)
rif =sitk.ResampleImageFilter()
rif.SetReferenceImage(msk_ref)
rif.SetOutputPixelType(z.GetPixelID())
rif.SetInterpolator(sitk.sitkNearestNeighbor)
z_mskref = rif.Execute(z)

z_mskref_array = sitk.GetArrayFromImage(z_mskref)
print(z_mskref_array.shape)
# (67, 136, 135)

msk_array = sitk.GetArrayFromImage(sitk.ReadImage(maskName))
average_feat_over_msk = np.sum(z_mskref_array * msk_array) / np.sum(msk_array)

print(average_feat_over_msk)

I get 958.75 vs 951.

If I calculate this over the wavelet-HLL_firstorder_Median image, such that z = result['wavelet-HLL_firstorder_Median'], the difference is even larger, voxel-based: 2.696 vs 3.3475, which is large enough to cause problems.

What is the reason for the difference and what is the exact relationship between the two?

Thanks