-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
108 lines (81 loc) · 2.27 KB
/
run.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import argparse
import anonymisation
import pydicom as dcm
def str2bool(v):
return v.lower() in ("true", "1")
if __name__ == '__main__':
# Initialize the parser
parser = argparse.ArgumentParser(
description="DICOM Anonymisation"
)
parser.add_argument(
"-i",
type=str,
default=None,
help="Input path",
)
parser.add_argument(
"-o",
type=str,
default=None,
help="Output path",
)
parser.add_argument(
"--keep_age",
type=str2bool,
default=True,
help="Whether to retain patient age",
)
parser.add_argument(
"--keep_dob",
type=str2bool,
default=True,
help="Whether to retain patient date of birth",
)
parser.add_argument(
"--keep_name",
type=str2bool,
default=False,
help="Whether to retain patient name",
)
parser.add_argument(
"--keep_address",
type=str2bool,
default=False,
help="Whether to retain patient address",
)
parser.add_argument(
"--keep_sex",
type=str2bool,
default=True,
help="Whether to retain patient sex",
)
parser.add_argument(
"--keep_id",
type=str2bool,
default=False,
help="Whether to retain patient ID",
)
parser.add_argument(
"--keep_accession",
type=str2bool,
default=False,
help="Whether to retain patient accession number",
)
args = parser.parse_args()
DCM = dcm.dcmread(args.i)
if not args.keep_age and hasattr(DCM, 'PatientAge'):
DCM.PatientAge = 'anon'
if not args.keep_dob and hasattr(DCM, 'PatientBirthDate'):
DCM.PatientBirthDate = 'anon'
if not args.keep_address and hasattr(DCM, 'PersonAddress'):
DCM.PersonAddress = 'anon'
if not args.keep_sex and hasattr(DCM, 'PatientSex'):
DCM.PatientSex = 'anon'
if not args.keep_id and hasattr(DCM, 'PatientID'):
DCM.PatientID = 'anon'
if not args.keep_accession and hasattr(DCM, 'AccessionNumber'):
DCM.AccessionNumber = 'anon'
if not args.keep_name and hasattr(DCM, 'PatientName'):
DCM.PatientName = 'anon'
dcm.dcmwrite(args.o, DCM)