3 from gdcmPython import *
5 from libvtkgdcmPython import *
7 from vtkgdcmPython import *
9 class gdcmTestCase(unittest.TestCase):
10 # The files whose name starts with a modality (e.g. CR-MONO1-10-chest.dcm)
11 # come from Sebastien Barre's Dicom2 highly recommendable site
12 # http://www.barre.nom.fr/medical/samples/index.html
14 ####################################
15 # CR modality examples:
16 ####################################
17 ["CR-MONO1-10-chest.dcm",
19 #"Transfer Syntax UID" is absent.
22 ["Bits Stored", "10"],
23 ["Bits Allocated", "16"],
25 ["Pixel Representation", "0"],
26 ["Manufacturer", "FUJI PHOTO FILM CO. LTD."],
27 ["Manufacturer's Model Name", "9000"],
28 ["Pixel Data", "gdcm::NotLoaded. Address:776 Length:387200 x(5e880)"]
30 ####################################
31 # CT modality examples:
32 ####################################
33 ["CT-MONO2-16-brain.dcm",
34 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
38 ["Bits Stored", "16"],
39 ["Bits Allocated", "16"],
41 ["Pixel Representation", "1"],
42 ["Manufacturer", "Picker International, Inc."],
43 ["Manufacturer's Model Name", "PQ5000"],
44 ["Pixel Data", "gdcm::NotLoaded. Address:1680 Length:524288 x(80000)"]
46 ["CT-MONO2-16-ort.dcm",
47 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
51 ["Bits Stored", "16"],
52 ["Bits Allocated", "16"],
54 ["Pixel Representation", "1"],
55 ["Manufacturer", "GE MEDICAL SYSTEMS"],
56 ["Manufacturer's Model Name", "HiSpeed CT/i"],
57 ["Pixel Data", "gdcm::NotLoaded. Address:1674 Length:524288 x(80000)"]
59 ["CT-MONO2-16-ankle.dcm",
60 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit, little
64 ["Bits Stored", "16"],
65 ["Bits Allocated", "16"],
67 ["Pixel Representation", "1"],
68 ["Manufacturer", "GE MEDICAL SYSTEMS"],
69 ["Manufacturer's Model Name", "GENESIS_ZEUS"],
70 ["Pixel Data", "gdcm::NotLoaded. Address:1148 Length:524288 x(80000)"]
72 ["CT-MONO2-8-abdo.dcm",
73 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit, little
78 ["Bits Allocated", "8"],
80 ["Pixel Representation", "0"],
81 ["Manufacturer", "FUJI"],
82 ["Pixel Data", "gdcm::NotLoaded. Address:796 Length:262144 x(40000)"]
84 ["CT-MONO2-12-lomb-an2.acr",
86 #"Transfer Syntax UID" and "Photometric Interpretation" are absent.
89 ["Bits Stored", "12"],
90 ["Bits Allocated", "16"],
92 ["Pixel Representation", "0"],
93 ["Manufacturer", "SIEMENS"],
94 ["Pixel Data", "gdcm::NotLoaded. Address:1230 Length:524288 x(80000)"]
96 ["CT-MONO2-16-chest.dcm",
97 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"], # jpeg...
99 ["Photometric Interpretation", "MONOCHROME2"],
102 ["Bits Stored", "16"],
103 ["Bits Allocated", "16"],
105 ["Pixel Representation", "1"],
106 ["Manufacturer", "GE MEDICAL SYSTEMS"],
107 ["Pixel Data", "gdcm::NotLoaded. Address:1638 Length:143498 x(2308a)"]
109 ####################################
110 ### MR modality examples:
111 ####################################
112 ["MR-MONO2-12-angio-an1.acr",
113 [ ["Recognition Code (RET)", "ACR-NEMA 1.0"],
115 #"Transfer Syntax UID" and "Photometric Interpretation" are absent.
118 ["Bits Stored", "12"],
119 ["Bits Allocated", "12"],
121 ["Pixel Representation", "0"],
122 ["Manufacturer", "Philips"],
123 # Note: 256*256*12/8 = 98304
124 ["Pixel Data", "gdcm::NotLoaded. Address:650 Length:98304 x(18000)"]
126 ["MR-MONO2-12-an2.acr",
127 [ ["Modality", "MR"],
128 ["Photometric Interpretation", "MONOCHROME2"],
131 ["Bits Stored", "12"],
132 ["Bits Allocated", "16"],
134 ["Pixel Representation", "0"],
135 ["Manufacturer", "SIEMENS"],
136 ["Manufacturer's Model Name", "MAGNETOM VISION"],
137 ["Pixel Data", "gdcm::NotLoaded. Address:1866 Length:131072 x(20000)"]
139 ["MR-MONO2-16-head.dcm",
140 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Imp VR, LE
142 ["Photometric Interpretation", "MONOCHROME2"],
145 ["Bits Stored", "16"],
146 ["Bits Allocated", "16"],
148 ["Pixel Representation", "1"],
149 ["Manufacturer", "GE MEDICAL SYSTEMS"],
150 ["Manufacturer's Model Name", "GENESIS_SIGNA"],
151 ["Pixel Data", "gdcm::NotLoaded. Address:1804 Length:131072 x(20000)"]
153 # MR-MONO2-12-shoulder example is present in the Jpeg section.
154 # MR-MONO2-16-knee is not present in the test suite since it is too
155 # closely related to MR-MONO2-16-head.dcm to be of interest.
156 ####################################
157 # OT modality examples:
158 ####################################
159 # OT-MONO2-8-hip 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-PAL-8-face.dcm",
162 # Interest: has a color palette
163 [#"Transfer Syntax UID", and "Manufacturer" are absent.
165 ["Photometric Interpretation", "PALETTE COLOR"],
168 ["Bits Stored", "8"],
169 ["Bits Allocated", "8"],
171 ["Pixel Representation", "0"],
172 ["Pixel Data", "gdcm::NotLoaded. Address:1654 Length:307200 x(4b000)"]
174 # OT-MONO2-8-colon is not present in the test suite since it is too
175 # closely related to OT-MONO2-8-a7 to be of interest.
176 ["OT-MONO2-8-a7.dcm",
177 [#"Transfer Syntax UID" is absent.
179 ["Photometric Interpretation", "MONOCHROME2"],
182 ["Bits Stored", "8"],
183 ["Bits Allocated", "8"],
185 ["Pixel Representation", "0"],
186 ["Manufacturer", "Philips Medical Systems"],
187 ["Pixel Data", "gdcm::NotLoaded. Address:438 Length:262144 x(40000)"]
189 ####################################
190 # US (Ultra Sound) modality examples:
191 ####################################
192 ["US-RGB-8-esopecho.dcm",
193 # Interest: RGB image
194 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Exp VR, LE
196 ["Photometric Interpretation", "RGB"],
199 ["Bits Stored", "8"],
200 ["Bits Allocated", "8"],
202 ["Pixel Representation", "0"],
203 ["Manufacturer", "Acme Products"],
204 # FIXME: 92160 / (120*256) = 3 bytes per pixel NOT 1. Maybe
205 # it has something to do with [Samples Per Pixel] = [3] ???
206 # You said it, puffy (tu l'as dit, bouffi, in french language)
207 # RGB is 3 bytes per pixel
208 # + Planar configuration (0028,0006) = 0 --> Pixels RGB
209 ["Pixel Data", "gdcm::NotLoaded. Address:904 Length:92160 x(16800)"]
211 ["US-RGB-8-epicard.dcm",
212 # Interest: Big endian transfert syntax
213 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.2"], # Big endian
214 # But ... group 0000 is LE .
216 ["Photometric Interpretation", "RGB"],
219 ["Bits Stored", "8"],
220 ["Bits Allocated", "8"],
222 ["Pixel Representation", "0"],
223 ["Manufacturer", "G.E. Medical Systems"],
224 ["Manufacturer's Model Name", "LOGIQ 700"],
225 # + Planar configuration (0028,0006) = 1 --> Plane R, Plane G, Plane B
226 ["Implementation Version Name", "OFFIS-DCMTK-311"],
227 ["Pixel Data", "gdcm::NotLoaded. Address:1012 Length:921600 x(e1000)"]
232 # The number of images is contained in the "Number of Frames" element
233 ["MR-MONO2-8-16x-heart.dcm",
234 # Interest: multi-frame
235 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
236 ["Number of Frames", "16"],
238 ["Photometric Interpretation", "MONOCHROME2"],
241 ["Bits Stored", "8"],
242 ["Bits Allocated", "8"],
244 ["Pixel Representation", "0"],
245 ["Manufacturer", "Philips"],
246 # Note: 256*256*16=1048576 (16 is the number of Frames)
247 ["Pixel Data", "gdcm::NotLoaded. Address:920 Length:1048576 x(100000)"]
249 ["NM-MONO2-16-13x-heart.dcm",
250 # Interest: NM modality, multi-frame
251 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
252 ["Number of Frames", "13"],
254 ["Photometric Interpretation", "MONOCHROME2"],
257 ["Bits Stored", "16"],
258 ["Bits Allocated", "16"],
260 ["Pixel Representation", "0"],
261 ["Manufacturer", "ACME Products"],
262 # Note: 64*64*13*2=106496
263 ["Pixel Data", "gdcm::NotLoaded. Address:1234 Length:106496 x(1a000)"]
265 ["US-MONO2-8-8x-execho.dcm",
266 # Interest: multi-frame
267 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
268 ["Number of Frames", "8"],
270 ["Photometric Interpretation", "MONOCHROME2"],
273 ["Bits Stored", "8"],
274 ["Bits Allocated", "8"],
276 ["Pixel Representation", "0"],
277 ["Manufacturer", "Acme Products"],
278 ["Pixel Data", "gdcm::NotLoaded. Address:976 Length:122880 x(1e000)"]
280 ["US-PAL-8-10x-echo.dcm",
281 # Interest: RLE (Run Length Encoded) compression, multiframe
282 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.5"], # RLE
283 ["Number of Frames", "10"],
285 ["Photometric Interpretation", "PALETTE COLOR"],
288 ["Bits Stored", "8"],
289 ["Bits Allocated", "8"],
291 ["Pixel Representation", "0"],
292 ["Manufacturer", "ACME Products"],
293 ["Pixel Data", "gdcm::NotLoaded. Address:2428 Length:481182 x(7579e)"]
295 ["XA-MONO2-8-12x-catheter.dcm",
296 # Interest: XA modality, multi-frame
297 [ #["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"], # jpeg
298 ["Number of Frames", "12"], # 12 images
300 ["Photometric Interpretation", "MONOCHROME2"],
303 ["Bits Stored", "8"],
304 ["Bits Allocated", "8"],
306 ["Pixel Representation", "0"],
307 ["Manufacturer", "Acme Products"],
308 ["Pixel Data", "gdcm::NotLoaded. Address:1006 Length:920072 x(e0a08)"]
313 ["gdcm-MR-SIEMENS-16-1.acr",
314 # Interest: good old Acr-Nema Version 1, see also Oddities below
315 [ ["Recognition Code (RET)", "ACR-NEMA 1.0"],
319 ["Bits Stored", "12"],
320 ["Bits Allocated", "16"],
322 ["Pixel Representation", "0"],
323 ["Manufacturer", "SIEMENS"],
324 ["Manufacturer's Model Name", "GBS III"],
325 # FIXME: this image looks padded at the end. The length of the file
326 # is 140288. Notice that, 256*256*2 + 1024 = 131072 + 1024 = 132096
327 ["Pixel Data", "gdcm::NotLoaded. Address:8192 Length:132096 x(20400)"],
328 # Oddities: "Study ID" and "Series Number" are empty
330 ["Series Number", ""] ] ],
331 # Oddities: "Study" and "Serie Instance UID" are not present
332 ["gdcm-MR-SIEMENS-16-2.acr",
333 # Interest: Acr-Nema Version 2
334 [ ["Recognition Code (RET)", "ACR-NEMA 2.0"],
338 ["Bits Stored", "12"],
339 ["Bits Allocated", "16"],
341 ["Pixel Representation", "0"],
342 ["Manufacturer", "SIEMENS"],
343 ["Manufacturer's Model Name", "MAGNETOM VISION"],
344 ["Study Instance UID",
345 "1.3.12.2.1107.5.2.4.7630.20000918174641000"],
347 ["Series Instance UID",
348 "1.3.12.2.1107.5.2.4.7630.20000918175714000007"],
349 ["Series Number", "7"],
350 ["Pixel Data", "gdcm::NotLoaded. Address:6052 Length:524288 x(80000)"]
352 ["gdcm-US-ALOKA-16.dcm",
353 # Interest: - possesses 3 LUTS: a Green (checked), a Red and BLue.
354 # - announced as implicit VR, but really explicit VR.
355 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
357 ["Photometric Interpretation", "PALETTE COLOR"],
358 ["Segmented Green Palette Color Lookup Table Data",
359 "gdcm::NotLoaded. Address:89576 Length:113784 x(1bc78)"],
362 ["Bits Stored", "16"],
363 ["Bits Allocated", "16"],
365 ["Pixel Representation", "0"],
366 ["Manufacturer", "ALOKA CO., LTD."],
367 ["Manufacturer's Model Name", "SSD-4000"],
368 ["Pixel Data", "gdcm::NotLoaded. Address:258740 Length:614400 x(96000)"]
370 ["gdcm-MR-PHILIPS-16.dcm",
371 # Interest: - possesses a sequence
372 # - dicom file, with a recognition code of ACR-NEMA1
373 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
374 ["Recognition Code (RET)", "ACR-NEMA 1.0"],
376 ["Photometric Interpretation", "MONOCHROME2"],
379 ["Bits Stored", "8"],
380 ["Bits Allocated", "16"],
382 ["Pixel Representation", "0"],
383 ["Manufacturer", "Philips Medical Systems"],
384 ["Manufacturer's Model Name", "Gyroscan Intera"],
385 ["Sequence Variant", "OTHER"],
386 ["Pixel Data", "gdcm::NotLoaded. Address:6584 Length:131072 x(20000)"]
388 ["gdcm-MR-PHILIPS-16-Multi-Seq.dcm",
389 # Interest: - possesses many sequences in group 0x0029
390 # - Big sequence 28808 bytes at (0x0029, 0x263d)
391 # - dicom file, with a recognition code of ACR-NEMA1
392 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"],
393 ["Recognition Code (RET)", "ACR-NEMA 1.0"],
395 ["Photometric Interpretation", "MONOCHROME2"],
398 ["Bits Stored", "12"],
399 ["Bits Allocated", "16"],
401 ["Pixel Representation", "0"],
402 ["Manufacturer", "Philips Medical Systems"],
403 ["Manufacturer's Model Name", "Gyroscan Intera"],
404 ["Sequence Variant", "OTHER"],
405 ["Pixel Data", "gdcm::NotLoaded. Address:35846 Length:32768 x(8000)"]
407 ["gdcm-MR-PHILIPS-16-NonRectPix.dcm",
408 # Interest: - pixels are non rectangular
409 # - private elements are in explicit VR (which is normal)
410 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
412 ["Photometric Interpretation", "MONOCHROME2"],
415 ["Bits Stored", "12"],
416 ["Bits Allocated", "16"],
418 ["Pixel Representation", "0"],
419 ["Manufacturer", "Philips Medical Systems"],
420 ["Manufacturer's Model Name", "Gyroscan Intera"],
421 ["Pixel Spacing", "0.487416\\0.194966"],
422 ["Pixel Data", "gdcm::NotLoaded. Address:5010 Length:20480 x(5000)"]
424 ["gdcm-CR-DCMTK-16-NonSamplePerPix.dcm",
425 # Interest: - Misses the "Samples Per Pixel" element which prevents
426 # e-film from reading it.
427 # - Misses the Manufacturer related info
428 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
430 ["Photometric Interpretation", "MONOCHROME2"],
433 ["Bits Stored", "8"],
434 ["Bits Allocated", "8"],
436 ["Pixel Representation", "0"],
437 ["Implementation Version Name", "OFFIS_DCMTK_341"],
438 ["Pixel Data", "gdcm::NotLoaded. Address:740 Length:562500 x(89544)"]
443 ["gdcm-JPEG-Extended.dcm",
444 # Interest: Jpeg compression [Extended (2,4)]
445 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.51"],
447 ["Photometric Interpretation", "MONOCHROME2"],
450 ["Bits Stored", "12"],
451 ["Bits Allocated", "16"],
453 ["Pixel Representation", "0"],
454 ["Manufacturer", "SIEMENS"],
455 ["Manufacturer's Model Name", "Volume Zoom"],
456 ["Pixel Data", "gdcm::NotLoaded. Address:2946 Length:192218 x(2eeda)"]
458 ["MR-MONO2-12-shoulder.dcm",
459 # Interest: Jpeg compression [Lossless, non-hierar. (14)]
460 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.57"],
462 ["Photometric Interpretation", "MONOCHROME2"],
465 ["Bits Stored", "12"],
466 ["Bits Allocated", "16"],
468 ["Pixel Representation", "0"],
469 ["Manufacturer", "Philips Medical Systems"],
470 ["Manufacturer's Model Name", "Gyroscan NT"],
471 ["Pixel Data", "gdcm::NotLoaded. Address:1580 Length:718948 x(af864)"]
473 ["gdcm-JPEG-LossLess3a.dcm",
474 # Interest: - Jpeg compression [Lossless, hierar., first-order
475 # pred. 14, Select. Val. 1]
476 # - contains a sequence [circa (0008,2112)]
477 # - contains additional data after the pixels ???
478 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"],
480 ["Photometric Interpretation", "MONOCHROME2"],
483 ["Bits Stored", "12"],
484 ["Bits Allocated", "16"],
486 ["Pixel Representation", "0"],
487 ["Manufacturer", "SIEMENS"],
488 ["Manufacturer's Model Name", "Volume Zoom"] ] ],
489 # FIXME: the pixel data looks like corrupted. As stated by "od -A d -c"
490 # 0002528 à 177 020 \0 O B \0 \0 ÿ ÿ ÿ ÿ þ ÿ \0 à
491 # 0002544 \0 \0 \0 \0 þ ÿ \0 à 202 ? 003 \0 ÿ Ø ÿ Ã
492 # which we interpret as follows:
493 # - 2528: (à 177, 020 \0) = (0x7fe0, 0x0010) i.e. Pixel Data tag,
494 # - 2532: OB i.e. encapsulated encoded Pixel Data,
495 # - 2534: Two bytes reserved,
496 # - 2536: ÿ ÿ ÿ ÿ = 0xffffffff i.e. data element length is undefined.
497 # - 2540: (þ ÿ, \0 à) = (0xfffe, 0xe000) i.e. basic offset table
499 # - 2544: \0 \0 \0 \0 i.e. offset table as length zero, i.e. no
500 # item value for offset table.
501 # - 2548: (þ ÿ, \0 à) = (0xfffe, 0xe000) i.e. item tag of first
502 # fragment of (encoded) pixel data.
503 # - 2552: 202 ? 003 \0 = 212866 bytes i.e. length of first fragment
504 # of (encoded) pixel data.
505 # and so the next item tag should be found at the 2556+212866 th
506 # octet i.e. at address 215422. But, as stated by od, we find:
507 # 0215408 E u Ö 026 Î É 7 ¬ Ã ¸ ó ¿ ÿ Ù \f °
508 # 0215424 ¶ 016 P Ñ 002 016
509 # and (\f °, ¶ 016) is NOT an OB item TAG which is required to be
510 # present (at least there should be a sequence delimiter), refer to
511 # PS 3.5-2001 page 50.
514 # at 9ec : ItemTag : fffe,e000
515 # at 9f0 : Basic Offset Table Item Lentgh (??) 0 x(00000000)
516 # at 9f4 : ItemTag : fffe,e000
517 # at 9f8 : fragment length 212866 x(00033f82)
518 # at 3497e : ItemTag b00c,0eb6 (should be fffe,e000 or fffe,e0dd):
520 ["gdcm-JPEG-LossLessThoravision.dcm",
521 # Interest: - Jpeg compression [Lossless, hierar., first-order
522 # pred. 14, Select. Val. 1]
523 # - encoding is sligthly different from LossLess3a.dcm ???
524 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"],
526 ["Photometric Interpretation", "MONOCHROME2"],
529 ["Bits Stored", "15"],
530 ["Bits Allocated", "16"],
532 ["Pixel Representation", "0"],
533 ["Manufacturer", "Philips Medical Systems"],
534 ["Manufacturer's Model Name", "Cassette Holder Type 9840 500 35201"],
535 ["Pixel Data", "gdcm::NotLoaded. Address:3144 Length:4795668 x(492d14)"]
539 def _BaseTest(self, FileSet):
540 for entry in FileSet:
541 fileName = os.path.join(GDCM_TEST_DATA_PATH, entry[0])
542 reader = gdcmHeader(fileName)
543 assert reader.IsReadable(),\
544 "File '%s' is not readable by gdcmHeader" % fileName
546 valDict = reader.GetEntry()
547 for subEntry in entry[1]:
548 element = subEntry[0]
550 self.assertEqual(valDict[element], value,
551 ("Wrong %s for file %s (got %s, shoud be %s)"
552 % (element,fileName, valDict[element], value)) )
555 gdcmTestCase._BaseTest(self, gdcmTestCase.BarreFiles)
557 def testMultiFram(self):
558 gdcmTestCase._BaseTest(self, gdcmTestCase.MultiFrameFiles)
561 gdcmTestCase._BaseTest(self, gdcmTestCase.GdcmFiles)
564 gdcmTestCase._BaseTest(self, gdcmTestCase.GdcmJpegFiles)
566 def ZOBtestWrite(self):
568 SourceFileName = os.path.join(GDCM_TEST_DATA_PATH,
569 'gdcm-MR-PHILIPS-16-Multi-Seq.dcm')
570 Source = gdcmFile(SourceFileName);
571 Source.GetImageData()
572 TargetFileName = "junk"
573 Target = Source.WriteDcmImplVR(TargetFileName)
574 # Sign = 'a1e2abdc2f6abedd86b93c8b88db5203' # new signature (found on Win)
575 Sign = '849e722e004d3bb37b87ab6006509b8f' # new signature without field strip
576 ComputeSign = md5.new(open(TargetFileName).read()).hexdigest()
577 self.assertEqual(ComputeSign, Sign,
578 ("Wrong signature for file %s (got %s, shoud be %s)"
579 % (SourceFileName, ComputeSign, Sign)) )
580 os.unlink(TargetFileName)
582 if __name__ == '__main__':
583 if not GDCM_TEST_DATA_PATH:
584 print "GDCM_TEST_DATA_PATH (internal variable) is not setup properly."
585 print " This test suite requires that some Dicom reference files be "
587 print " For further details on installation of gdcmData, please"
588 print " refer to the developper's section of page "
589 print " http://www.creatis.insa-lyon.fr/Public/Gdcm"
591 print "gdcmData directory (used in the test suite) must be placed in"
592 print "the gdcm directory. The gdcm tree must be :"
596 print " |____gdcmData (not in gdcm by default)"
597 print " |____gdcmPython"