1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
| from __future__ import print_function
import sys
import pandas as pd from PyQt5.QtCore import pyqtSignal from radiomics import featureextractor as FEE import yaml
from PyQt5 import uic from PyQt5.QtWidgets import QDialog, QFileDialog, QApplication
from DataProsessing import child
class RadiomicsFunc(QDialog): isChecked = pyqtSignal(int) def __init__(self): super().__init__() self.dia = uic.loadUi("New_UI.ui", self)
def setupParaFile(self): self.para_path = './ParaFile/Param.yml'
def ImgType_init(self,tag): self.para_path = './ParaFile/Param.yml' settingData = {
} with open(self.para_path, 'w', encoding='utf-8') as f: if tag == 1: self.displayOri() elif tag == 2: self.displayCT() elif tag == 3: self.displayMR3() elif tag == 4: self.displayMR5() elif tag == 5: self.displayMR() yaml.dump(data=settingData, stream=f, allow_unicode=True)
def featureSet(self): featureData = {
} with open(self.para_path, 'w', encoding='utf-8') as f: if self.checkBox_First.isChecked(): featureData["featureClass"] = {"firstorder": [] } if self.checkBox_shape.isChecked(): featureData["featureClass"] = {"shape": [] } if self.checkBox_glcm.isChecked(): featureData["featureClass"] = {"glcm": [] } if self.checkBox_glrlm.isChecked(): featureData["featureClass"] = {"glrlm": []} if self.checkBox_glszm.isChecked(): featureData["featureClass"] = {"glszm": [] } if self.checkBox_gldm.isChecked(): featureData["featureClass"] = {"gldm": [] } if self.checkBox_ngtdm.isChecked(): featureData["featureClass"] = {"ngtdm": [] } yaml.dump(data=featureData, stream=f, allow_unicode=True)
def outPuts(self,place,name,nii_path,ifsave,ori_path,label_path): self.ori_path = ori_path self.label_path = label_path extractor = FEE.RadiomicsFeatureExtractor(parameter_file=self.para_path) save_path = name + '.csv'
try: result = extractor.execute(ori_path, nii_path) except ValueError: result = extractor.execute(ori_path, nii_path, label=2) type(result)
df = pd.DataFrame() for key, value in result.items(): df = df.append({'Feature': key, 'Value': value}, ignore_index=True) ori_path = None lab_path = None
if ifsave == True : df.to_csv(save_path, index=False) RadiomicsFunc.invokeDialog_1(self, save_path)
def invokeDialog_1(self,path): dialog = child(path,self.ori_path,self.label_path) dialog.exec()
def displayOri(self): with open('./ParaFile/exampleCT.yaml', "rb") as ff: content = ff.read() with open(self.para_path, "ab") as f2: f2.write(content) def displayCT(self): with open('./ParaFile/exampleCT.yaml', "rb") as ff: content = ff.read() with open(self.para_path, "ab") as f2: f2.write(content) def displayMR3(self): with open('./ParaFile/exampleMR_3mm.yaml', "rb") as ff: content = ff.read() with open(self.para_path, "ab") as f2: f2.write(content) def displayMR5(self): with open('./ParaFile/exampleMR_5mm.yaml', "rb") as ff: content = ff.read() with open(self.para_path, "ab") as f2: f2.write(content) def displayMR(self): with open('./ParaFile/exampleMR_NoResampling.yaml.yaml', "rb") as ff: content = ff.read() with open(self.para_path, "ab") as f2: f2.write(content)
def Add_Nor(self, state): data = {
} with open(self.para_path, 'a', encoding='utf-8') as f: if state: data["setting"] = {"normalize": "True", "normalizeScale": 500} yaml.dump(data=data, stream=f, allow_unicode=True)
def Add_Mask(self, state): data = {
} with open(self.para_path, 'a', encoding='utf-8') as f: if state: data["setting"] = {"minimumROIDimensions": "2", "minimumROISize": "50"} yaml.dump(data=data, stream=f, allow_unicode=True)
def Add_Bin(self, state): data = {
} with open(self.para_path, 'a', encoding='utf-8') as f: if state: data["setting"] = {"minimumROISize": "50"} yaml.dump(data=data, stream=f, allow_unicode=True)
def Add_Misc(self, state): data = {
} with open(self.para_path, 'a', encoding='utf-8') as f: if state: data["setting"] = {"label": 1} yaml.dump(data=data, stream=f, allow_unicode=True)
def Add_FirstSpe(self, state): data = {
} with open(self.para_path, 'a', encoding='utf-8') as f: if state: data["setting"] = {"voxelArrayShift": "1000"} yaml.dump(data=data, stream=f, allow_unicode=True)
def Add_FirstSpe2(self, state): data = {
} with open(self.para_path, 'a', encoding='utf-8') as f: if state: data["setting"] = {"voxelArrayShift": "300"} yaml.dump(data=data, stream=f, allow_unicode=True)
def Add_Resampling(self, state): data = {
} with open(self.para_path, 'a', encoding='utf-8') as f: if state: data["setting"] = {"interpolator ": "'sitkBSpline'", "resampledPixelSpacing": " [2, 2, 2]"} yaml.dump(data=data, stream=f, allow_unicode=True)
def Add_Resampling2(self, state): data = {
} with open(self.para_path, 'a', encoding='utf-8') as f: if state: data["setting"] = {"preCrop ": "true"} yaml.dump(data=data, stream=f, allow_unicode=True)
""" if self.dia.checkBox_4.isChecked(): data["setting"] = {"minimumROIDimensions": "2","minimumROISize": "50"} elif self.dia.checkBox_5.isChecked(): #可以改成binwidth的输入项 data["setting"] = {"minimumROISize": "50"} elif self.dia.checkBox_6.isChecked(): data["setting"] = {"voxelArrayShift": "1000"} elif self.dia.checkBox.isChecked():#label数的输入项 data["setting"] = {"label": 1} """
def Add_2D(self, state): data = {
} with open(self.para_path, 'a', encoding='utf-8') as f: if state: data["setting"] = {"force2D ": "true"} yaml.dump(data=data, stream=f, allow_unicode=True)
def Add_Voxel(self,state): data = {
} with open(self.para_path, 'a', encoding='utf-8') as f: if state: data["voxelSetting"] = {"kernelRadius ": 2,"maskedKernel":"true","initValue":"nan","voxelBatch":10000} yaml.dump(data=data, stream=f, allow_unicode=True)
def cusParaSet(self,place): file_name = QFileDialog.getOpenFileName(None, "Open File", "./", "yaml(*.yml;*.yaml)") self.para_path = file_name[0] place.setText(self.para_path)
""" if tag == 1: #Original settingData["imageType"] = {"Original": {}} #写入参数设定文件 self.displayOri(settingData) elif tag == 2: settingData["imageType"] = {"Original": {}} self.displayCT(settingData) elif tag == 3: settingData["imageType"] = {"LoG": {}} elif tag == 4: settingData["imageType"] = {"Square": {}} elif tag == 5: settingData["imageType"] = {"SquareRoot": {}} elif tag == 6: settingData["imageType"] = {"Logarithm": {}} elif tag == 7: settingData["imageType"] = {"Exponential": {}} elif tag == 8: settingData["imageType"] = {"Gradient": {}} elif tag == 9: settingData["imageType"] = {"LocalBinaryPattern2D": {}} else : settingData["imageType"] = {"LocalBinaryPattern3D": {}} """
|