comparison Plugins/DicomWeb/Run.py @ 304:b8399213b840

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 May 2020 18:25:38 +0200
parents cb56f56c98fb
children 59e8a50bef00
comparison
equal deleted inserted replaced
303:cb56f56c98fb 304:b8399213b840
37 import pprint 37 import pprint
38 import sys 38 import sys
39 import argparse 39 import argparse
40 import unittest 40 import unittest
41 import re 41 import re
42 from PIL import ImageChops
43
42 from DicomWeb import * 44 from DicomWeb import *
43 45
44 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests')) 46 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests'))
45 from Toolbox import * 47 from Toolbox import *
46 48
999 UploadInstance(ORTHANC, 'Issue164.dcm') 1001 UploadInstance(ORTHANC, 'Issue164.dcm')
1000 1002
1001 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') 1003 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')
1002 self.assertEqual(1, len(p)) 1004 self.assertEqual(1, len(p))
1003 self.assertEqual(743 * 975 * 3, len(p[0])) 1005 self.assertEqual(743 * 975 * 3, len(p[0]))
1004 self.assertTrue(ComputeMD5(p[0]) in [ 1006
1005 # The actual value depends on the JPEG decompression algorithm 1007 if HasGdcmPlugin(ORTHANC):
1006 # $ convert -depth 8 -size 975x743 rgb:tutu.raw pic.png 1008 self.assertTrue(ComputeMD5(p[0]) in [
1007 'b952d67da9ff004b0adae3982e89d620', # With GDCM 1009 'b952d67da9ff004b0adae3982e89d620', # GDCM >= 3.0
1008 'b3662c4bfa24a0c73abb08548c63319b', # With DCMTK 1010 'b3662c4bfa24a0c73abb08548c63319b' # Fallback to DCMTK
1009 ]) 1011 ])
1012 else:
1013 self.assertEqual('b3662c4bfa24a0c73abb08548c63319b', ComputeMD5(p[0])) # DCMTK
1010 1014
1011 1015
1012 def test_bitbucket_issue_168(self): 1016 def test_bitbucket_issue_168(self):
1013 # "Plugins can't read private tags from the configuration 1017 # "Plugins can't read private tags from the configuration
1014 # file" This test will fail if DCMTK <= 3.6.1 (e.g. on Ubuntu 1018 # file" This test will fail if DCMTK <= 3.6.1 (e.g. on Ubuntu
1155 '1.2.840.10008.1.2.4.57' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.57', 1159 '1.2.840.10008.1.2.4.57' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.57',
1156 '1.2.840.10008.1.2.4.70' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.70', 1160 '1.2.840.10008.1.2.4.70' : 'multipart/related; type=image/jpeg; transfer-syntax=1.2.840.10008.1.2.4.70',
1157 } 1161 }
1158 1162
1159 uri = '/dicom-web%s' % UploadAndGetWadoPath('TransferSyntaxes/1.2.840.10008.1.2.4.50.dcm') 1163 uri = '/dicom-web%s' % UploadAndGetWadoPath('TransferSyntaxes/1.2.840.10008.1.2.4.50.dcm')
1160 1164 truth = Image.open(GetDatabasePath('TransferSyntaxes/1.2.840.10008.1.2.4.50.png'))
1165
1161 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri, 1166 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri,
1162 headers = { 'Accept' : ACCEPT['1.2.840.10008.1.2.4.50'] }, 1167 headers = { 'Accept' : ACCEPT['1.2.840.10008.1.2.4.50'] },
1163 returnHeaders = True) 1168 returnHeaders = True)
1164 self.assertEqual(1, len(a)) 1169 self.assertEqual(1, len(a))
1165 self.assertEqual(2, len(a[0])) 1170 self.assertEqual(2, len(a[0]))
1171 self.assertEqual('142fdb8a1dc2aa7e6b8952aa294a6e22', ComputeMD5(a[0][0])) 1176 self.assertEqual('142fdb8a1dc2aa7e6b8952aa294a6e22', ComputeMD5(a[0][0]))
1172 1177
1173 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri) 1178 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri)
1174 self.assertEqual(1, len(a)) 1179 self.assertEqual(1, len(a))
1175 self.assertEqual(480 * 640 * 3, len(a[0])) 1180 self.assertEqual(480 * 640 * 3, len(a[0]))
1176 1181
1182 # http://effbot.org/zone/pil-comparing-images.htm
1183 img = Image.frombytes('RGB', [ 640, 480 ], a[0])
1184 self.assertLessEqual(GetMaxImageDifference(img, truth), 2)
1185
1177 ACCEPT2 = copy.deepcopy(ACCEPT) 1186 ACCEPT2 = copy.deepcopy(ACCEPT)
1178 if ComputeMD5(a[0]) == '654fd026c19daf92bf05137233b4f426': 1187 if HasGdcmPlugin(ORTHANC):
1179 IS_GDCM = True 1188 IS_GDCM = True
1180 ACCEPT2['1.2.840.10008.1.2.1'] = 'multipart/related; type=application/octet-stream' 1189 ACCEPT2['1.2.840.10008.1.2.1'] = 'multipart/related; type=application/octet-stream'
1181 del ACCEPT2['1.2.840.10008.1.2'] 1190 del ACCEPT2['1.2.840.10008.1.2']
1182 else: 1191 else:
1183 self.assertEqual('dfdc79f5070926bbb8ac079ee91f5b91', ComputeMD5(a[0])) 1192 self.assertEqual('dfdc79f5070926bbb8ac079ee91f5b91', ComputeMD5(a[0]))
1186 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri, 1195 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri,
1187 headers = { 'Accept' : ACCEPT2['1.2.840.10008.1.2.1'] }) 1196 headers = { 'Accept' : ACCEPT2['1.2.840.10008.1.2.1'] })
1188 self.assertEqual(1, len(a)) 1197 self.assertEqual(1, len(a))
1189 self.assertEqual(480 * 640 * 3, len(a[0])) 1198 self.assertEqual(480 * 640 * 3, len(a[0]))
1190 1199
1191 if IS_GDCM: 1200 img = Image.frombytes('RGB', [ 640, 480 ], a[0])
1192 self.assertEqual('654fd026c19daf92bf05137233b4f426', ComputeMD5(a[0])) 1201 self.assertLessEqual(GetMaxImageDifference(img, truth), 2)
1193 else: 1202
1203 if not IS_GDCM:
1194 self.assertEqual('dfdc79f5070926bbb8ac079ee91f5b91', ComputeMD5(a[0])) 1204 self.assertEqual('dfdc79f5070926bbb8ac079ee91f5b91', ComputeMD5(a[0]))
1195 1205
1196 1206
1197 # Test download using the same transfer syntax 1207 # Test download using the same transfer syntax
1198 RESULTS = { 1208 RESULTS = {
1205 } 1215 }
1206 1216
1207 if IS_GDCM: 1217 if IS_GDCM:
1208 # This file was failing with GDCM, as it has 2 fragments, 1218 # This file was failing with GDCM, as it has 2 fragments,
1209 # and only the first one was returned => the MD5 below is BAD 1219 # and only the first one was returned => the MD5 below is BAD
1210 RESULTS['1.2.840.10008.1.2.4.51'] = '901963a322a817946b074f9ed0afa060' 1220 #RESULTS['1.2.840.10008.1.2.4.51'] = '901963a322a817946b074f9ed0afa060'
1211 1221 pass
1222
1212 for syntax in ACCEPT2: 1223 for syntax in ACCEPT2:
1213 uri = '/dicom-web%s' % UploadAndGetWadoPath('TransferSyntaxes/%s.dcm' % syntax) 1224 uri = '/dicom-web%s' % UploadAndGetWadoPath('TransferSyntaxes/%s.dcm' % syntax)
1214 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri, 1225 a = DoGetMultipart(ORTHANC, '%s/frames/1' % uri,
1215 headers = { 'Accept' : ACCEPT2[syntax] }) 1226 headers = { 'Accept' : ACCEPT2[syntax] })
1216 self.assertEqual(1, len(a)) 1227 self.assertEqual(1, len(a))