文件夹内所有数据的读取
import os.path
import re
filepath = 'D:/datasets/Soft-tissue-Sarcoma/STS_004/09-30-1999-RIGHT THIGH C-81525/601-CLARKE CALFAXT1 RT - RESEARCH-86077'
for info in os.listdir(filepath):
file_name = os.path.join('%s\%s' % (filepath, info))
ds = pydicom.read_file(file_name)
# print(ds.dir("pat")) #查看dcm文件的所有词段
pix = ds.pixel_array
# pylab.imshow(ds.pixel_array, cmap=pylab.cm.bone)
# pylab.show()
dcm文件中包含患者信息的字段,可以通过dir查看DICOM文件有什么信息,可以通过字典返回相关的值。(本人没运行)
import json
def loadFileInformation(filename):
information = {}
ds = dicom.read_file(filename)
information['PatientID'] = ds.PatientID
information['PatientName'] = ds.PatientName
information['PatientBirthDate'] = ds.PatientBirthDate
information['PatientSex'] = ds.PatientSex
information['StudyID'] = ds.StudyID
information['StudyDate'] = ds.StudyDate
information['StudyTime'] = ds.StudyTime
information['InstitutionName'] = ds.InstitutionName
information['Manufacturer'] = ds.Manufacturer
print dir(ds)
print type(information)
return information
a=loadFileInformation('AT0001_100225002.DCM')
print a
网友评论