-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakedicom.py
37 lines (29 loc) · 1.07 KB
/
makedicom.py
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
import pydicom
import os
PathDicom = "G:/test/NeuroSeg_Imgs" # 与python文件同一个目录下的文件夹
lstFilesDCM = []
DCMname = []
for dirName, subdirList, fileList in sorted(os.walk(PathDicom)):
for filename in fileList:
if ".dcm" in filename.lower(): # 判断文件是否为dicom文件
lstFilesDCM.append(os.path.join(dirName, filename)) # 加入到列表中
# DCMname.append(filename)
# print(dirName)
# print(subdirList)
# print(fileList)
# print(filename)
# print(lstFilesDCM)
# print(DCMname)
# print(len(DCMname))
# print(len(lstFilesDCM))
i = 0
for i in range(len(lstFilesDCM)):
ds = pydicom.dcmread(lstFilesDCM[i])
ds.PatientName = '0000'
ds.save_as(lstFilesDCM[i])
i = i+1
# filename = r"E:\Dicom\test\DicomResource\1.3.12.2.1107.5.1.4.58073.30000010042701180060900001838.dcm"
# ds = pydicom.dcmread(filename) # 读取dicom文件
# ds.PatientName = '0000'
# ds.save_as('E:/Dicom/test/DicomResource/1.3.12.2.1107.5.1.4.58073.30000010042701180060900001838.dcm') # 将修改后文件保存
# print(ds.PatientName)