import radiomics
import radiomics.featureextractor as FEE
import os
import json
# 文件名
main_path = os.path.abspath('.')
print (os.getcwd())
ori_name = r'/PET WB.nrrd'
lab_name = r'/object_image.nrrd'
para_name = r'/Params.yaml'
# 文件全部路径
ori_path = main_path + ori_name
lab_path = main_path + lab_name
para_path = main_path + para_name
# print("originl path: " + ori_path)
# print("label path: " + lab_path)
# print("parameter path: " + para_path)
# 使用配置文件初始化特征抽取器
extractor = FEE.RadiomicsFeatureExtractor(para_path)
extractor.enableAllImageTypes()
# print ("Extraction parameters:\n\t", extractor.settings)
# print ("Enabled filters:\n\t", extractor.enabledImagetypes)
# print ("Enabled features:\n\t", extractor.enabledFeatures)
# 运行
result = extractor.execute(ori_path,lab_path) #抽取特征
res={}
for key, value in result.items(): #输出特征
if(str(type(value))=="<class 'numpy.ndarray'>"):
res[key]=value.tolist()
else:
res[key]=value
#缓存到外部json
with open("record.json","w") as f:
json.dump(res,f)
with open("record.json","r") as dump_f:
load_dict = json.load(dump_f)
#print(len(load_dict))
网友评论