import radiomics
import radiomics.featureextractor as FEE
import os
import json
# 文件名
main_path = os.path.abspath('.')
print (os.getcwd())
ori_name = r'/Abdomen 1.5 B30f.nrrd'
lab_name = r'/1.nrrd'
para_name = r'/Params.yaml'
# 文件全部路径
ori_path = main_path + ori_name
lab_path = main_path + lab_name
para_path = main_path + para_name
# 使用配置文件初始化特征抽取器
extractor = FEE.RadiomicsFeatureExtractor(para_path)
# 运行
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(load_dict)
网友评论