forked from bhalchandranoopur/GRP-3B
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOPHTHA_classifier.py
More file actions
139 lines (109 loc) · 4.58 KB
/
OPHTHA_classifier.py
File metadata and controls
139 lines (109 loc) · 4.58 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import re
import common_utils
import logging
log = logging.getLogger(__name__)
# Laterality, Left
def is_left(description):
regexes = [
re.compile('(^|[^a-zA-Z])(L|LE)([^a-zA-Z]|$)', re.IGNORECASE), # L or LE not surrounded by any other letters
re.compile('LEFT', re.IGNORECASE)
]
return common_utils.regex_search_label(regexes, description)
# Laterality, Right
def is_right(description):
regexes = [
re.compile('(^|[^a-zA-Z])(R|RE)([^a-zA-Z]|$)', re.IGNORECASE), # R or RE not surrounded by any other letters
re.compile('RIGHT', re.IGNORECASE)
]
return common_utils.regex_search_label(regexes, description)
# Modality, OCT
def is_OCT(description):
regexes = [
re.compile('OCT', re.IGNORECASE)
]
return common_utils.regex_search_label(regexes, description)
# Modality, OCT-OP
def is_OCT_OP(description):
regexes = [
re.compile('SD.*OCT.*OP(?!T)', re.IGNORECASE) # match ...OP, but not ...OPT
]
return common_utils.regex_search_label(regexes, description)
# Modality, OCT-OPT
def is_OCT_OPT(description):
regexes = [
re.compile('SD.*OCT.*OPT', re.IGNORECASE)
]
return common_utils.regex_search_label(regexes, description)
######################################################################################
######################################################################################
def classify_OPHTHA(dcm_metadata, acquisition):
"""
Classifies a OCT dicom series
Args:
dcm_metadata: dicom data object
acquisition: acquisition object
Returns:
dcm_metadata: The dictionary for the OCT classification
"""
log.info("Determining OPHTHA Classification...")
single_header_object = dcm_metadata['info']['header']['dicom']
updateFlag = False
if 'Columns' in single_header_object.keys():
updateFlag = True
elif is_OCT(acquisition.label):
updateFlag = True
if updateFlag:
study_description = None
if 'StudyDescription' in single_header_object.keys():
study_description = single_header_object['StudyDescription']
device_code_sequence = None
if 'AcquisitionDeviceTypeCodeSequence' in single_header_object.keys():
if 'CodeValue' in single_header_object['AcquisitionDeviceTypeCodeSequence']:
device_code_sequence = single_header_object['AcquisitionDeviceTypeCodeSequence']['CodeValue']
elif 'CodeValue' in single_header_object['AcquisitionDeviceTypeCodeSequence'][0]:
device_code_sequence = single_header_object['AcquisitionDeviceTypeCodeSequence'][0]['CodeValue']
classifications = {}
# Get Modality
modality = None
if device_code_sequence and device_code_sequence == 'A-00FBE':
modality = 'OCT'
elif is_OCT(acquisition.label):
modality = 'OCT'
updateFlag = True
elif device_code_sequence and study_description and study_description == 'CF':
modality = 'CF'
# Get Laterality
laterality = None
if single_header_object.get('ImageLaterality') == 'R':
laterality = ['Right Eye']
elif single_header_object.get('ImageLaterality') == 'L':
laterality = ['Left Eye']
elif is_right(acquisition.label):
laterality = ['Right Eye']
elif is_left(acquisition.label):
laterality = ['Left Eye']
if laterality: # set classification laterality
classifications.update({"Laterality": laterality})
# Get OCT Type
oct_type = None
if device_code_sequence and device_code_sequence == 'A-00FBE':
oct_type = ['Standard']
# print("Found match for Standard OCT from AcquisitionDeviceTypeCodeSequence match")
elif device_code_sequence and device_code_sequence == 'A-00E8A':
oct_type = ['Fundus']
# print("Found match for Fundus OCT from AcquisitionDeviceTypeCodeSequence match")
elif is_OCT_OP(acquisition.label):
oct_type = ['Fundus']
# print("Found match for Fundus OCT from is_OCT_OP match")
elif is_OCT_OPT(acquisition.label):
oct_type = ['Standard']
# print("Found match for Standard OCT from is_OCT_OPT match")
if oct_type:
classifications.update({"OCT Type": oct_type})
if classifications:
dcm_metadata['classification'] = classifications
if modality:
dcm_metadata['modality'] = modality
else:
pass
return dcm_metadata