I have this code which is an adaption of the examples offered and it use to extract all the features as described in the params.yaml . The code use to work well, now it is extracting less features than it has to.
extractor.py file:
from __future__ import print_function
import os
import sys
import logging
import numpy as np
import SimpleITK as sitk
import six
import radiomics
reader1 = sitk.ImageFileReader()
reader2 = sitk.ImageFileReader()
reader1.SetFileName(input_imageName)
reader2.SetFileName(input_maskName)
image = reader1.Execute()
mask = reader2.Execute()
dataDir = '/home/leonardo/Desktop/Mestrado/DataSet-Pesquisa/Estudo-I/Included-Reprocessamento'
params = os.path.join(dataDir,"params.yaml")
extractor = radiomics.featureextractor.RadiomicsFeatureExtractor(params)
results = extractor.execute(image, mask)
features = []
features.append("Patients")
values = []
values.append(patient_id)
i = 0 # feature counter
for (key, val) in six.iteritems(results):
# the results comes with a 32 lines header. The first condition is to avoid storing those information;
if (i >= 32):
if (key.find("wavelet") == -1) and (key.find("gradient") == -1):
# This condition means if the feature is neither wavelet nor gradient it WILL BE SAVED;
features.append(key)
values.append(val)
elif (key.find("wavelet") != -1) and (key.find("firstorder") != -1):
# This condition means if the feature is WAVELET it MUST BE FIRSTORDER too to be SAVED;
features.append(key)
values.append(val)
elif (key.find("gradient") != -1) and (key.find("firstorder") != -1):
# This condition means if the feature is GRADIENT it MUST BE FIRSTORDER too to be SAVED;
features.append(key)
values.append(val)
i += 1
print('done')
feature_vals = ','.join(str(e) for e in values)
feature_keys = ','.join(str(e) for e in features)
print("Total number of features extrated: ", len(features), ".")
if os.path.exists("pyRadiomicsOutput.csv"):
with open("pyRadiomicsOutput.csv", "a+") as f:
f.write(feature_vals)
f.write("\n")
else:
with open("pyRadiomicsOutput.csv", "a+") as f:
f.write(feature_keys)
f.write("\n")
f.write(feature_vals)
f.write("\n")
Now, the params.yaml:
imageType:
Original: {}
Wavelet: {}
Gradient: {}
featureClass:
# redundant Compactness 1, Compactness 2 an Spherical Disproportion features are disabled by default, they can be
# enabled by specifying individual feature names (as is done for glcm) and including them in the list.
firstorder:
glcm:
glrlm:
glszm:
gldm:
ngtdm:
shape:
setting:
resegmentMode: 'sigma'
resegmentRange: [-3, 3]
binWidth: 3
label: 1
Any thoughts are welcomed.