comparison Plugins/DicomWeb/Run.py @ 325:b7c2fb8e1b57

DICOMweb: test_compare_wado_uri_and_rs
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Aug 2020 20:30:28 +0200
parents 3c8c6b41eec4
children 4d3b797aa5ae
comparison
equal deleted inserted replaced
324:6164d39399ad 325:b7c2fb8e1b57
1034 self.assertEqual('20170404', a[0]['00080020']['Value'][0]) 1034 self.assertEqual('20170404', a[0]['00080020']['Value'][0])
1035 1035
1036 a = DoGet(ORTHANC, '/dicom-web/studies?includefield=00091001') 1036 a = DoGet(ORTHANC, '/dicom-web/studies?includefield=00091001')
1037 self.assertEqual(1, len(a)) 1037 self.assertEqual(1, len(a))
1038 self.assertFalse('00090010' in a[0]) 1038 self.assertFalse('00090010' in a[0])
1039 self.assertTrue('00091001' in a[0]) 1039 self.assertTrue('00091001' in a[0]) # This fails if DCMTK <= 3.6.1
1040 self.assertEqual('DS', a[0]['00091001']['vr']) 1040 self.assertEqual('DS', a[0]['00091001']['vr'])
1041 self.assertEqual(1, len(a[0]['00091001']['Value'])) 1041 self.assertEqual(1, len(a[0]['00091001']['Value']))
1042 self.assertAlmostEqual(98.41, a[0]['00091001']['Value'][0]) 1042 self.assertAlmostEqual(98.41, a[0]['00091001']['Value'][0])
1043 1043
1044 a = DoGet(ORTHANC, '/dicom-web/studies?00090010=Lunit&includefield=00091001') 1044 a = DoGet(ORTHANC, '/dicom-web/studies?00090010=Lunit&includefield=00091001')
1322 a = DoGetMultipart(ORTHANC, '%s' % uri, 1322 a = DoGetMultipart(ORTHANC, '%s' % uri,
1323 headers = { 'Accept' : 'multipart/related; type=application/dicom; transfer-syntax=1.2.840.10008.1.2.1' }) 1323 headers = { 'Accept' : 'multipart/related; type=application/dicom; transfer-syntax=1.2.840.10008.1.2.1' })
1324 self.assertEqual(1, len(a)) 1324 self.assertEqual(1, len(a))
1325 self.assertEqual('1.2.840.10008.1.2.1', GetTransferSyntax(a[0])) 1325 self.assertEqual('1.2.840.10008.1.2.1', GetTransferSyntax(a[0]))
1326 self.assertTrue(10 * s < len(a[0])) 1326 self.assertTrue(10 * s < len(a[0]))
1327
1328
1329 def test_compare_wado_uri_and_rs(self):
1330 # https://groups.google.com/d/msg/orthanc-users/mKgr2QAKTCU/R7u4I1LvBAAJ
1331
1332 # Image "2020-08-12-Christopher.dcm" corresponds to the result of:
1333 # $ gdcmconv --raw 1.2.840.113704.9.1000.16.2.20190613104005642000100010001.dcm 2020-08-12-Christopher.dcm
1334 # Image "2020-08-12-Christopher.png" corresponds to "2.png"
1335
1336 i = UploadInstance(ORTHANC, '2020-08-12-Christopher.dcm') ['ID']
1337 STUDY = '1.2.840.113704.9.1000.16.0.20190613103939444'
1338 SERIES = '1.2.840.113704.9.1000.16.1.2019061310394289000010001'
1339 INSTANCE = '1.2.840.113704.9.1000.16.2.20190613104005642000100010001'
1340
1341 with open(GetDatabasePath('2020-08-12-Christopher.png'), 'rb') as f:
1342 truth = UncompressImage(f.read())
1343
1344 im1 = GetImage(ORTHANC, args.wado + '?requestType=WADO&objectUID=%s&contentType=image/jpg' % INSTANCE)
1345 self.assertEqual('JPEG', im1.format)
1346
1347 im2 = GetImage(ORTHANC, args.wado + '?requestType=WADO&objectUID=%s&contentType=image/png' % INSTANCE)
1348 self.assertEqual('PNG', im2.format)
1349
1350 im3 = GetImage(ORTHANC, '/dicom-web/studies/%s/series/%s/instances/%s/frames/1/rendered' % (STUDY, SERIES, INSTANCE))
1351 self.assertEqual('JPEG', im3.format)
1352
1353 im4 = GetImage(ORTHANC, '/dicom-web/studies/%s/series/%s/instances/%s/rendered' % (STUDY, SERIES, INSTANCE),
1354 headers = { 'Accept' : 'image/png' })
1355 self.assertEqual('PNG', im4.format)
1356
1357 im5 = GetImage(ORTHANC, '/instances/%s/rendered' % i, { 'Accept' : 'image/jpeg' })
1358 self.assertEqual('JPEG', im5.format)
1359
1360 im6 = GetImage(ORTHANC, '/instances/%s/rendered' % i)
1361 self.assertEqual('PNG', im6.format)
1362
1363 for im in [ truth, im1, im2, im3, im4, im5, im6 ]:
1364 self.assertEqual('L', im.mode)
1365 self.assertEqual(512, im.size[0])
1366 self.assertEqual(512, im.size[1])
1367
1368 im2.save('/tmp/a.png')
1369 im4.save('/tmp/b.png')
1370 im6.save('/tmp/c.png')
1371
1372 # The following fails in DICOMweb plugin <= 1.2, as "/rendered"
1373 # was redirecting to the "/preview" route of Orthanc
1374 # http://effbot.org/zone/pil-comparing-images.htm
1375 self.assertTrue(ImageChops.difference(im2, truth).getbbox() is None)
1376 self.assertTrue(ImageChops.difference(im1, im3).getbbox() is None)
1377 self.assertTrue(ImageChops.difference(im1, im5).getbbox() is None)
1378 self.assertTrue(ImageChops.difference(im2, im4).getbbox() is None)
1379 self.assertTrue(ImageChops.difference(im2, im6).getbbox() is None)
1380 self.assertTrue(ImageChops.difference(im3, im5).getbbox() is None)
1381 self.assertTrue(ImageChops.difference(im4, im6).getbbox() is None)
1382
1327 1383
1328 try: 1384 try:
1329 print('\nStarting the tests...') 1385 print('\nStarting the tests...')
1330 unittest.main(argv = [ sys.argv[0] ] + args.options) 1386 unittest.main(argv = [ sys.argv[0] ] + args.options)
1331 1387