-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdorenamedicom
More file actions
executable file
·27 lines (25 loc) · 879 Bytes
/
dorenamedicom
File metadata and controls
executable file
·27 lines (25 loc) · 879 Bytes
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
#!/usr/bin/env python
import os
import sys
import pydicom
from string import maketrans # Required to call maketrans function.
# read in the datafile
if len(sys.argv) != 2:
print("usage: dorenamedicom directoryname inputfile")
exit()
indirname = sys.argv[1]
infilename = sys.argv[2]
plan = pydicom.read_file(indirname + "/" + infilename)
# print plan
seriesnostr = plan.SeriesNumber
imagenostr = plan.AcquisitionNumber
protocolname = plan.SeriesDescription
tempstring = protocolname + "_" + str(seriesnostr)
thelist = tempstring.split()
dirname = indirname + "/" + ''.join(thelist)
outfilename = "IM-" + str(seriesnostr).rjust(4, '0') + "-" + str(imagenostr).rjust(4, '0') + ".dcm"
print(dirname, outfilename)
if not os.path.isdir(dirname + "/"):
os.mkdir(dirname + "/")
namestring = dirname + "/" + outfilename
os.rename(indirname + "/" + infilename, namestring)