comparison Plugins/DicomWeb/Run.py @ 539:ef41b62b456e

updated DicomWEB tests for YBR images that are not transformed into RGB anymore
author Alain Mazy <am@osimis.io>
date Tue, 06 Jun 2023 17:05:26 +0200
parents 23d577e9a32f
children 8722f7f95a38
comparison
equal deleted inserted replaced
538:7a83a8f087c7 539:ef41b62b456e
1079 1079
1080 p = DoGetMultipart(ORTHANC, 'dicom-web/studies/1.2.276.0.26.1.1.1.2.2020.45.52293.1506048/series/1.2.276.0.26.1.1.1.2.2020.45.52293.6384450/instances/1.2.276.0.26.1.1.1.2.2020.45.52366.2551599.179568640/frames/5') 1080 p = DoGetMultipart(ORTHANC, 'dicom-web/studies/1.2.276.0.26.1.1.1.2.2020.45.52293.1506048/series/1.2.276.0.26.1.1.1.2.2020.45.52293.6384450/instances/1.2.276.0.26.1.1.1.2.2020.45.52366.2551599.179568640/frames/5')
1081 self.assertEqual(1, len(p)) 1081 self.assertEqual(1, len(p))
1082 self.assertEqual(743 * 975 * 3, len(p[0])) 1082 self.assertEqual(743 * 975 * 3, len(p[0]))
1083 1083
1084 metadata = DoGet(ORTHANC, 'dicom-web/studies/1.2.276.0.26.1.1.1.2.2020.45.52293.1506048/series/1.2.276.0.26.1.1.1.2.2020.45.52293.6384450/instances/1.2.276.0.26.1.1.1.2.2020.45.52366.2551599.179568640/metadata')
1085 self.assertEqual("YBR_FULL_422", metadata[0]['00280004']['Value'][0])
1086
1087 # starting from 1.12.1, Orthanc does not convert YBR to RGB anymore -> new checksum (https://discourse.orthanc-server.org/t/orthanc-convert-ybr-to-rgb-but-does-not-change-metadata/3533)
1088 if IsOrthancVersionAbove(ORTHANC, 1, 12, 1):
1089 expectedDcmtkChecksum = '7535a11e7da0fa590c467ac9d323c5c1'
1090 else:
1091 expectedDcmtkChecksum = 'b3662c4bfa24a0c73abb08548c63319b'
1092
1084 if HasGdcmPlugin(ORTHANC): 1093 if HasGdcmPlugin(ORTHANC):
1085 self.assertTrue(ComputeMD5(p[0]) in [ 1094 self.assertTrue(ComputeMD5(p[0]) in [
1086 'b952d67da9ff004b0adae3982e89d620', # GDCM >= 3.0 1095 'b952d67da9ff004b0adae3982e89d620', # GDCM >= 3.0
1087 'b3662c4bfa24a0c73abb08548c63319b' # Fallback to DCMTK 1096 expectedDcmtkChecksum # Fallback to DCMTK
1088 ]) 1097 ])
1089 else: 1098 else:
1090 self.assertEqual('b3662c4bfa24a0c73abb08548c63319b', ComputeMD5(p[0])) # DCMTK 1099 self.assertEqual(expectedDcmtkChecksum, ComputeMD5(p[0])) # DCMTK
1091 1100
1092 1101
1093 def test_bitbucket_issue_168(self): 1102 def test_bitbucket_issue_168(self):
1094 # "Plugins can't read private tags from the configuration 1103 # "Plugins can't read private tags from the configuration
1095 # file" This test will fail if DCMTK <= 3.6.1 (e.g. on Ubuntu 1104 # file" This test will fail if DCMTK <= 3.6.1 (e.g. on Ubuntu
1236 '1.2.840.10008.1.2.4.57' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.57', 1245 '1.2.840.10008.1.2.4.57' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.57',
1237 '1.2.840.10008.1.2.4.70' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.70', 1246 '1.2.840.10008.1.2.4.70' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.70',
1238 } 1247 }
1239 1248
1240 uri = 'dicom-web%s' % UploadAndGetWadoPath('TransferSyntaxes/1.2.840.10008.1.2.4.50.dcm') 1249 uri = 'dicom-web%s' % UploadAndGetWadoPath('TransferSyntaxes/1.2.840.10008.1.2.4.50.dcm')
1241 truth = Image.open(GetDatabasePath('TransferSyntaxes/1.2.840.10008.1.2.4.50.png')) 1250 truthRGB = Image.open(GetDatabasePath('TransferSyntaxes/1.2.840.10008.1.2.4.50.png'))
1242 1251 with open(GetDatabasePath('TransferSyntaxes/1.2.840.10008.1.2.4.50.YBR.raw'), 'rb') as f:
1252 truthRawYbr = f.read()
1253
1254 # first test: no transcoding since we accept the JPEG transfer syntax
1243 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri, 1255 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri,
1244 headers = { 'Accept' : ACCEPT['1.2.840.10008.1.2.4.50'] }, 1256 headers = { 'Accept' : ACCEPT['1.2.840.10008.1.2.4.50'] },
1245 returnHeaders = True) 1257 returnHeaders = True)
1246 self.assertEqual(1, len(a)) 1258 self.assertEqual(1, len(a))
1247 self.assertEqual(2, len(a[0])) 1259 self.assertEqual(2, len(a[0]))
1250 self.assertEqual(ACCEPT['1.2.840.10008.1.2.4.50'], 1262 self.assertEqual(ACCEPT['1.2.840.10008.1.2.4.50'],
1251 'multipart/related; type=%s' % a[0][1]['Content-Type']) 1263 'multipart/related; type=%s' % a[0][1]['Content-Type'])
1252 self.assertEqual(53476, len(a[0][0])) 1264 self.assertEqual(53476, len(a[0][0]))
1253 self.assertEqual('142fdb8a1dc2aa7e6b8952aa294a6e22', ComputeMD5(a[0][0])) 1265 self.assertEqual('142fdb8a1dc2aa7e6b8952aa294a6e22', ComputeMD5(a[0][0]))
1254 1266
1267 # second test: no accept header -> defaults to raw explicit
1255 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri) 1268 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri)
1256 self.assertEqual(1, len(a)) 1269 self.assertEqual(1, len(a))
1257 self.assertEqual(480 * 640 * 3, len(a[0])) 1270 self.assertEqual(480 * 640 * 3, len(a[0]))
1258 1271
1259 # http://effbot.org/zone/pil-comparing-images.htm 1272 # Orthanc is now returning the YBR image instead of the RGB
1260 img = Image.frombytes('RGB', [ 640, 480 ], a[0]) 1273 if IsOrthancVersionAbove(ORTHANC, 1, 12, 1) and not HasGdcmPlugin(ORTHANC):
1261 self.assertLessEqual(GetMaxImageDifference(img, truth), 2) 1274 # GetMaxImageDifference does not work with YBR images -> strict comparison with the output of dcmdjpeg
1275 self.assertEqual('d4aacc6c7758c7c968a4fc8d59b041d5', ComputeMD5(a[0]))
1276 else:
1277 # http://effbot.org/zone/pil-comparing-images.htm
1278 img = Image.frombytes('RGB', [ 640, 480 ], a[0])
1279 self.assertLessEqual(GetMaxImageDifference(img, truthRGB), 2)
1262 1280
1263 ACCEPT2 = copy.deepcopy(ACCEPT) 1281 ACCEPT2 = copy.deepcopy(ACCEPT)
1264 if HasGdcmPlugin(ORTHANC): 1282 if HasGdcmPlugin(ORTHANC):
1265 IS_GDCM = True 1283 IS_GDCM = True
1266 ACCEPT2['1.2.840.10008.1.2.1'] = 'multipart/related; type=application/octet-stream' 1284 ACCEPT2['1.2.840.10008.1.2.1'] = 'multipart/related; type=application/octet-stream'
1267 del ACCEPT2['1.2.840.10008.1.2'] 1285 del ACCEPT2['1.2.840.10008.1.2']
1268 else: 1286 else:
1269 self.assertEqual('dfdc79f5070926bbb8ac079ee91f5b91', ComputeMD5(a[0])) 1287 if not IsOrthancVersionAbove(ORTHANC, 1, 12, 1):
1288 self.assertEqual('dfdc79f5070926bbb8ac079ee91f5b91', ComputeMD5(a[0]))
1270 IS_GDCM = False 1289 IS_GDCM = False
1271 1290
1272 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri, 1291 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri,
1273 headers = { 'Accept' : ACCEPT2['1.2.840.10008.1.2.1'] }) 1292 headers = { 'Accept' : ACCEPT2['1.2.840.10008.1.2.1'] })
1274 self.assertEqual(1, len(a)) 1293 self.assertEqual(1, len(a))
1275 self.assertEqual(480 * 640 * 3, len(a[0])) 1294 self.assertEqual(480 * 640 * 3, len(a[0]))
1276 1295
1277 img = Image.frombytes('RGB', [ 640, 480 ], a[0]) 1296 if IsOrthancVersionAbove(ORTHANC, 1, 12, 1) and not HasGdcmPlugin(ORTHANC):
1278 self.assertLessEqual(GetMaxImageDifference(img, truth), 2) 1297 # GetMaxImageDifference does not work with YBR images -> strict comparison with the output of dcmdjpeg
1279 1298 self.assertEqual('d4aacc6c7758c7c968a4fc8d59b041d5', ComputeMD5(a[0]))
1280 if not IS_GDCM: 1299 else:
1300 # http://effbot.org/zone/pil-comparing-images.htm
1301 img = Image.frombytes('RGB', [ 640, 480 ], a[0])
1302 self.assertLessEqual(GetMaxImageDifference(img, truthRGB), 2)
1303
1304 if not IS_GDCM and not IsOrthancVersionAbove(ORTHANC, 1, 12, 1):
1281 self.assertEqual('dfdc79f5070926bbb8ac079ee91f5b91', ComputeMD5(a[0])) 1305 self.assertEqual('dfdc79f5070926bbb8ac079ee91f5b91', ComputeMD5(a[0]))
1282 1306
1283 1307
1284 # Test download using the same transfer syntax 1308 # Test download using the same transfer syntax
1285 RESULTS = { 1309 RESULTS = {