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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
251
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Orthanc - A Lightweight, RESTful DICOM Store
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 #
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 # This program is free software: you can redistribute it and/or
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # modify it under the terms of the GNU General Public License as
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 # published by the Free Software Foundation, either version 3 of the
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # License, or (at your option) any later version.
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 #
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 # This program is distributed in the hope that it will be useful, but
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 # General Public License for more details.
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 #
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 # You should have received a copy of the GNU General Public License
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import argparse
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 import os
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 import pprint
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 import re
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 import subprocess
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 import sys
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 import tempfile
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 import unittest
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 from shutil import copyfile
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'Tests'))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 from Toolbox import *
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 ##
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 ## Parse the command-line arguments
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 ##
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 parser = argparse.ArgumentParser(description = 'Run the integration tests for the WSI Dicomizer.')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 parser.add_argument('--server',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 default = 'localhost',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 help = 'Address of the Orthanc server to test')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 parser.add_argument('--rest',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 type = int,
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 default = 8042,
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 help = 'Port to the REST API')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 parser.add_argument('--username',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 default = 'alice',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 help = 'Username to the REST API')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 parser.add_argument('--password',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 default = 'orthanctest',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 help = 'Password to the REST API')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 parser.add_argument('--dicomizer',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 default = '/home/jodogne/Subversion/orthanc-wsi/Applications/i/OrthancWSIDicomizer',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 help = 'Password to the REST API')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 parser.add_argument('--to-tiff',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 default = '/home/jodogne/Subversion/orthanc-wsi/Applications/i/OrthancWSIDicomToTiff',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 help = 'Password to the REST API')
252
01db33301c3d valgrind
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 251
diff changeset
64 parser.add_argument('--valgrind', help = 'Use valgrind while running the DICOM-izer',
01db33301c3d valgrind
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 251
diff changeset
65 action = 'store_true')
251
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 parser.add_argument('--force', help = 'Do not warn the user',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 action = 'store_true')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 parser.add_argument('options', metavar = 'N', nargs = '*',
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 help='Arguments to Python unittest')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 args = parser.parse_args()
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 if not args.force:
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 print("""
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 WARNING: This test will remove all the content of your
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 Orthanc instance running on %s!
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 Are you sure ["yes" to go on]?""" % args.server)
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 if sys.stdin.readline().strip() != 'yes':
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 print('Aborting...')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 exit(0)
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 ##
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 ## The tests
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 ##
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 ORTHANC = DefineOrthanc(server = args.server,
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 username = args.username,
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 password = args.password,
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 restPort = args.rest)
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
96 def CallCommand(command):
252
01db33301c3d valgrind
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 251
diff changeset
97 prefix = []
01db33301c3d valgrind
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 251
diff changeset
98 if args.valgrind:
01db33301c3d valgrind
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 251
diff changeset
99 prefix = [ 'valgrind' ]
01db33301c3d valgrind
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 251
diff changeset
100
253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
101 log = subprocess.check_output(prefix + command,
252
01db33301c3d valgrind
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 251
diff changeset
102 stderr=subprocess.STDOUT)
253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
103
252
01db33301c3d valgrind
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 251
diff changeset
104 # If using valgrind, only print the lines from the log starting
01db33301c3d valgrind
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 251
diff changeset
105 # with '==' (they contain the report from valgrind)
01db33301c3d valgrind
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 251
diff changeset
106 if args.valgrind:
01db33301c3d valgrind
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 251
diff changeset
107 print('\n'.join(filter(lambda x: x.startswith('=='), log.splitlines())))
251
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
109
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
110 def CallDicomizer(suffix):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
111 CallCommand([ args.dicomizer,
460
Alain Mazy <am@osimis.io>
parents: 459
diff changeset
112 '--orthanc=http://%s:%s' % (args.server, args.rest),
253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
113 '--username=%s' % args.username,
459
723d4535252e WSI tests: set orthanc url
Alain Mazy <am@osimis.io>
parents: 449
diff changeset
114 '--password=%s' % args.password ] + suffix
723d4535252e WSI tests: set orthanc url
Alain Mazy <am@osimis.io>
parents: 449
diff changeset
115 )
253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
116
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
117
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
118 def CallDicomToTiff(suffix):
316
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 260
diff changeset
119 CallCommand([ args.to_tiff,
460
Alain Mazy <am@osimis.io>
parents: 459
diff changeset
120 '--orthanc=http://%s:%s' % (args.server, args.rest),
316
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 260
diff changeset
121 '--username=%s' % args.username,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 260
diff changeset
122 '--password=%s' % args.password ] + suffix)
253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
124
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
125 def CallTiffInfoOnSeries(series):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
126 with tempfile.NamedTemporaryFile(delete = False) as temp:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
127 temp.close()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
128 CallDicomToTiff([ series, temp.name ])
316
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 260
diff changeset
129 try:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 260
diff changeset
130 tiff = subprocess.check_output([ 'tiffinfo', temp.name ])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 260
diff changeset
131 except:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 260
diff changeset
132 print('\ntiffinfo is probably not installed => sudo apt-get install libtiff-tools\n')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 260
diff changeset
133 tiff = None
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 260
diff changeset
134
253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
135 os.unlink(temp.name)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
136
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
137 return tiff
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
138
251
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 class Orthanc(unittest.TestCase):
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 def setUp(self):
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 if (sys.version_info >= (3, 0)):
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 # Remove annoying warnings about unclosed socket in Python 3
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 import warnings
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 warnings.simplefilter("ignore", ResourceWarning)
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 DropOrthanc(ORTHANC)
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 def test_single(self):
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 CallDicomizer([ GetDatabasePath('Lena.jpg') ])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 i = DoGet(ORTHANC, '/instances')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 self.assertEqual(1, len(i))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i[0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 self.assertEqual(1, int(tags['NumberOfFrames']))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 self.assertEqual(512, int(tags['Columns']))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 self.assertEqual(512, int(tags['Rows']))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 self.assertEqual('YBR_FULL_422', tags['PhotometricInterpretation'])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 s = DoGet(ORTHANC, '/series')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 self.assertEqual(1, len(s))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 self.assertEqual(s[0], pyramid['ID'])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 self.assertEqual(1, len(pyramid['Resolutions']))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 self.assertEqual(1, len(pyramid['Sizes']))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 self.assertEqual(1, len(pyramid['TilesCount']))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 self.assertEqual(1, pyramid['Resolutions'][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 self.assertEqual(512, pyramid['Sizes'][0][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 self.assertEqual(512, pyramid['TotalWidth'])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 self.assertEqual(512, pyramid['TotalHeight'])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 self.assertEqual(1, pyramid['TilesCount'][0][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 self.assertEqual(1, pyramid['TilesCount'][0][1])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
182 tiff = CallTiffInfoOnSeries(s[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
183 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
184 self.assertEqual(1, len(p))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
185 self.assertTrue('YCbCr' in p[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
186
251
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 def test_grayscale_pyramid(self):
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 CallDicomizer([ GetDatabasePath('LenaGrayscale.png'), '--tile-width=64', '--tile-height=64' ])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 i = DoGet(ORTHANC, '/instances')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 self.assertEqual(4, len(i))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 for j in range(4):
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 tags = DoGet(ORTHANC, '/instances/%s/tags?simplify' % i[j])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 self.assertEqual(64, int(tags['Columns']))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 self.assertEqual(64, int(tags['Rows']))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 self.assertEqual('MONOCHROME2', tags['PhotometricInterpretation'])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 s = DoGet(ORTHANC, '/series')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 self.assertEqual(1, len(s))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 self.assertEqual(s[0], pyramid['ID'])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 self.assertEqual(4, len(pyramid['Resolutions']))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 self.assertEqual(4, len(pyramid['Sizes']))
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 self.assertEqual(1, pyramid['Resolutions'][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 self.assertEqual(2, pyramid['Resolutions'][1])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 self.assertEqual(4, pyramid['Resolutions'][2])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 self.assertEqual(8, pyramid['Resolutions'][3])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 self.assertEqual(512, pyramid['Sizes'][0][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 self.assertEqual(512, pyramid['Sizes'][0][1])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 self.assertEqual(256, pyramid['Sizes'][1][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 self.assertEqual(256, pyramid['Sizes'][1][1])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 self.assertEqual(128, pyramid['Sizes'][2][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 self.assertEqual(128, pyramid['Sizes'][2][1])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 self.assertEqual(64, pyramid['Sizes'][3][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 self.assertEqual(512, pyramid['TotalWidth'])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 self.assertEqual(512, pyramid['TotalHeight'])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 self.assertEqual(8, pyramid['TilesCount'][0][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 self.assertEqual(8, pyramid['TilesCount'][0][1])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 self.assertEqual(4, pyramid['TilesCount'][1][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 self.assertEqual(4, pyramid['TilesCount'][1][1])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 self.assertEqual(2, pyramid['TilesCount'][2][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 self.assertEqual(2, pyramid['TilesCount'][2][1])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 self.assertEqual(1, pyramid['TilesCount'][3][0])
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 self.assertEqual(1, pyramid['TilesCount'][3][1])
253
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
236
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
237 tiff = CallTiffInfoOnSeries(s[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
238 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
239 self.assertEqual(4, len(p))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
240 for j in range(4):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
241 self.assertTrue('min-is-black' in p[j])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
242
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
243
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
244 def test_import_tiff_grayscale(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
245 CallDicomizer([ GetDatabasePath('WSI/LenaGrayscaleJpeg.tiff') ])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
246
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
247 s = DoGet(ORTHANC, '/series')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
248 self.assertEqual(1, len(s))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
249
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
250 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
251 self.assertEqual(4, len(pyramid['Resolutions']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
252
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
253 tiff = CallTiffInfoOnSeries(s[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
254 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
255 self.assertEqual(4, len(p))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
256 for j in range(4):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
257 self.assertTrue('min-is-black' in p[j])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
258
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
259
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
260 def test_import_tiff_ycbcr(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
261 CallDicomizer([ GetDatabasePath('WSI/LenaColorJpegYCbCr.tiff') ])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
262
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
263 s = DoGet(ORTHANC, '/series')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
264 self.assertEqual(1, len(s))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
265
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
266 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
267 self.assertEqual(4, len(pyramid['Resolutions']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
268
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
269 tiff = CallTiffInfoOnSeries(s[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
270 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
271 self.assertEqual(4, len(p))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
272 for j in range(4):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
273 self.assertTrue('YCbCr' in p[j])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
274
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
275
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
276 def test_import_tiff_rgb(self):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
277 CallDicomizer([ GetDatabasePath('WSI/LenaColorJpegRGB.tiff') ])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
278
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
279 s = DoGet(ORTHANC, '/series')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
280 self.assertEqual(1, len(s))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
281
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
282 pyramid = DoGet(ORTHANC, '/wsi/pyramids/%s' % s[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
283 self.assertEqual(4, len(pyramid['Resolutions']))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
284
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
285 tiff = CallTiffInfoOnSeries(s[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
286 p = filter(lambda x: 'Photometric Interpretation' in x, tiff.splitlines())
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
287 self.assertEqual(4, len(p))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
288 for j in range(4):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
289 self.assertTrue('RGB' in p[j])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 252
diff changeset
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
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 try:
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 print('\nStarting the tests...')
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 unittest.main(argv = [ sys.argv[0] ] + args.options)
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 finally:
16a5e79accff testing WSI DICOM-izer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 print('\nDone')