Voxel-based radiomic feature extraction

Hi everyone, I am doing radiomic feature extraction using voxel-based mode. Although I can get the feature maps (.nrrd files), I can’t find a way to get each voxel’s values (radiomic feature). I need those values in a .csv or .xls format to train a classification model. Could someone please help me?

The feature maps are the per-voxel radiomics features. There are a lot of them so the binary nrrd format is more appropriate than a csv file would be. You can access the per-voxel values by working with the feature maps as a numpy array like the examples here.

Hi Steve,
Thank you for your quick reply. But, I need to extract all the voxel values (not just for a coordinate) of the feature map. With the code slicer.util.arrayFromVolume(volumeNode), I can get just some values. Any suggestion ?

I’m not sure what you mean here. The array will have one element for each voxel in the volume. If the volume is a feature map the element is the feature value for that voxel.

This is the script to obtain one feature (Entropy)

import numpy
import radiomics
from radiomics import featureextractor
import six
import sys, os
import matplotlib.pyplot as plt
import numpy as np
import SimpleITK as sitk
dataDir = '----my directory-----'
imageName = os.path.join(dataDir, 'brain.nii.gz')
maskName = os.path.join(dataDir, 'roi.nii.gz')
params = os.path.join(dataDir, 'Params.yaml')
extractor = featureextractor.RadiomicsFeatureExtractor(params)
extractor.disableAllFeatures()  # disable all features
extractor.enableFeaturesByName(firstorder=['Entropy'])  # Only enable firstorder Entropy

extractor.settings['initValue'] = 0  # Set the non-calculated voxels to 0

result = extractor.execute(imageName, maskName, voxelBased=True)

for key, val in six.iteritems(result):
  if isinstance(val, sitk.Image):
    parametermap = sitk.GetArrayFromImage(val)
    parametermap[np.isnan(parametermap)] = 0

plt.imshow(parametermap[15, :, :])
plt.show()
print(parametermap)

[[[0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  ...
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]]

 [[0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  ...
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]]

 [[0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  ...
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]]

 ...

 [[0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  ...
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]]

 [[0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  ...
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]]

 [[0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  ...
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]
  [0. 0. 0. ... 0. 0. 0.]]]

Process finished with exit code 0

As you see, I got only 0 values…
I tried to save the array to csv, but It seem not to be compatible with 3D arrays. So, I reshaped the array to 3D, but It doesn’t work…

The map looks fine, but I need the values of every voxel from all the radiomic features

Ah, that’s because numpy shortens the output by only showing the first and last values, so for volumes with some padding it often looks empty but isn’t. Try print(parametermap.mean()) or print(parametermap.max()) instead.

Yes, with .mean = 0.5405715539212325, and with .max = 4.095795255000928. But, I need the entire array of the volume (voxel by voxel) in a table format.
Thanks a lot for your help!

Hmm, that’s going to be a long table, but if that’s what you need then you can just make a nested loop through all the slice, row, column indices and save the corresponding values into a table. You can get the dimensions from the array’s shape property. You might use a csv writer.

Thanks Steve, but I can’t get a proper table, there is a problem with 3D array type. I wonder if there is a “clean” way to do what I’m looking for…

By the way, with np.set_printoptions(threshold=np.inf) I get all values from 1 slice of my volume

Hi, did you solve this problem please. I recently had this one problem too and would like some advice.

Have we solved this problem? I need the answer. My question is related. How do I write voxel-based feature map data in a nrrd file, which I can import to 3D slicer?

Altought Pyradiomics offers the option to save the feature maps as nrrd. The best solution I found is to extract the features and convert them directly into an array while keeping the spatial information from the source segmentation (mask). Please check out this repo GitHub - smcch/Predicting_Glioblastoma_Recurrence_MRI