3 from gdcmPython import *
4 from vtkgdcmPython import *
6 class gdcmTestCase(unittest.TestCase):
7 # The files whose name starts with a modality (e.g. CR-MONO1-10-chest.dcm)
8 # come from Sebastien Barre's Dicom2 highly recommendable site
9 # http://www.barre.nom.fr/medical/samples/index.html
11 ####################################
12 # CR modality examples:
13 ####################################
14 ["CR-MONO1-10-chest.dcm",
16 #"Transfer Syntax UID" is absent.
19 ["Bits Stored", "10"],
20 ["Bits Allocated", "16"],
22 ["Pixel Representation", "0"],
23 ["Manufacturer", "FUJI PHOTO FILM CO. LTD."],
24 ["Manufacturer's Model Name", "9000"],
25 ["Pixel Data", "gdcm::NotLoaded. Address:776 Length:387200"] ] ],
26 ####################################
27 # CT modality examples:
28 ####################################
29 ["CT-MONO2-16-brain.dcm",
30 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
34 ["Bits Stored", "16"],
35 ["Bits Allocated", "16"],
37 ["Pixel Representation", "1"],
38 ["Manufacturer", "Picker International, Inc."],
39 ["Manufacturer's Model Name", "PQ5000"],
40 ["Pixel Data", "gdcm::NotLoaded. Address:1680 Length:524288"] ] ],
41 ["CT-MONO2-16-ort.dcm",
42 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
46 ["Bits Stored", "16"],
47 ["Bits Allocated", "16"],
49 ["Pixel Representation", "1"],
50 ["Manufacturer", "GE MEDICAL SYSTEMS"],
51 ["Manufacturer's Model Name", "HiSpeed CT/i"],
52 ["Pixel Data", "gdcm::NotLoaded. Address:1674 Length:524288"] ] ],
53 ["CT-MONO2-16-ankle.dcm",
54 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit, little
58 ["Bits Stored", "16"],
59 ["Bits Allocated", "16"],
61 ["Pixel Representation", "1"],
62 ["Manufacturer", "GE MEDICAL SYSTEMS"],
63 ["Manufacturer's Model Name", "GENESIS_ZEUS"],
64 ["Pixel Data", "gdcm::NotLoaded. Address:1148 Length:524288"] ] ],
65 ["CT-MONO2-8-abdo.dcm",
66 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit, little
71 ["Bits Allocated", "8"],
73 ["Pixel Representation", "0"],
74 ["Manufacturer", "FUJI"],
75 ["Pixel Data", "gdcm::NotLoaded. Address:796 Length:262144"] ] ],
76 ["CT-MONO2-12-lomb-an2.acr2",
78 #"Transfer Syntax UID" and "Photometric Interpretation" are absent.
81 ["Bits Stored", "12"],
82 ["Bits Allocated", "16"],
84 ["Pixel Representation", "0"],
85 ["Manufacturer", "SIEMENS"],
86 ["Pixel Data", "gdcm::NotLoaded. Address:1230 Length:524288"] ] ],
87 ["CT-MONO2-16-chest.dcm",
88 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"], # jpeg...
90 ["Photometric Interpretation", "MONOCHROME2"],
93 ["Bits Stored", "16"],
94 ["Bits Allocated", "16"],
96 ["Pixel Representation", "1"],
97 ["Manufacturer", "GE MEDICAL SYSTEMS"],
98 ["Pixel Data", "gdcm::NotLoaded. Address:1638 Length:143498"] ] ],
99 ####################################
100 ### MR modality examples:
101 ####################################
102 ["MR-MONO2-12-angio-an1.acr1",
103 [ ["Recognition Code (RET)", "ACR-NEMA 1.0"],
105 #"Transfer Syntax UID" and "Photometric Interpretation" are absent.
108 ["Bits Stored", "12"],
109 ["Bits Allocated", "12"],
111 ["Pixel Representation", "0"],
112 ["Manufacturer", "Philips"],
113 # Note: 256*256*12/8 = 98304
114 ["Pixel Data", "gdcm::NotLoaded. Address:650 Length:98304"] ] ],
115 ["MR-MONO2-12-an2.acr2",
116 [ ["Modality", "MR"],
117 ["Photometric Interpretation", "MONOCHROME2"],
120 ["Bits Stored", "12"],
121 ["Bits Allocated", "16"],
123 ["Pixel Representation", "0"],
124 ["Manufacturer", "SIEMENS"],
125 ["Manufacturer's Model Name", "MAGNETOM VISION"],
126 ["Pixel Data", "gdcm::NotLoaded. Address:1866 Length:131072"] ] ],
127 ["MR-MONO2-16-head.dcm",
128 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Imp VR, LE
130 ["Photometric Interpretation", "MONOCHROME2"],
133 ["Bits Stored", "16"],
134 ["Bits Allocated", "16"],
136 ["Pixel Representation", "1"],
137 ["Manufacturer", "GE MEDICAL SYSTEMS"],
138 ["Manufacturer's Model Name", "GENESIS_SIGNA"],
139 ["Pixel Data", "gdcm::NotLoaded. Address:1804 Length:131072"] ] ],
140 # MR-MONO2-12-shoulder example is present in the Jpeg section.
141 # MR-MONO2-16-knee is not present in the test suite since it is too
142 # closely related to MR-MONO2-16-head.dcm to be of interest.
143 ####################################
144 # OT modality examples:
145 ####################################
146 # OT-MONO2-8-hip is not present in the test suite since it is too
147 # closely related to OT-MONO2-8-a7 to be of interest.
148 ["OT-PAL-8-face.dcm",
149 # Interest: has a color palette
150 [#"Transfer Syntax UID", and "Manufacturer" are absent.
152 ["Photometric Interpretation", "PALETTE COLOR"],
155 ["Bits Stored", "8"],
156 ["Bits Allocated", "8"],
158 ["Pixel Representation", "0"],
159 ["Pixel Data", "gdcm::NotLoaded. Address:1654 Length:307200"] ] ],
160 # OT-MONO2-8-colon is not present in the test suite since it is too
161 # closely related to OT-MONO2-8-a7 to be of interest.
162 ["OT-MONO2-8-a7.dcm",
163 [#"Transfer Syntax UID" is absent.
165 ["Photometric Interpretation", "MONOCHROME2"],
168 ["Bits Stored", "8"],
169 ["Bits Allocated", "8"],
171 ["Pixel Representation", "0"],
172 ["Manufacturer", "Philips Medical Systems"],
173 ["Pixel Data", "gdcm::NotLoaded. Address:438 Length:262144"] ] ],
174 ####################################
175 # US (Ultra Sound) modality examples:
176 ####################################
177 ["US-RGB-8-esopecho.dcm",
178 # Interest: RGB image
179 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Exp VR, LE
181 ["Photometric Interpretation", "RGB"],
184 ["Bits Stored", "8"],
185 ["Bits Allocated", "8"],
187 ["Pixel Representation", "0"],
188 ["Manufacturer", "Acme Products"],
189 # FIXME: 92160 / (120*256) = 3 bytes per pixel NOT 1. Maybe
190 # it has something to do with [Samples Per Pixel] = [3] ???
191 # You said it, puffy (tu l'as dit, bouffi, in french language)
192 # RGB is 3 bytes per pixel
193 # + Planar configuration (0028,0006) = 0 --> Pixels RGB
194 ["Pixel Data", "gdcm::NotLoaded. Address:904 Length:92160"] ] ],
195 ["US-RGB-8-epicard.dcm",
196 # Interest: Big endian transfert syntax
197 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.2"], # Big endian
198 # But ... group 0000 is LE .
200 ["Photometric Interpretation", "RGB"],
203 ["Bits Stored", "8"],
204 ["Bits Allocated", "8"],
206 ["Pixel Representation", "0"],
207 ["Manufacturer", "G.E. Medical Systems"],
208 ["Manufacturer's Model Name", "LOGIQ 700"],
209 # + Planar configuration (0028,0006) = 1 --> Plane R, Plane G, Plane B
210 ["Implementation Version Name", "OFFIS-DCMTK-311"],
211 ["Pixel Data", "gdcm::NotLoaded. Address:1012 Length:921600"] ] ],
215 # The number of images is contained in the "Number of Frames" element
216 ["MR-MONO2-8-16x-heart.dcm",
217 # Interest: multi-frame
218 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
219 ["Number of Frames", "16"],
221 ["Photometric Interpretation", "MONOCHROME2"],
224 ["Bits Stored", "8"],
225 ["Bits Allocated", "8"],
227 ["Pixel Representation", "0"],
228 ["Manufacturer", "Philips"],
229 # Note: 256*256*16=1048576 (16 is the number of Frames)
230 ["Pixel Data", "gdcm::NotLoaded. Address:920 Length:1048576"] ] ],
231 ["NM-MONO2-16-13x-heart.dcm",
232 # Interest: NM modality, multi-frame
233 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
234 ["Number of Frames", "13"],
236 ["Photometric Interpretation", "MONOCHROME2"],
239 ["Bits Stored", "16"],
240 ["Bits Allocated", "16"],
242 ["Pixel Representation", "0"],
243 ["Manufacturer", "ACME Products"],
244 # Note: 64*64*13*2=106496
245 ["Pixel Data", "gdcm::NotLoaded. Address:1234 Length:106496"] ] ],
246 ["US-MONO2-8-8x-execho.dcm",
247 # Interest: multi-frame
248 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
249 ["Number of Frames", "8"],
251 ["Photometric Interpretation", "MONOCHROME2"],
254 ["Bits Stored", "8"],
255 ["Bits Allocated", "8"],
257 ["Pixel Representation", "0"],
258 ["Manufacturer", "Acme Products"],
259 ["Pixel Data", "gdcm::NotLoaded. Address:976 Length:122880"] ] ],
260 ["US-PAL-8-10x-echo.dcm",
261 # Interest: RLE (Run Length Encoded) compression, multiframe
262 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.5"], # RLE
263 ["Number of Frames", "10"],
265 ["Photometric Interpretation", "PALETTE COLOR"],
268 ["Bits Stored", "8"],
269 ["Bits Allocated", "8"],
271 ["Pixel Representation", "0"],
272 ["Manufacturer", "ACME Products"],
273 ["Pixel Data", "gdcm::NotLoaded. Address:2428 Length:481182"] ] ],
274 ["XA-MONO2-8-12x-catheter.dcm",
275 # Interest: XA modality, multi-frame
276 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"], # jpeg
277 ["Number of Frames", "12"], # 12 images
279 ["Photometric Interpretation", "MONOCHROME2"],
282 ["Bits Stored", "8"],
283 ["Bits Allocated", "8"],
285 ["Pixel Representation", "0"],
286 ["Manufacturer", "Acme Products"],
287 ["Pixel Data", "gdcm::NotLoaded. Address:1006 Length:920072"] ] ],
291 ["gdcm-MR-SIEMENS-16.acr1",
292 # Interest: good old Acr-Nema Version 1, see also Oddities below
293 [ ["Recognition Code (RET)", "ACR-NEMA 1.0"],
297 ["Bits Stored", "12"],
298 ["Bits Allocated", "16"],
300 ["Pixel Representation", "0"],
301 ["Manufacturer", "SIEMENS"],
302 ["Manufacturer's Model Name", "GBS III"],
303 # FIXME: this image looks padded at the end. The length of the file
304 # is 140288. Notice that, 256*256*2 + 1024 = 131072 + 1024 = 132096
305 ["Pixel Data", "gdcm::NotLoaded. Address:8192 Length:132096"],
306 # Oddities: "Study ID" and "Series Number" are empty
308 ["Series Number", ""] ] ],
309 # Oddities: "Study" and "Serie Instance UID" are not present
310 ["gdcm-MR-SIEMENS-16.acr2",
311 # Interest: Acr-Nema Version 2
312 [ ["Recognition Code (RET)", "ACR-NEMA 2.0"],
316 ["Bits Stored", "12"],
317 ["Bits Allocated", "16"],
319 ["Pixel Representation", "0"],
320 ["Manufacturer", "SIEMENS"],
321 ["Manufacturer's Model Name", "MAGNETOM VISION"],
322 ["Study Instance UID",
323 "1.3.12.2.1107.5.2.4.7630.20000918174641000"],
325 ["Series Instance UID",
326 "1.3.12.2.1107.5.2.4.7630.20000918175714000007"],
327 ["Series Number", "7"],
328 ["Pixel Data", "gdcm::NotLoaded. Address:6052 Length:524288"] ] ],
329 ["gdcm-US-ALOKA-16.dcm",
330 # Interest: - possesses 3 LUTS: a Green (checked), a Red and BLue.
331 # - announced as implicit VR, but really explicit VR.
332 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
334 ["Photometric Interpretation", "PALETTE COLOR"],
335 ["Segmented Green Palette Color Lookup Table Data",
336 "gdcm::NotLoaded. Address:89576 Length:113784"],
339 ["Bits Stored", "16"],
340 ["Bits Allocated", "16"],
342 ["Pixel Representation", "0"],
343 ["Manufacturer", "ALOKA CO., LTD."],
344 ["Manufacturer's Model Name", "SSD-4000"],
345 ["Pixel Data", "gdcm::NotLoaded. Address:258740 Length:614400"] ] ],
346 ["gdcm-MR-PHILIPS-16.dcm",
347 # Interest: - possesses a sequence
348 # - dicom file, with a recognition code of ACR-NEMA1
349 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
350 ["Recognition Code (RET)", "ACR-NEMA 1.0"],
352 ["Photometric Interpretation", "MONOCHROME2"],
355 ["Bits Stored", "8"],
356 ["Bits Allocated", "16"],
358 ["Pixel Representation", "0"],
359 ["Manufacturer", "Philips Medical Systems"],
360 ["Manufacturer's Model Name", "Gyroscan Intera"],
361 ["Sequence Variant", "OTHER"],
362 ["Pixel Data", "gdcm::NotLoaded. Address:6584 Length:131072"] ] ],
363 ["gdcm-MR-PHILIPS-16-Multi-Seq.dcm",
364 # Interest: - possesses many sequences in group 0x0029
365 # - Big sequence 28808 bytes at (0x0029, 0x263d)
366 # - dicom file, with a recognition code of ACR-NEMA1
367 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"],
368 ["Recognition Code (RET)", "ACR-NEMA 1.0"],
370 ["Photometric Interpretation", "MONOCHROME2"],
373 ["Bits Stored", "12"],
374 ["Bits Allocated", "16"],
376 ["Pixel Representation", "0"],
377 ["Manufacturer", "Philips Medical Systems"],
378 ["Manufacturer's Model Name", "Gyroscan Intera"],
379 ["Sequence Variant", "OTHER"],
380 ["Pixel Data", "gdcm::NotLoaded. Address:35846 Length:32768"] ] ],
381 ["gdcm-MR-PHILIPS-16-NonRectPix.dcm",
382 # Interest: - pixels are non rectangular
383 # - private elements are in explicit VR (which is normal)
384 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
386 ["Photometric Interpretation", "MONOCHROME2"],
389 ["Bits Stored", "12"],
390 ["Bits Allocated", "16"],
392 ["Pixel Representation", "0"],
393 ["Manufacturer", "Philips Medical Systems"],
394 ["Manufacturer's Model Name", "Gyroscan Intera"],
395 ["Pixel Spacing", "0.487416\\0.194966"],
396 ["Pixel Data", "gdcm::NotLoaded. Address:5010 Length:20480"] ] ],
397 ["gdcm-CR-DCMTK-16-NonSamplePerPix.dcm",
398 # Interest: - Misses the "Samples Per Pixel" element which prevents
399 # e-film from reading it.
400 # - Misses the Manufacturer related info
401 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
403 ["Photometric Interpretation", "MONOCHROME2"],
406 ["Bits Stored", "8"],
407 ["Bits Allocated", "8"],
409 ["Pixel Representation", "0"],
410 ["Implementation Version Name", "OFFIS_DCMTK_341"],
411 ["Pixel Data", "gdcm::NotLoaded. Address:740 Length:562500"] ] ],
415 ["gdcm-JPEG-Extended.dcm",
416 # Interest: Jpeg compression [Extended (2,4)]
417 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.51"],
419 ["Photometric Interpretation", "MONOCHROME2"],
422 ["Bits Stored", "12"],
423 ["Bits Allocated", "16"],
425 ["Pixel Representation", "0"],
426 ["Manufacturer", "SIEMENS"],
427 ["Manufacturer's Model Name", "Volume Zoom"],
428 ["Pixel Data", "gdcm::NotLoaded. Address:2946 Length:192218"] ] ],
429 ["MR-MONO2-12-shoulder.dcm",
430 # Interest: Jpeg compression [Lossless, non-hierar. (14)]
431 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.57"],
433 ["Photometric Interpretation", "MONOCHROME2"],
436 ["Bits Stored", "12"],
437 ["Bits Allocated", "16"],
439 ["Pixel Representation", "0"],
440 ["Manufacturer", "Philips Medical Systems"],
441 ["Manufacturer's Model Name", "Gyroscan NT"],
442 ["Pixel Data", "gdcm::NotLoaded. Address:1580 Length:718948"] ] ],
443 ["gdcm-JPEG-LossLess3a.dcm",
444 # Interest: - Jpeg compression [Lossless, hierar., first-order
445 # pred. 14, Select. Val. 1]
446 # - contains a sequence [circa (0008,2112)]
447 # - contains additional data after the pixels ???
448 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"],
450 ["Photometric Interpretation", "MONOCHROME2"],
453 ["Bits Stored", "12"],
454 ["Bits Allocated", "16"],
456 ["Pixel Representation", "0"],
457 ["Manufacturer", "SIEMENS"],
458 ["Manufacturer's Model Name", "Volume Zoom"] ] ],
459 # FIXME: the pixel data looks like corrupted. As stated by "od -A d -c"
460 # 0002528 à 177 020 \0 O B \0 \0 ÿ ÿ ÿ ÿ þ ÿ \0 à
461 # 0002544 \0 \0 \0 \0 þ ÿ \0 à 202 ? 003 \0 ÿ Ø ÿ Ã
462 # which we interpret as follows:
463 # - 2528: (à 177, 020 \0) = (0x7fe0, 0x0010) i.e. Pixel Data tag,
464 # - 2532: OB i.e. encapsulated encoded Pixel Data,
465 # - 2534: Two bytes reserved,
466 # - 2536: ÿ ÿ ÿ ÿ = 0xffffffff i.e. data element length is undefined.
467 # - 2540: (þ ÿ, \0 à) = (0xfffe, 0xe000) i.e. basic offset table
469 # - 2544: \0 \0 \0 \0 i.e. offset table as length zero, i.e. no
470 # item value for offset table.
471 # - 2548: (þ ÿ, \0 à) = (0xfffe, 0xe000) i.e. item tag of first
472 # fragment of (encoded) pixel data.
473 # - 2552: 202 ? 003 \0 = 212866 bytes i.e. length of first fragment
474 # of (encoded) pixel data.
475 # and so the next item tag should be found at the 2556+212866 th
476 # octet i.e. at address 215422. But, as stated by od, we find:
477 # 0215408 E u Ö 026 Î É 7 ¬ Ã ¸ ó ¿ ÿ Ù \f °
478 # 0215424 ¶ 016 P Ñ 002 016
479 # and (\f °, ¶ 016) is NOT an OB item TAG which is required to be
480 # present (at least there should be a sequence delimiter), refer to
481 # PS 3.5-2001 page 50.
484 # at 9ec : ItemTag : fffe,e000
485 # at 9f0 : Basic Offset Table Item Lentgh (??) 0 x(00000000)
486 # at 9f4 : ItemTag : fffe,e000
487 # at 9f8 : fragment length 212866 x(00033f82)
488 # at 3497e : ItemTag b00c,0eb6 (should be fffe,e000 or fffe,e0dd):
490 ["gdcm-JPEG-LossLessThoravision.dcm",
491 # Interest: - Jpeg compression [Lossless, hierar., first-order
492 # pred. 14, Select. Val. 1]
493 # - encoding is sligthly different from LossLess3a.dcm ???
494 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"],
496 ["Photometric Interpretation", "MONOCHROME2"],
499 ["Bits Stored", "15"],
500 ["Bits Allocated", "16"],
502 ["Pixel Representation", "0"],
503 ["Manufacturer", "Philips Medical Systems"],
504 ["Manufacturer's Model Name", "Cassette Holder Type 9840 500 35201"],
505 ["Pixel Data", "gdcm::NotLoaded. Address:3144 Length:4795668"] ] ],
508 def _BaseTest(self, FileSet):
509 for entry in FileSet:
510 fileName = os.path.join(GDCM_TEST_DATA_PATH, entry[0])
511 toRead = gdcmHeader(fileName)
512 valDict = toRead.GetPubElVal()
513 for subEntry in entry[1]:
514 element = subEntry[0]
516 self.assertEqual(valDict[element], value,
517 ("Wrong %s for file %s (got %s, shoud be %s)"
518 % (element,fileName, valDict[element], value)) )
521 gdcmTestCase._BaseTest(self, gdcmTestCase.BarreFiles)
523 def testMultiFram(self):
524 gdcmTestCase._BaseTest(self, gdcmTestCase.MultiFrameFiles)
527 gdcmTestCase._BaseTest(self, gdcmTestCase.GdcmFiles)
530 gdcmTestCase._BaseTest(self, gdcmTestCase.GdcmJpegFiles)
534 SourceFileName = os.path.join(GDCM_TEST_DATA_PATH,
535 'gdcm-MR-PHILIPS-16-Multi-Seq.dcm')
536 Source = gdcmFile(SourceFileName);
537 Source.GetImageData()
538 TargetFileName = "junk"
539 Target = Source.WriteDcmImplVR(TargetFileName)
540 Sign = 'c3d27238647b7eaa773bff6ea0692b54'
541 ComputeSign = md5.new(open(TargetFileName).read()).hexdigest()
542 self.assertEqual(ComputeSign, Sign,
543 ("Wrong signature for file %s (got %s, shoud be %s)"
544 % (SourceFileName, ComputeSign, Sign)) )
545 os.unlink(TargetFileName)
547 if __name__ == '__main__':
548 if not GDCM_TEST_DATA_PATH:
549 print "GDCM_TEST_DATA_PATH (internal variable) is not setup properly."
550 print " This test suite requires that some Dicom reference files be "
552 print " For further details on installation of gdcmData, please"
553 print " refer to the developper's section of page "
554 print " http://www.creatis.insa-lyon.fr/Public/Gdcm"
556 print "gdcmData directory (used in the test suite) must be placed in"
557 print "the gdcm directory. The gdcm tree must be :"
561 print " |____gdcmData (not in gdcm by default)"
562 print " |____gdcmPython"