Skip to content

Instantly share code, notes, and snippets.

@mcdlee
Created July 25, 2020 02:59
Show Gist options
  • Save mcdlee/aaa35896f612fd84fb6342f96120856c to your computer and use it in GitHub Desktop.
Save mcdlee/aaa35896f612fd84fb6342f96120856c to your computer and use it in GitHub Desktop.
PyRadiomics to Pandas DataFrame
import radiomics
import six
from radiomics import featureextractor
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
extractor = featureextractor.RadiomicsFeatureExtractor()
def feature2pd(image, mask, index):
result = extractor.execute(image, mask)
sub_dict = {}
for key, value in six.iteritems(result):
if key.find('original') == 0: #篩選key的開頭是'original'
#print(key)
#print(float(value))
key = key[9:]
value=float(value)
sub_dict.update({key:value})
output = pd.DataFrame.from_dict(sub_dict, orient='index', columns=[index]).transpose()
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment