-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdicomdiff.py
executable file
·55 lines (48 loc) · 1.21 KB
/
dicomdiff.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python3
import argparse
import os
import re
import pydicom
import dicomtools
def _path2dataset(path):
assert os.path.isfile(path)
assert dicomtools.file_is_valid(path)
return pydicom.dcmread(path)
def diff(dcm1, dcm2):
if type(dcm1) is str:
dcm1 = _path2dataset(dcm1)
if type(dcm2) is str:
dcm2 = _path2dataset(dcm2)
tags1 = iter(sorted(dcm1.keys()))
tags2 = iter(sorted(dcm2.keys()))
tag1 = next(tags1, None)
tag2 = next(tags2, None)
while tag1 and tag2:
val1 = dcm1[tag1]
val2 = dcm2[tag2]
if tag1 < tag2:
print("< {}".format(val1))
tag1 = next(tags1, None)
elif tag2 < tag1:
print("> {}".format(val2))
tag2 = next(tags2, None)
else:
if val1 != val2:
print("< {}".format(val1))
print("> {}".format(val2))
tag1 = next(tags1, None)
tag2 = next(tags2, None)
while tag1:
val1 = dcm1[tag1]
print("< {}".format(val1))
tag1 = next(tags1, None)
while tag2:
val2 = dcm2[tag2]
print("< {}".format(val2))
tag2 = next(tags2, None)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("dcm1", help="first DICOM file")
parser.add_argument("dcm2", help="second DICOM file")
args = parser.parse_args()
diff(args.dcm1, args.dcm2)