Mercurial > hg > orthanc-tests
annotate Plugins/WSI/Run.py @ 527:86456045ac80 Orthanc-1.12.0
added test_numeric_metadata
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 Apr 2023 12:12:44 +0200 |
parents | 933fe1bbce4f |
children | 13169c8ddc96 |
rev | line source |
---|---|
251 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 | |
5 # Orthanc - A Lightweight, RESTful DICOM Store | |
6 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
7 # Department, University Hospital of Liege, Belgium | |
511
933fe1bbce4f
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
460
diff
changeset
|
8 # Copyright (C) 2017-2023 Osimis S.A., Belgium |
933fe1bbce4f
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
460
diff
changeset
|
9 # Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
251 | 10 # |
11 # This program is free software: you can redistribute it and/or | |
12 # modify it under the terms of the GNU General Public License as | |
13 # published by the Free Software Foundation, either version 3 of the | |
14 # License, or (at your option) any later version. | |
15 # | |
16 # This program is distributed in the hope that it will be useful, but | |
17 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 # General Public License for more details. | |
20 # | |
21 # You should have received a copy of the GNU General Public License | |
22 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
23 | |
24 | |
25 import argparse | |
26 import os | |
27 import pprint | |
28 import re | |
29 import subprocess | |
30 import sys | |
31 import tempfile | |
32 import unittest | |
33 from shutil import copyfile | |
34 | |
35 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests')) | |
36 from Toolbox import * | |
37 | |
38 | |
39 ## | |
40 ## Parse the command-line arguments | |
41 ## | |
42 | |
43 parser = argparse.ArgumentParser(description = 'Run the integration tests for the WSI Dicomizer.') | |
44 | |
45 parser.add_argument('--server', | |
46 default = 'localhost', | |
47 help = 'Address of the Orthanc server to test') | |
48 parser.add_argument('--rest', | |
49 type = int, | |
50 default = 8042, | |
51 help = 'Port to the REST API') | |
52 parser.add_argument('--username', | |
53 default = 'alice', | |
54 help = 'Username to the REST API') | |
55 parser.add_argument('--password', | |
56 default = 'orthanctest', | |
57 help = 'Password to the REST API') | |
58 parser.add_argument('--dicomizer', | |
59 default = '/home/jodogne/Subversion/orthanc-wsi/Applications/i/OrthancWSIDicomizer', | |
60 help = 'Password to the REST API') | |
61 parser.add_argument('--to-tiff', | |
62 default = '/home/jodogne/Subversion/orthanc-wsi/Applications/i/OrthancWSIDicomToTiff', | |
63 help = 'Password to the REST API') | |
252 | 64 parser.add_argument('--valgrind', help = 'Use valgrind while running the DICOM-izer', |
65 action = 'store_true') | |
251 | 66 parser.add_argument('--force', help = 'Do not warn the user', |
67 action = 'store_true') | |
68 parser.add_argument('options', metavar = 'N', nargs = '*', | |
69 help='Arguments to Python unittest') | |
70 | |
71 args = parser.parse_args() | |
72 | |
73 if not args.force: | |
74 print(""" | |
75 WARNING: This test will remove all the content of your | |
76 Orthanc instance running on %s! | |
77 | |
78 Are you sure ["yes" to go on]?""" % args.server) | |
79 | |
80 if sys.stdin.readline().strip() != 'yes': | |
81 print('Aborting...') | |
82 exit(0) | |
83 | |
84 | |
85 | |
86 | |
87 ## | |
88 ## The tests | |
89 ## | |
90 | |
91 ORTHANC = DefineOrthanc(server = args.server, | |
92 username = args.username, | |
93 password = args.password, | |
94 restPort = args.rest) | |
95 | |
253 | 96 def CallCommand(command): |
252 | 97 prefix = [] |
98 if args.valgrind: | |
99 prefix = [ 'valgrind' ] | |
100 | |
253 | 101 log = subprocess.check_output(prefix + command, |
252 | 102 stderr=subprocess.STDOUT) |
253 | 103 |
252 | 104 # If using valgrind, only print the lines from the log starting |
105 # with '==' (they contain the report from valgrind) | |
106 if args.valgrind: | |
107 print('\n'.join(filter(lambda x: x.startswith('=='), log.splitlines()))) | |
251 | 108 |
253 | 109 |
110 def CallDicomizer(suffix): | |
111 CallCommand([ args.dicomizer, | |
460 | 112 '--orthanc=http://%s:%s' % (args.server, args.rest), |
253 | 113 '--username=%s' % args.username, |
459 | 114 '--password=%s' % args.password ] + suffix |
115 ) | |
253 | 116 |
117 | |
118 def CallDicomToTiff(suffix): | |
316 | 119 CallCommand([ args.to_tiff, |
460 | 120 '--orthanc=http://%s:%s' % (args.server, args.rest), |
316 | 121 '--username=%s' % args.username, |
122 '--password=%s' % args.password ] + suffix) | |
253 | 123 |
124 | |
125 def CallTiffInfoOnSeries(series): | |
126 with tempfile.NamedTemporaryFile(delete = False) as temp: | |
127 temp.close() | |
128 CallDicomToTiff([ series, temp.name ]) | |
316 | 129 try: |
130 tiff = subprocess.check_output([ 'tiffinfo', temp.name ]) | |
131 except: | |
132 print('\ntiffinfo is probably not installed => sudo apt-get install libtiff-tools\n') | |
133 tiff = None | |
134 | |
253 | 135 os.unlink(temp.name) |
136 | |
137 return tiff | |
138 | |
251 | 139 |
140 class Orthanc(unittest.TestCase): | |
141 def setUp(self): | |
142 if (sys.version_info >= (3, 0)): | |
143 # Remove annoying warnings about unclosed socket in Python 3 | |
144 import warnings | |
145 warnings.simplefilter("ignore", ResourceWarning) | |
146 | |
147 DropOrthanc(ORTHANC) | |
148 | |
149 | |
150 def test_single(self): | |
151 CallDicomizer([ GetDatabasePath('Lena.jpg') ]) | |
152 | |
153 i = DoGet(ORTHANC, '/instances') | |
154 self.assertEqual(1, len(i)) | |
155 | |
156 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i[0]) | |
157 self.assertEqual(1, int(tags['NumberOfFrames'])) | |
158 self.assertEqual(512, int(tags['Columns'])) | |
159 self.assertEqual(512, int(tags['Rows'])) | |
160 self.assertEqual('YBR_FULL_422', tags['PhotometricInterpretation']) | |
161 | |
162 s = DoGet(ORTHANC, '/series') | |
163 self.assertEqual(1, len(s)) | |
164 | |
165 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0]) | |
166 self.assertEqual(s[0], pyramid['ID']) | |
167 self.assertEqual(1, len(pyramid['Resolutions'])) | |
168 self.assertEqual(1, len(pyramid['Sizes'])) | |
169 self.assertEqual(1, len(pyramid['TilesCount'])) | |
170 self.assertEqual(1, pyramid['Resolutions'][0]) | |
171 self.assertEqual(512, pyramid['Sizes'][0][0]) | |
172 self.assertEqual(512, pyramid['Sizes'][0][1]) | |
364
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
173 self.assertEqual(1, len(pyramid['TilesSizes'])) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
174 self.assertEqual(2, len(pyramid['TilesSizes'][0])) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
175 self.assertEqual(512, pyramid['TilesSizes'][0][0]) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
176 self.assertEqual(512, pyramid['TilesSizes'][0][1]) |
251 | 177 self.assertEqual(512, pyramid['TotalWidth']) |
178 self.assertEqual(512, pyramid['TotalHeight']) | |
179 self.assertEqual(1, pyramid['TilesCount'][0][0]) | |
180 self.assertEqual(1, pyramid['TilesCount'][0][1]) | |
181 | |
253 | 182 tiff = CallTiffInfoOnSeries(s[0]) |
183 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) | |
184 self.assertEqual(1, len(p)) | |
185 self.assertTrue('YCbCr' in p[0]) | |
186 | |
251 | 187 |
188 def test_grayscale_pyramid(self): | |
189 CallDicomizer([ GetDatabasePath('LenaGrayscale.png'), '--tile-width=64', '--tile-height=64' ]) | |
190 | |
191 i = DoGet(ORTHANC, '/instances') | |
192 self.assertEqual(4, len(i)) | |
193 | |
194 for j in range(4): | |
195 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i[j]) | |
196 self.assertEqual(64, int(tags['Columns'])) | |
197 self.assertEqual(64, int(tags['Rows'])) | |
198 self.assertEqual('MONOCHROME2', tags['PhotometricInterpretation']) | |
199 | |
200 s = DoGet(ORTHANC, '/series') | |
201 self.assertEqual(1, len(s)) | |
202 | |
203 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0]) | |
204 self.assertEqual(s[0], pyramid['ID']) | |
205 self.assertEqual(4, len(pyramid['Resolutions'])) | |
206 self.assertEqual(4, len(pyramid['Sizes'])) | |
207 self.assertEqual(4, len(pyramid['TilesCount'])) | |
364
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
208 self.assertEqual(4, len(pyramid['TilesSizes'])) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
209 |
251 | 210 self.assertEqual(1, pyramid['Resolutions'][0]) |
211 self.assertEqual(2, pyramid['Resolutions'][1]) | |
212 self.assertEqual(4, pyramid['Resolutions'][2]) | |
213 self.assertEqual(8, pyramid['Resolutions'][3]) | |
214 self.assertEqual(512, pyramid['Sizes'][0][0]) | |
215 self.assertEqual(512, pyramid['Sizes'][0][1]) | |
216 self.assertEqual(256, pyramid['Sizes'][1][0]) | |
217 self.assertEqual(256, pyramid['Sizes'][1][1]) | |
218 self.assertEqual(128, pyramid['Sizes'][2][0]) | |
219 self.assertEqual(128, pyramid['Sizes'][2][1]) | |
220 self.assertEqual(64, pyramid['Sizes'][3][0]) | |
221 self.assertEqual(64, pyramid['Sizes'][3][1]) | |
364
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
222 for i in range(4): |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
223 self.assertEqual(2, len(pyramid['TilesSizes'][i])) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
224 self.assertEqual(64, pyramid['TilesSizes'][i][0]) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
225 self.assertEqual(64, pyramid['TilesSizes'][i][1]) |
251 | 226 self.assertEqual(512, pyramid['TotalWidth']) |
227 self.assertEqual(512, pyramid['TotalHeight']) | |
228 self.assertEqual(8, pyramid['TilesCount'][0][0]) | |
229 self.assertEqual(8, pyramid['TilesCount'][0][1]) | |
230 self.assertEqual(4, pyramid['TilesCount'][1][0]) | |
231 self.assertEqual(4, pyramid['TilesCount'][1][1]) | |
232 self.assertEqual(2, pyramid['TilesCount'][2][0]) | |
233 self.assertEqual(2, pyramid['TilesCount'][2][1]) | |
234 self.assertEqual(1, pyramid['TilesCount'][3][0]) | |
235 self.assertEqual(1, pyramid['TilesCount'][3][1]) | |
253 | 236 |
237 tiff = CallTiffInfoOnSeries(s[0]) | |
238 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) | |
239 self.assertEqual(4, len(p)) | |
240 for j in range(4): | |
241 self.assertTrue('min-is-black' in p[j]) | |
242 | |
243 | |
244 def test_import_tiff_grayscale(self): | |
245 CallDicomizer([ GetDatabasePath('WSI/LenaGrayscaleJpeg.tiff') ]) | |
246 | |
247 s = DoGet(ORTHANC, '/series') | |
248 self.assertEqual(1, len(s)) | |
249 | |
250 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0]) | |
251 self.assertEqual(4, len(pyramid['Resolutions'])) | |
252 | |
253 tiff = CallTiffInfoOnSeries(s[0]) | |
254 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) | |
255 self.assertEqual(4, len(p)) | |
256 for j in range(4): | |
257 self.assertTrue('min-is-black' in p[j]) | |
258 | |
259 | |
260 def test_import_tiff_ycbcr(self): | |
261 CallDicomizer([ GetDatabasePath('WSI/LenaColorJpegYCbCr.tiff') ]) | |
262 | |
263 s = DoGet(ORTHANC, '/series') | |
264 self.assertEqual(1, len(s)) | |
265 | |
266 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0]) | |
267 self.assertEqual(4, len(pyramid['Resolutions'])) | |
268 | |
269 tiff = CallTiffInfoOnSeries(s[0]) | |
270 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) | |
271 self.assertEqual(4, len(p)) | |
272 for j in range(4): | |
273 self.assertTrue('YCbCr' in p[j]) | |
274 | |
275 | |
276 def test_import_tiff_rgb(self): | |
277 CallDicomizer([ GetDatabasePath('WSI/LenaColorJpegRGB.tiff') ]) | |
278 | |
279 s = DoGet(ORTHANC, '/series') | |
280 self.assertEqual(1, len(s)) | |
281 | |
282 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0]) | |
283 self.assertEqual(4, len(pyramid['Resolutions'])) | |
284 | |
285 tiff = CallTiffInfoOnSeries(s[0]) | |
286 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines()) | |
287 self.assertEqual(4, len(p)) | |
288 for j in range(4): | |
289 self.assertTrue('RGB' in p[j]) | |
290 | |
364
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
291 |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
292 def test_concatenation(self): |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
293 # https://bugs.orthanc-server.com/show_bug.cgi?id=145 |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
294 CallDicomizer([ GetDatabasePath('LenaGrayscale.png'), '--levels=1', ]) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
295 i = DoGet(ORTHANC, '/instances') |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
296 self.assertEqual(1, len(i)) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
297 tags = DoGet(ORTHANC, '/instances/%s/tags?short' % i[0]) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
298 self.assertTrue('0020,0242' in tags) # SOP Instance UID of Concatenation Source |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
299 self.assertTrue('0020,9161' in tags) # Concatenation UID |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
300 self.assertTrue('0020,9162' in tags) # In-concatenation Number |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
301 self.assertTrue('0020,9228' in tags) # Concatenation Frame Offset Number |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
302 self.assertEqual('1', tags['0020,9162']) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
303 self.assertEqual('0', tags['0020,9228']) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
304 |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
305 DropOrthanc(ORTHANC) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
306 |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
307 # "--max-size" disables the concatenation |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
308 CallDicomizer([ GetDatabasePath('LenaGrayscale.png'), '--levels=1', '--max-size=0' ]) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
309 i = DoGet(ORTHANC, '/instances') |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
310 self.assertEqual(1, len(i)) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
311 tags = DoGet(ORTHANC, '/instances/%s/tags?short' % i[0]) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
312 self.assertFalse('0020,0242' in tags) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
313 self.assertFalse('0020,9161' in tags) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
314 self.assertFalse('0020,9162' in tags) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
315 self.assertFalse('0020,9228' in tags) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
316 |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
317 DropOrthanc(ORTHANC) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
318 |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
319 # This creates a series with 2 instances of roughly 1.5MB (= 2 frames x 512 x 512 x 3 (RGB24) + DICOM overhead) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
320 CallDicomizer([ GetDatabasePath('WSI/Lena2x2.png'), '--levels=1', '--max-size=1', '--compression=none' ]) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
321 i = DoGet(ORTHANC, '/instances') |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
322 self.assertEqual(2, len(i)) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
323 t1 = DoGet(ORTHANC, '/instances/%s/tags?short' % i[0]) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
324 t2 = DoGet(ORTHANC, '/instances/%s/tags?short' % i[1]) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
325 self.assertTrue('0020,0242' in t1) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
326 self.assertTrue('0020,9161' in t1) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
327 self.assertTrue('0020,9162' in t1) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
328 self.assertTrue('0020,9228' in t1) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
329 self.assertEqual(t1['0020,0242'], t2['0020,0242']) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
330 self.assertEqual(t1['0020,9161'], t2['0020,9161']) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
331 if t1['0020,9162'] == '1': |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
332 self.assertEqual('1', t1['0020,9162']) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
333 self.assertEqual('0', t1['0020,9228']) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
334 self.assertEqual('2', t2['0020,9162']) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
335 self.assertEqual('2', t2['0020,9228']) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
336 else: |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
337 self.assertEqual('1', t2['0020,9162']) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
338 self.assertEqual('0', t2['0020,9228']) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
339 self.assertEqual('2', t1['0020,9162']) |
6fa8218cf8db
wsi: test_concatenation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
363
diff
changeset
|
340 self.assertEqual('2', t1['0020,9228']) |
365
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
341 |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
342 |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
343 def test_pixel_spacing(self): |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
344 # https://bugs.orthanc-server.com/show_bug.cgi?id=139 |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
345 CallDicomizer([ GetDatabasePath('LenaGrayscale.png'), # Image is 512x512 |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
346 '--levels=4', '--tile-width=64', '--tile-height=64', '--max-size=0', |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
347 '--imaged-width=20', '--imaged-height=10' ]) |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
348 |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
349 instances = DoGet(ORTHANC, '/instances') |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
350 self.assertEqual(4, len(instances)) |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
351 |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
352 spacings = {} |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
353 for i in instances: |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
354 t = DoGet(ORTHANC, '/instances/%s/tags?short' % i) |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
355 spacings[t['0028,0008']] = t['5200,9229'][0]['0028,9110'][0]['0028,0030'] |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
356 |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
357 self.assertEqual(4, len(spacings)) |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
358 for i in range(4): |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
359 s = spacings[str(4 ** i)].split('\\') |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
360 self.assertEqual(2, len(s)) |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
361 self.assertEqual(20.0 / 512.0 * (2.0 ** (3 - i)), float(s[0])) |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
362 self.assertEqual(10.0 / 512.0 * (2.0 ** (3 - i)), float(s[1])) |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
363 |
27cb0b60f2d3
wsi: test_pixel_spacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
364
diff
changeset
|
364 |
251 | 365 try: |
366 print('\nStarting the tests...') | |
367 unittest.main(argv = [ sys.argv[0] ] + args.options) | |
368 | |
369 finally: | |
370 print('\nDone') |