Commit a302c2d1a82dd6bc9090cf886be443cec4a84022
1 parent
e5314ee9
Exists in
master
and in
6 other branches
ENH: Replaced the way it reads some data, changed of vtkgdcm to gdcm reader DICOM tags.
Showing
1 changed file
with
154 additions
and
98 deletions
Show diff stats
invesalius/reader/dicom.py
... | ... | @@ -104,10 +104,12 @@ class Parser(): |
104 | 104 | DICOM standard tag (0x0008,0x0022) was used. |
105 | 105 | """ |
106 | 106 | # TODO: internationalize data |
107 | - date = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
108 | - .GetAcquisitionDate() | |
109 | - if (date) and (date != ''): | |
110 | - return self.__format_date(date) | |
107 | + tag = gdcm.Tag(0x0008, 0x0022) | |
108 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
109 | + if ds.FindDataElement(tag): | |
110 | + date = ds.GetDataElement(tag).GetValue() | |
111 | + if (date) and (date != ''): | |
112 | + return self.__format_date(str(date)) | |
111 | 113 | return "" |
112 | 114 | |
113 | 115 | def GetAcquisitionNumber(self): |
... | ... | @@ -151,10 +153,12 @@ class Parser(): |
151 | 153 | |
152 | 154 | DICOM standard tag (0x0008,0x0032) was used. |
153 | 155 | """ |
154 | - time = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
155 | - .GetAcquisitionTime() | |
156 | - if (time) and (time != 'None'): | |
157 | - return self.__format_time(time) | |
156 | + tag = gdcm.Tag(0x0008, 0x0032) | |
157 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
158 | + if ds.FindDataElement(tag): | |
159 | + data = ds.GetDataElement(tag).GetValue() | |
160 | + if (data) and (data != ''): | |
161 | + return self.__format_time(str(data)) | |
158 | 162 | return "" |
159 | 163 | |
160 | 164 | def GetPatientAdmittingDiagnosis(self): |
... | ... | @@ -164,7 +168,6 @@ class Parser(): |
164 | 168 | |
165 | 169 | DICOM standard tag (0x0008,0x1080) was used. |
166 | 170 | """ |
167 | - | |
168 | 171 | tag = gdcm.Tag(0x0008, 0x1080) |
169 | 172 | sf = gdcm.StringFilter() |
170 | 173 | sf.SetFile(self.gdcm_reader.GetFile()) |
... | ... | @@ -1063,14 +1066,15 @@ class Parser(): |
1063 | 1066 | DICOM standard tag (0x0010,0x0030) was used. |
1064 | 1067 | """ |
1065 | 1068 | # TODO: internationalize data |
1066 | - date = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1067 | - .GetPatientBirthDate() | |
1068 | - if (date) and (date!='None'): | |
1069 | - self.__format_date(date) | |
1069 | + tag = gdcm.Tag(0x0010, 0x0030) | |
1070 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1071 | + if ds.FindDataElement(tag): | |
1072 | + data = ds.GetDataElement(tag).GetValue() | |
1073 | + if (data) and (data != 'None'): | |
1074 | + return self.__format_date(str(data)) | |
1070 | 1075 | return "" |
1071 | 1076 | |
1072 | 1077 | |
1073 | - | |
1074 | 1078 | def GetStudyID(self): |
1075 | 1079 | """ |
1076 | 1080 | Return string containing the Study ID. |
... | ... | @@ -1078,13 +1082,14 @@ class Parser(): |
1078 | 1082 | |
1079 | 1083 | DICOM standard tag (0x0020,0x0010) was used. |
1080 | 1084 | """ |
1081 | - | |
1082 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1083 | - .GetStudyID() | |
1084 | - if (data): | |
1085 | - return data | |
1085 | + tag = gdcm.Tag(0x0020, 0x0010) | |
1086 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1087 | + if ds.FindDataElement(tag): | |
1088 | + data = ds.GetDataElement(tag).GetValue() | |
1089 | + if (data): | |
1090 | + return str(data) | |
1086 | 1091 | return "" |
1087 | - | |
1092 | + | |
1088 | 1093 | def GetAcquisitionGantryTilt(self): |
1089 | 1094 | """ |
1090 | 1095 | Return floating point containing nominal angle of |
... | ... | @@ -1093,10 +1098,14 @@ class Parser(): |
1093 | 1098 | |
1094 | 1099 | DICOM standard tag (0x0018,0x1120) was used. |
1095 | 1100 | """ |
1096 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1097 | - .GetGantryTilt() | |
1098 | - if (data): | |
1099 | - return float(data) | |
1101 | + tag = gdcm.Tag(0x0018, 0x1120) | |
1102 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1103 | + if ds.FindDataElement(tag): | |
1104 | + data = ds.GetDataElement(tag).GetValue() | |
1105 | + | |
1106 | + if (data): | |
1107 | + return float(str(data)) | |
1108 | + | |
1100 | 1109 | return 0.0 |
1101 | 1110 | |
1102 | 1111 | def GetPatientGender(self): |
... | ... | @@ -1109,10 +1118,13 @@ class Parser(): |
1109 | 1118 | |
1110 | 1119 | DICOM standard tag (0x0010,0x0040) was used. |
1111 | 1120 | """ |
1112 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1113 | - .GetPatientSex() | |
1114 | - if (data): | |
1115 | - return data | |
1121 | + tag = gdcm.Tag(0x0010, 0x0040) | |
1122 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1123 | + if ds.FindDataElement(tag): | |
1124 | + data = ds.GetDataElement(tag).GetValue() | |
1125 | + | |
1126 | + if (data): | |
1127 | + return str(data) | |
1116 | 1128 | return "" |
1117 | 1129 | |
1118 | 1130 | def GetPatientAge(self): |
... | ... | @@ -1123,14 +1135,17 @@ class Parser(): |
1123 | 1135 | |
1124 | 1136 | DICOM standard tag (0x0010, 0x1010) was used. |
1125 | 1137 | """ |
1126 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1127 | - .GetPatientAge() | |
1128 | - if (data): | |
1129 | - age = (data.split('Y')[0]) | |
1130 | - try: | |
1131 | - return int(age) | |
1132 | - except ValueError: | |
1133 | - return age | |
1138 | + tag = gdcm.Tag(0x0010, 0x1010) | |
1139 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1140 | + if ds.FindDataElement(tag): | |
1141 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1142 | + | |
1143 | + if (data): | |
1144 | + age = (data.split('Y')[0]) | |
1145 | + try: | |
1146 | + return int(age) | |
1147 | + except ValueError: | |
1148 | + return age | |
1134 | 1149 | return "" |
1135 | 1150 | |
1136 | 1151 | def GetPatientName(self): |
... | ... | @@ -1140,14 +1155,16 @@ class Parser(): |
1140 | 1155 | |
1141 | 1156 | DICOM standard tag (0x0010,0x0010) was used. |
1142 | 1157 | """ |
1143 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1144 | - .GetPatientName() | |
1158 | + tag = gdcm.Tag(0x0010, 0x0010) | |
1159 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1160 | + if ds.FindDataElement(tag): | |
1161 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1145 | 1162 | |
1146 | - if (data): | |
1147 | - name = data.strip() | |
1148 | - encoding = self.GetEncoding() | |
1149 | - # Returns a unicode decoded in the own dicom encoding | |
1150 | - return name.decode(encoding) | |
1163 | + if (data): | |
1164 | + name = data.strip() | |
1165 | + encoding = self.GetEncoding() | |
1166 | + # Returns a unicode decoded in the own dicom encoding | |
1167 | + return name.decode(encoding) | |
1151 | 1168 | return "" |
1152 | 1169 | |
1153 | 1170 | def GetPatientID(self): |
... | ... | @@ -1158,12 +1175,15 @@ class Parser(): |
1158 | 1175 | |
1159 | 1176 | DICOM standard tag (0x0010,0x0020) was used. |
1160 | 1177 | """ |
1161 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1162 | - .GetPatientID() | |
1163 | - if (data): | |
1164 | - encoding = self.GetEncoding() | |
1165 | - # Returns a unicode decoded in the own dicom encoding | |
1166 | - return data.decode(encoding) | |
1178 | + tag = gdcm.Tag(0x0010, 0x0020) | |
1179 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1180 | + if ds.FindDataElement(tag): | |
1181 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1182 | + | |
1183 | + if (data): | |
1184 | + encoding = self.GetEncoding() | |
1185 | + # Returns a unicode decoded in the own dicom encoding | |
1186 | + return data.decode(encoding) | |
1167 | 1187 | return "" |
1168 | 1188 | |
1169 | 1189 | |
... | ... | @@ -1212,10 +1232,13 @@ class Parser(): |
1212 | 1232 | |
1213 | 1233 | DICOM standard tag (0x0018,0x1151) was used. |
1214 | 1234 | """ |
1215 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1216 | - .GetXRayTubeCurrent() | |
1217 | - if (data): | |
1218 | - return data | |
1235 | + tag = gdcm.Tag(0x0018, 0x1151) | |
1236 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1237 | + if ds.FindDataElement(tag): | |
1238 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1239 | + | |
1240 | + if (data): | |
1241 | + return data | |
1219 | 1242 | return "" |
1220 | 1243 | |
1221 | 1244 | def GetExposureTime(self): |
... | ... | @@ -1226,10 +1249,13 @@ class Parser(): |
1226 | 1249 | |
1227 | 1250 | DICOM standard tag (0x0018, 0x1152) was used. |
1228 | 1251 | """ |
1229 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1230 | - .GetExposureTime() | |
1231 | - if (data): | |
1232 | - return float(data) | |
1252 | + tag = gdcm.Tag(0x0018, 0x1152) | |
1253 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1254 | + if ds.FindDataElement(tag): | |
1255 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1256 | + | |
1257 | + if (data): | |
1258 | + return float(data) | |
1233 | 1259 | return "" |
1234 | 1260 | |
1235 | 1261 | def GetEquipmentKVP(self): |
... | ... | @@ -1240,10 +1266,13 @@ class Parser(): |
1240 | 1266 | |
1241 | 1267 | DICOM standard tag (0x0018,0x0060) was used. |
1242 | 1268 | """ |
1243 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1244 | - .GetKVP() | |
1245 | - if (data): | |
1246 | - return float(data) | |
1269 | + tag = gdcm.Tag(0x0018, 0x0060) | |
1270 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1271 | + if ds.FindDataElement(tag): | |
1272 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1273 | + | |
1274 | + if (data): | |
1275 | + return float(data) | |
1247 | 1276 | return "" |
1248 | 1277 | |
1249 | 1278 | def GetImageThickness(self): |
... | ... | @@ -1254,10 +1283,13 @@ class Parser(): |
1254 | 1283 | |
1255 | 1284 | DICOM standard tag (0x0018,0x0050) was used. |
1256 | 1285 | """ |
1257 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1258 | - .GetSliceThickness() | |
1259 | - if (data): | |
1260 | - return float(data) | |
1286 | + tag = gdcm.Tag(0x0018, 0x1050) | |
1287 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1288 | + if ds.FindDataElement(tag): | |
1289 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1290 | + | |
1291 | + if (data): | |
1292 | + return float(data) | |
1261 | 1293 | return 0 |
1262 | 1294 | |
1263 | 1295 | def GetImageConvolutionKernel(self): |
... | ... | @@ -1270,10 +1302,13 @@ class Parser(): |
1270 | 1302 | |
1271 | 1303 | DICOM standard tag (0x0018,0x1210) was used. |
1272 | 1304 | """ |
1273 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1274 | - .GetConvolutionKernel() | |
1275 | - if (data): | |
1276 | - return data | |
1305 | + tag = gdcm.Tag(0x0018, 0x1210) | |
1306 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1307 | + if ds.FindDataElement(tag): | |
1308 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1309 | + | |
1310 | + if (data): | |
1311 | + return data | |
1277 | 1312 | return "" |
1278 | 1313 | |
1279 | 1314 | def GetEquipmentInstitutionName(self): |
... | ... | @@ -1284,10 +1319,13 @@ class Parser(): |
1284 | 1319 | |
1285 | 1320 | DICOM standard tag (0x0008,0x0080) was used. |
1286 | 1321 | """ |
1287 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1288 | - .GetInstitutionName() | |
1289 | - if (data): | |
1290 | - return data | |
1322 | + tag = gdcm.Tag(0x0008, 0x0080) | |
1323 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1324 | + if ds.FindDataElement(tag): | |
1325 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1326 | + | |
1327 | + if (data): | |
1328 | + return data | |
1291 | 1329 | return "" |
1292 | 1330 | |
1293 | 1331 | def GetStationName(self): |
... | ... | @@ -1298,10 +1336,13 @@ class Parser(): |
1298 | 1336 | |
1299 | 1337 | DICOM standard tag (0x0008, 0x1010) was used. |
1300 | 1338 | """ |
1301 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1302 | - .GetStationName() | |
1303 | - if (data): | |
1304 | - return data | |
1339 | + tag = gdcm.Tag(0x0008, 0x1010) | |
1340 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1341 | + if ds.FindDataElement(tag): | |
1342 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1343 | + | |
1344 | + if (data): | |
1345 | + return data | |
1305 | 1346 | return "" |
1306 | 1347 | |
1307 | 1348 | def GetManufacturerModelName(self): |
... | ... | @@ -1312,10 +1353,13 @@ class Parser(): |
1312 | 1353 | |
1313 | 1354 | DICOM standard tag (0x0008,0x1090) was used. |
1314 | 1355 | """ |
1315 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1316 | - .GetManufacturerModelName() | |
1317 | - if (data): | |
1318 | - return data | |
1356 | + tag = gdcm.Tag(0x0008, 0x1090) | |
1357 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1358 | + if ds.FindDataElement(tag): | |
1359 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1360 | + | |
1361 | + if (data): | |
1362 | + return data | |
1319 | 1363 | return "" |
1320 | 1364 | |
1321 | 1365 | def GetEquipmentManufacturer(self): |
... | ... | @@ -1325,10 +1369,13 @@ class Parser(): |
1325 | 1369 | |
1326 | 1370 | DICOM standard tag (0x0008, 0x1010) was used. |
1327 | 1371 | """ |
1328 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1329 | - .GetManufacturer() | |
1330 | - if (data): | |
1331 | - return data | |
1372 | + tag = gdcm.Tag(0x0008, 0x1010) | |
1373 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1374 | + if ds.FindDataElement(tag): | |
1375 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1376 | + | |
1377 | + if (data): | |
1378 | + return data | |
1332 | 1379 | return "" |
1333 | 1380 | |
1334 | 1381 | def GetAcquisitionModality(self): |
... | ... | @@ -1340,10 +1387,13 @@ class Parser(): |
1340 | 1387 | |
1341 | 1388 | DICOM standard tag (0x0008,0x0060) was used. |
1342 | 1389 | """ |
1343 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1344 | - .GetModality() | |
1345 | - if (data): | |
1346 | - return data | |
1390 | + tag = gdcm.Tag(0x0008, 0x0060) | |
1391 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1392 | + if ds.FindDataElement(tag): | |
1393 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1394 | + | |
1395 | + if (data): | |
1396 | + return data | |
1347 | 1397 | return "" |
1348 | 1398 | |
1349 | 1399 | |
... | ... | @@ -1354,10 +1404,13 @@ class Parser(): |
1354 | 1404 | |
1355 | 1405 | DICOM standard tag (0x0020,0x0013) was used. |
1356 | 1406 | """ |
1357 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1358 | - .GetImageNumber() | |
1359 | - if (data): | |
1360 | - return int(data) | |
1407 | + tag = gdcm.Tag(0x0020, 0x0013) | |
1408 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1409 | + if ds.FindDataElement(tag): | |
1410 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1411 | + | |
1412 | + if (data): | |
1413 | + return int(data) | |
1361 | 1414 | return "" |
1362 | 1415 | |
1363 | 1416 | def GetStudyDescription(self): |
... | ... | @@ -1367,11 +1420,14 @@ class Parser(): |
1367 | 1420 | |
1368 | 1421 | DICOM standard tag (0x0008,0x1030) was used. |
1369 | 1422 | """ |
1370 | - data = self.vtkgdcm_reader.GetMedicalImageProperties()\ | |
1371 | - .GetStudyDescription() | |
1372 | - if (data): | |
1373 | - encoding = self.GetEncoding() | |
1374 | - return data.decode(encoding) | |
1423 | + tag = gdcm.Tag(0x0008, 0x1030) | |
1424 | + ds = self.gdcm_reader.GetFile().GetDataSet() | |
1425 | + if ds.FindDataElement(tag): | |
1426 | + data = str(ds.GetDataElement(tag).GetValue()) | |
1427 | + | |
1428 | + if (data): | |
1429 | + encoding = self.GetEncoding() | |
1430 | + return data.decode(encoding) | |
1375 | 1431 | return "" |
1376 | 1432 | |
1377 | 1433 | def GetStudyAdmittingDiagnosis(self): | ... | ... |