from tkinter import *
import tkinter.filedialog
from tkinter.filedialog import askdirectory
import tkinter.messagebox
import os
import radiomics
from radiomics import featureextractor
import pandas as pd
import numpy as np
import skimage
import trimesh
import joblib
import webbrowser
def FeatureExtrator(): #path为待提取特征的文件夹所在路径
path = str(inp1.get())
folderList = []
for root, dirs, files in os.walk(path): #遍历整个文件夹,把所有文件夹名字存入folderList变量中(不包括子文件夹)
for d in dirs :
folderList.append(d)
df = pd.DataFrame() #建立空表格
settings = {
'binWidth': 20,
'sigma': [1, 2, 3],
'verbose': True,
# 'force2D': True,
# 'label': 255
}
extractor = featureextractor.RadiomicsFeatureExtractor(additionInfo=True, **settings)
extractor.enableAllImageTypes()
extractor.enableAllFeatures()
for folder in folderList:
imageName = path +'/' + folder +'/T2.nrrd'
maskName = path +'/' + folder + '/T2-label.nrrd'
featureVector = extractor.execute(imageName,maskName)
df_add = pd.DataFrame.from_dict(featureVector.values()).T
df_add.columns = featureVector.keys()
df_add.insert(0, 'Name', folder, allow_duplicates=False) #首列新增一列为病人名字
df = pd.concat([df,df_add])
print('已提取T2--'+folder)
df_T2 = df