读取dicom文件,获取内部信息进行保存,一个人保存一次

Elaine ·
更新时间:2024-11-14
· 739 次阅读

def rename_temp(): img_PATH = r"./test" flag = "(1)" csvfile = open(r'./patientID.csv', 'w', newline='') for path, dirs, files in os.walk(img_PATH): for filename in files: # 遍历所有文件 num = ((filename.split("_")[1]).split(")")[0]).split("(")[-1] file_path = os.path.join(path, filename) ds = pydicom.dcmread(file_path, force=True) # 读取dcm patient_id = str(ds.PatientID) patient_sex = str(ds.PatientSex) patient_age = str(ds.PatientAge) if patient_id != flag: print(num) print("{}***{}***{}".format(patient_id, patient_sex, patient_age)) writer = csv.writer(csvfile) writer.writerow([num, patient_id,patient_sex,patient_age]) flag = patient_id else: pass csvfile.close()
作者:QianLingjun



dicom

需要 登录 后方可回复, 如果你还没有账号请 注册新账号