需要注意的的是Pyradiomics需要C++支持,Microsoft C++ 生成工具可以解决
直接安装pyradiomics,pip会自动安装其他pyradiomics所需的安装包
pip install pyradiomics
数据格式:图像使用的是.nrrd格式储存,每个受试者两个文件,一个是图像,一个是体素感兴趣区(VOI)
数据储存格式:两个文件夹一个存放所有的图像,一个存放所有的VOI
注意:图像的命名与VOI命名如下,如test1.nrrd(图像文件)和 test1.nrrd(VOI文件)
需要修改的是四处:1. tree1,是图像文件的地址;2. tree2,是VOI文件的地址;3. tree3,是参数配置文件,格式为.yaml;4. 特征提取结束后结果文件储存位置
import radiomics
import radiomics.featureextractor as FEE
import os
import csv
import pandas as pd
tree1 = r'G:\img'
tree2 = r'G:\voi'
tree3 = r'G:\parameter.yaml'
tree4 = r'results.csv'
extractor = FEE.RadiomicsFeatureExtractor(tree3)
namelist = []
valuelist = []
result = []
for root, dirs, files in os.walk(tree1):
for name in files:
result = (extractor.execute(os.path.join(tree1, name), os.path.join(tree2, name)))
valuelist.append(result.values())
namelist.append(name)
with open("./csv.csv",'w',newline='') as t:
writer = csv.writer(t)
writer.writerow(result.keys())
writer.writerows(valuelist)
csv = pd.read_csv("./csv.csv")
csv.insert(0, 'Name', namelist)
csv.to_csv(tree4, index=False)