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