3 from gdcmPython import *
5 class gdcmTestCase(unittest.TestCase):
6 # The files whose name starts with a modality (e.g. CR-MONO1-10-chest.dcm)
7 # come from Sebastien Barre's Dicom2 highly recommendable site
8 # http://www.barre.nom.fr/medical/samples/index.html
10 ####################################
11 # CR modality examples:
12 ####################################
13 ["CR-MONO1-10-chest.dcm",
15 #"Transfer Syntax UID" is absent.
18 ["Bits Stored", "10"],
19 ["Bits Allocated", "16"],
21 ["Pixel Representation", "0"],
22 ["Manufacturer", "FUJI PHOTO FILM CO. LTD."],
23 ["Manufacturer Model Name", "9000"],
24 ["7fe0|0010", "gdcm::NotLoaded. Address:776 Length:387200"] ] ],
25 ####################################
26 # CT modality examples:
27 ####################################
28 ["CT-MONO2-16-brain.dcm",
29 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
33 ["Bits Stored", "16"],
34 ["Bits Allocated", "16"],
36 ["Pixel Representation", "1"],
37 ["Manufacturer", "Picker International, Inc."],
38 ["Manufacturer Model Name", "PQ5000"],
39 ["7fe0|0010", "gdcm::NotLoaded. Address:1680 Length:524288"] ] ],
40 ["CT-MONO2-16-ort.dcm",
41 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
45 ["Bits Stored", "16"],
46 ["Bits Allocated", "16"],
48 ["Pixel Representation", "1"],
49 ["Manufacturer", "GE MEDICAL SYSTEMS"],
50 ["Manufacturer Model Name", "HiSpeed CT/i"],
51 ["7fe0|0010", "gdcm::NotLoaded. Address:1674 Length:524288"] ] ],
52 ["CT-MONO2-16-ankle.dcm",
53 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit, little
57 ["Bits Stored", "16"],
58 ["Bits Allocated", "16"],
60 ["Pixel Representation", "1"],
61 ["Manufacturer", "GE MEDICAL SYSTEMS"],
62 ["Manufacturer Model Name", "GENESIS_ZEUS"],
63 ["7fe0|0010", "gdcm::NotLoaded. Address:1148 Length:524288"] ] ],
64 ["CT-MONO2-8-abdo.dcm",
65 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit, little
70 ["Bits Allocated", "8"],
72 ["Pixel Representation", "0"],
73 ["Manufacturer", "FUJI"],
74 ["7fe0|0010", "gdcm::NotLoaded. Address:796 Length:262144"] ] ],
75 ["CT-MONO2-12-lomb-an2.acr2",
77 #"Transfer Syntax UID" and "Photometric Interpretation" are absent.
80 ["Bits Stored", "12"],
81 ["Bits Allocated", "16"],
83 ["Pixel Representation", "0"],
84 ["Manufacturer", "SIEMENS"],
85 ["7fe0|0010", "gdcm::NotLoaded. Address:1230 Length:524288"] ] ],
86 ["CT-MONO2-16-chest.dcm",
87 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"], # jpeg...
89 ["Photometric Interpretation", "MONOCHROME2"],
92 ["Bits Stored", "16"],
93 ["Bits Allocated", "16"],
95 ["Pixel Representation", "1"],
96 ["Manufacturer", "GE MEDICAL SYSTEMS"],
97 ["7fe0|0010", "gdcm::NotLoaded. Address:1638 Length:143498"] ] ],
98 ####################################
99 ### MR modality examples:
100 ####################################
101 ["MR-MONO2-12-angio-an1.acr1",
102 [ ["Recognition Code", "ACR-NEMA 1.0"],
104 #"Transfer Syntax UID" and "Photometric Interpretation" are absent.
107 ["Bits Stored", "12"],
108 ["Bits Allocated", "12"],
110 ["Pixel Representation", "0"],
111 ["Manufacturer", "Philips"],
112 # Note: 256*256*12/8 = 98304
113 ["7fe0|0010", "gdcm::NotLoaded. Address:650 Length:98304"] ] ],
114 ["MR-MONO2-12-an2.acr2",
115 [ ["Modality", "MR"],
116 ["Photometric Interpretation", "MONOCHROME2"],
119 ["Bits Stored", "12"],
120 ["Bits Allocated", "16"],
122 ["Pixel Representation", "0"],
123 ["Manufacturer", "SIEMENS"],
124 ["Manufacturer Model Name", "MAGNETOM VISION"],
125 ["7fe0|0010", "gdcm::NotLoaded. Address:1866 Length:131072"] ] ],
126 ["MR-MONO2-16-head.dcm",
127 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Imp VR, LE
129 ["Photometric Interpretation", "MONOCHROME2"],
132 ["Bits Stored", "16"],
133 ["Bits Allocated", "16"],
135 ["Pixel Representation", "1"],
136 ["Manufacturer", "GE MEDICAL SYSTEMS"],
137 ["Manufacturer Model Name", "GENESIS_SIGNA"],
138 ["7fe0|0010", "gdcm::NotLoaded. Address:1804 Length:131072"] ] ],
139 # MR-MONO2-12-shoulder example is present in the Jpeg section.
140 # MR-MONO2-16-knee is not present in the test suite since it is too
141 # closely related to MR-MONO2-16-head.dcm to be of interest.
142 ####################################
143 # OT modality examples:
144 ####################################
145 # OT-MONO2-8-hip is not present in the test suite since it is too
146 # closely related to OT-MONO2-8-a7 to be of interest.
147 ["OT-PAL-8-face.dcm",
148 # Interest: has a color palette
149 [#"Transfer Syntax UID", and "Manufacturer" are absent.
151 ["Photometric Interpretation", "PALETTE COLOR"],
154 ["Bits Stored", "8"],
155 ["Bits Allocated", "8"],
157 ["Pixel Representation", "0"],
158 ["7fe0|0010", "gdcm::NotLoaded. Address:1654 Length:307200"] ] ],
159 # OT-MONO2-8-colon is not present in the test suite since it is too
160 # closely related to OT-MONO2-8-a7 to be of interest.
161 ["OT-MONO2-8-a7.dcm",
162 [#"Transfer Syntax UID" is absent.
164 ["Photometric Interpretation", "MONOCHROME2"],
167 ["Bits Stored", "8"],
168 ["Bits Allocated", "8"],
170 ["Pixel Representation", "0"],
171 ["Manufacturer", "Philips Medical Systems"],
172 ["7fe0|0010", "gdcm::NotLoaded. Address:438 Length:262144"] ] ],
173 ####################################
174 # US (Ultra Sound) modality examples:
175 ####################################
176 ["US-RGB-8-esopecho.dcm",
177 # Interest: RGB image
178 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Exp VR, LE
180 ["Photometric Interpretation", "RGB"],
183 ["Bits Stored", "8"],
184 ["Bits Allocated", "8"],
186 ["Pixel Representation", "0"],
187 ["Manufacturer", "Acme Products"],
188 # FIXME: 92160 / (120*256) = 3 bytes per pixel NOT 1. Maybe
189 # it has something to do with [Samples Per Pixel] = [3] ???
190 ["7fe0|0010", "gdcm::NotLoaded. Address:904 Length:92160"] ] ],
191 ["US-RGB-8-epicard.dcm",
192 # Interest: Big endian transfert syntax
193 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.2"], # Big endian
195 ["Photometric Interpretation", "RGB"],
198 ["Bits Stored", "8"],
199 ["Bits Allocated", "8"],
201 ["Pixel Representation", "0"],
202 ["Manufacturer", "G.E. Medical Systems"],
203 ["Manufacturer Model Name", "LOGIQ 700"],
204 # FIXME: 921600/(480*640) = 3 bytes per pixel NOT 1. Maybe
205 # it has something to do with [Samples Per Pixel] = [3] ???
206 ["Implementation Version Name", "OFFIS-DCMTK-311"],
207 ["7fe0|0010", "gdcm::NotLoaded. Address:1012 Length:921600"] ] ],
211 # The number of images is contained in the "Number of Frames" element
212 ["MR-MONO2-8-16x-heart.dcm",
213 # Interest: multi-frame
214 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
215 ["Number of Frames", "16"],
217 ["Photometric Interpretation", "MONOCHROME2"],
220 ["Bits Stored", "8"],
221 ["Bits Allocated", "8"],
223 ["Pixel Representation", "0"],
224 ["Manufacturer", "Philips"],
225 # Note: 256*256*16=1048576 (16 is the number of Frames)
226 ["7fe0|0010", "gdcm::NotLoaded. Address:920 Length:1048576"] ] ],
227 ["NM-MONO2-16-13x-heart.dcm",
228 # Interest: NM modality, multi-frame
229 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
230 ["Number of Frames", "13"],
232 ["Photometric Interpretation", "MONOCHROME2"],
235 ["Bits Stored", "16"],
236 ["Bits Allocated", "16"],
238 ["Pixel Representation", "0"],
239 ["Manufacturer", "ACME Products"],
240 # Note: 64*64*13*2=106496
241 ["7fe0|0010", "gdcm::NotLoaded. Address:1234 Length:106496"] ] ],
242 ["US-MONO2-8-8x-execho.dcm",
243 # Interest: multi-frame
244 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
245 ["Number of Frames", "8"],
247 ["Photometric Interpretation", "MONOCHROME2"],
250 ["Bits Stored", "8"],
251 ["Bits Allocated", "8"],
253 ["Pixel Representation", "0"],
254 ["Manufacturer", "Acme Products"],
255 ["7fe0|0010", "gdcm::NotLoaded. Address:976 Length:122880"] ] ],
256 ["US-PAL-8-10x-echo.dcm",
257 # Interest: RLE (Run Length Encoded) compression, multiframe
258 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.5"], # RLE
259 ["Number of Frames", "10"],
261 ["Photometric Interpretation", "PALETTE COLOR"],
264 ["Bits Stored", "8"],
265 ["Bits Allocated", "8"],
267 ["Pixel Representation", "0"],
268 ["Manufacturer", "ACME Products"],
269 ["7fe0|0010", "gdcm::NotLoaded. Address:2428 Length:481182"] ] ],
270 ["XA-MONO2-8-12x-catheter.dcm",
271 # Interest: XA modality, multi-frame
272 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"], # jpeg
273 ["Number of Frames", "12"], # 12 images
275 ["Photometric Interpretation", "MONOCHROME2"],
278 ["Bits Stored", "8"],
279 ["Bits Allocated", "8"],
281 ["Pixel Representation", "0"],
282 ["Manufacturer", "Acme Products"],
283 ["7fe0|0010", "gdcm::NotLoaded. Address:1006 Length:920072"] ] ],
287 ["gdcm-MR-SIEMENS-16.acr1",
288 # Interest: good old Acr-Nema Version 1, see also Oddities below
289 [ ["Recognition Code", "ACR-NEMA 1.0"],
293 ["Bits Stored", "12"],
294 ["Bits Allocated", "16"],
296 ["Pixel Representation", "0"],
297 ["Manufacturer", "SIEMENS"],
298 ["Manufacturer Model Name", "GBS III"],
299 # FIXME: this image looks padded at the end. The length of the file
300 # is 140288. Notice that, 256*256*2 + 1024 = 131072 + 1024 = 132096
301 ["7fe0|0010", "gdcm::NotLoaded. Address:8192 Length:132096"],
302 # Oddities: "Study ID" and "Series Number" are empty
304 ["Series Number", ""] ] ],
305 # Oddities: "Study" and "Serie Instance UID" are not present
306 ["gdcm-MR-SIEMENS-16.acr2",
307 # Interest: Acr-Nema Version 2
308 [ ["Recognition Code", "ACR-NEMA 2.0"],
312 ["Bits Stored", "12"],
313 ["Bits Allocated", "16"],
315 ["Pixel Representation", "0"],
316 ["Manufacturer", "SIEMENS"],
317 ["Manufacturer Model Name", "MAGNETOM VISION"],
318 ["Study Instance UID",
319 "1.3.12.2.1107.5.2.4.7630.20000918174641000"],
321 ["Series Instance UID",
322 "1.3.12.2.1107.5.2.4.7630.20000918175714000007"],
323 ["Series Number", "7"],
324 ["7fe0|0010", "gdcm::NotLoaded. Address:6052 Length:524288"] ] ],
325 ["gdcm-US-ALOKA-16.dcm",
326 # Interest: - possesses 3 LUTS: a Green (checked), a Red and BLue.
327 # - announced as implicit VR, but really explicit VR.
328 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
330 ["Photometric Interpretation", "PALETTE COLOR"],
331 ["Segmented Green Palette Color LUT Data",
332 "gdcm::NotLoaded. Address:89576 Length:113784"],
335 ["Bits Stored", "16"],
336 ["Bits Allocated", "16"],
338 ["Pixel Representation", "0"],
339 ["Manufacturer", "ALOKA CO., LTD."],
340 ["Manufacturer Model Name", "SSD-4000"],
341 ["7fe0|0010", "gdcm::NotLoaded. Address:258740 Length:614400"] ] ],
342 ["gdcm-MR-PHILIPS-16.dcm",
343 # Interest: - possesses a sequence
344 # - dicom file, with a recognition code of ACR-NEMA1
345 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
346 ["Recognition Code", "ACR-NEMA 1.0"],
348 ["Photometric Interpretation", "MONOCHROME2"],
351 ["Bits Stored", "8"],
352 ["Bits Allocated", "16"],
354 ["Pixel Representation", "0"],
355 ["Manufacturer", "Philips Medical Systems"],
356 ["Manufacturer Model Name", "Gyroscan Intera"],
357 ["Sequence Variant", "OTHER"],
358 ["7fe0|0010", "gdcm::NotLoaded. Address:6584 Length:131072"] ] ],
359 ["gdcm-MR-PHILIPS-16-NonRectPix.dcm",
360 # Interest: - pixels are non rectangular
361 # - private elements are in explicit VR (which is normal)
362 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
364 ["Photometric Interpretation", "MONOCHROME2"],
367 ["Bits Stored", "12"],
368 ["Bits Allocated", "16"],
370 ["Pixel Representation", "0"],
371 ["Manufacturer", "Philips Medical Systems"],
372 ["Manufacturer Model Name", "Gyroscan Intera"],
373 ["Pixel Spacing", "0.487416\\0.194966"],
374 ["7fe0|0010", "gdcm::NotLoaded. Address:5010 Length:20480"] ] ],
375 ["gdcm-CR-DCMTK-16-NonSamplePerPix.dcm",
376 # Interest: - Misses the "Samples Per Pixel" element which prevents
377 # e-film from reading it.
378 # - Misses the Manufacturer related info
379 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
381 ["Photometric Interpretation", "MONOCHROME2"],
384 ["Bits Stored", "8"],
385 ["Bits Allocated", "8"],
387 ["Pixel Representation", "0"],
388 ["Implementation Version Name", "OFFIS_DCMTK_341"],
389 ["7fe0|0010", "gdcm::NotLoaded. Address:740 Length:562500"] ] ],
393 ["gdcm-JPEG-Extended.dcm",
394 # Interest: Jpeg compression [Extended (2,4)]
395 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.51"],
397 ["Photometric Interpretation", "MONOCHROME2"],
400 ["Bits Stored", "12"],
401 ["Bits Allocated", "16"],
403 ["Pixel Representation", "0"],
404 ["Manufacturer", "SIEMENS"],
405 ["Manufacturer Model Name", "Volume Zoom"],
406 ["7fe0|0010", "gdcm::NotLoaded. Address:2946 Length:192218"] ] ],
407 ["MR-MONO2-12-shoulder.dcm",
408 # Interest: Jpeg compression [Lossless, non-hierar. (14)]
409 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.57"],
411 ["Photometric Interpretation", "MONOCHROME2"],
414 ["Bits Stored", "12"],
415 ["Bits Allocated", "16"],
417 ["Pixel Representation", "0"],
418 ["Manufacturer", "Philips Medical Systems"],
419 ["Manufacturer Model Name", "Gyroscan NT"],
420 ["7fe0|0010", "gdcm::NotLoaded. Address:1580 Length:718948"] ] ],
421 ["gdcm-JPEG-LossLess3a.dcm",
422 # Interest: - Jpeg compression [Lossless, hierar., first-order
423 # pred. 14, Select. Val. 1]
424 # - contains a sequence [circa (0008,2112)]
425 # - contains additional data after the pixels ???
426 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"],
428 ["Photometric Interpretation", "MONOCHROME2"],
431 ["Bits Stored", "12"],
432 ["Bits Allocated", "16"],
434 ["Pixel Representation", "0"],
435 ["Manufacturer", "SIEMENS"],
436 ["Manufacturer Model Name", "Volume Zoom"] ] ],
437 # FIXME: the pixel data looks like corrupted. As stated by "od -A d -c"
438 # 0002528 à 177 020 \0 O B \0 \0 ÿ ÿ ÿ ÿ þ ÿ \0 à
439 # 0002544 \0 \0 \0 \0 þ ÿ \0 à 202 ? 003 \0 ÿ Ø ÿ Ã
440 # which we interpret as follows:
441 # - 2528: (à 177, 020 \0) = (0x7fe0, 0x0010) i.e. Pixel Data tag,
442 # - 2532: OB i.e. encapsulated encoded Pixel Data,
443 # - 2534: Two bytes reserved,
444 # - 2536: ÿ ÿ ÿ ÿ = 0xffffffff i.e. data element length is undefined.
445 # - 2540: (þ ÿ, \0 à) = (0xfffe, 0xe000) i.e. basic offset table
447 # - 2544: \0 \0 \0 \0 i.e. offset table as length zero, i.e. no
448 # item value for offset table.
449 # - 2548: (þ ÿ, \0 à) = (0xfffe, 0xe000) i.e. item tag of first
450 # fragment of (encoded) pixel data.
451 # - 2552: 202 ? 003 \0 = 212866 bytes i.e. length of first fragment
452 # of (encoded) pixel data.
453 # and so the next item tag should be found at the 2556+212866 th
454 # octet i.e. at address 215422. But, as stated by od, we find:
455 # 0215408 E u Ö 026 Î É 7 ¬ Ã ¸ ó ¿ ÿ Ù \f °
456 # 0215424 ¶ 016 P Ñ 002 016
457 # and (\f °, ¶ 016) is NOT an OB item TAG which is required to be
458 # present (at least there should be a sequence delimiter), refer to
459 # PS 3.5-2001 page 50.
460 ["gdcm-JPEG-LossLess3b.dcm",
461 # Interest: - Jpeg compression [Lossless, hierar., first-order
462 # pred. 14, Select. Val. 1]
463 # - encoding is sligthly different from LossLess3a.dcm ???
464 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"],
466 ["Photometric Interpretation", "MONOCHROME2"],
469 ["Bits Stored", "15"],
470 ["Bits Allocated", "16"],
472 ["Pixel Representation", "0"],
473 ["Manufacturer", "Philips Medical Systems"],
474 ["Manufacturer Model Name", "Cassette Holder Type 9840 500 35201"],
475 ["7fe0|0010", "gdcm::NotLoaded. Address:3144 Length:4795668"] ] ],
478 def _BaseTest(self, FileSet):
479 for entry in FileSet:
480 fileName = os.path.join(GDCM_DATA_PATH, entry[0])
481 toRead = gdcmHeader(fileName)
482 toRead.LoadElements()
483 valDict = toRead.GetPubElVal()
484 for subEntry in entry[1]:
485 element = subEntry[0]
487 self.assertEqual(valDict[element], value,
488 ("Wrong %s for file %s (got %s, shoud be %s)"
489 % (element,fileName, valDict[element], value)) )
492 gdcmTestCase._BaseTest(self, gdcmTestCase.BarreFiles)
494 def testMultiFram(self):
495 gdcmTestCase._BaseTest(self, gdcmTestCase.MultiFrameFiles)
498 gdcmTestCase._BaseTest(self, gdcmTestCase.GdcmFiles)
501 gdcmTestCase._BaseTest(self, gdcmTestCase.GdcmJpegFiles)
503 if __name__ == '__main__':