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 x(5e880)"]
27 ####################################
28 # CT modality examples:
29 ####################################
30 ["CT-MONO2-16-brain.dcm",
31 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
35 ["Bits Stored", "16"],
36 ["Bits Allocated", "16"],
38 ["Pixel Representation", "1"],
39 ["Manufacturer", "Picker International, Inc."],
40 ["Manufacturer's Model Name", "PQ5000"],
41 ["Pixel Data", "gdcm::NotLoaded. Address:1680 Length:524288 x(80000)"]
43 ["CT-MONO2-16-ort.dcm",
44 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
48 ["Bits Stored", "16"],
49 ["Bits Allocated", "16"],
51 ["Pixel Representation", "1"],
52 ["Manufacturer", "GE MEDICAL SYSTEMS"],
53 ["Manufacturer's Model Name", "HiSpeed CT/i"],
54 ["Pixel Data", "gdcm::NotLoaded. Address:1674 Length:524288 x(80000)"]
56 ["CT-MONO2-16-ankle.dcm",
57 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit, little
61 ["Bits Stored", "16"],
62 ["Bits Allocated", "16"],
64 ["Pixel Representation", "1"],
65 ["Manufacturer", "GE MEDICAL SYSTEMS"],
66 ["Manufacturer's Model Name", "GENESIS_ZEUS"],
67 ["Pixel Data", "gdcm::NotLoaded. Address:1148 Length:524288 x(80000)"]
69 ["CT-MONO2-8-abdo.dcm",
70 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit, little
75 ["Bits Allocated", "8"],
77 ["Pixel Representation", "0"],
78 ["Manufacturer", "FUJI"],
79 ["Pixel Data", "gdcm::NotLoaded. Address:796 Length:262144 x(40000)"]
81 ["CT-MONO2-12-lomb-an2.acr2",
83 #"Transfer Syntax UID" and "Photometric Interpretation" are absent.
86 ["Bits Stored", "12"],
87 ["Bits Allocated", "16"],
89 ["Pixel Representation", "0"],
90 ["Manufacturer", "SIEMENS"],
91 ["Pixel Data", "gdcm::NotLoaded. Address:1230 Length:524288 x(80000)"]
93 ["CT-MONO2-16-chest.dcm",
94 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"], # jpeg...
96 ["Photometric Interpretation", "MONOCHROME2"],
99 ["Bits Stored", "16"],
100 ["Bits Allocated", "16"],
102 ["Pixel Representation", "1"],
103 ["Manufacturer", "GE MEDICAL SYSTEMS"],
104 ["Pixel Data", "gdcm::NotLoaded. Address:1638 Length:143498 x(2308a)"]
106 ####################################
107 ### MR modality examples:
108 ####################################
109 ["MR-MONO2-12-angio-an1.acr1",
110 [ ["Recognition Code (RET)", "ACR-NEMA 1.0"],
112 #"Transfer Syntax UID" and "Photometric Interpretation" are absent.
115 ["Bits Stored", "12"],
116 ["Bits Allocated", "12"],
118 ["Pixel Representation", "0"],
119 ["Manufacturer", "Philips"],
120 # Note: 256*256*12/8 = 98304
121 ["Pixel Data", "gdcm::NotLoaded. Address:650 Length:98304 x(18000)"]
123 ["MR-MONO2-12-an2.acr2",
124 [ ["Modality", "MR"],
125 ["Photometric Interpretation", "MONOCHROME2"],
128 ["Bits Stored", "12"],
129 ["Bits Allocated", "16"],
131 ["Pixel Representation", "0"],
132 ["Manufacturer", "SIEMENS"],
133 ["Manufacturer's Model Name", "MAGNETOM VISION"],
134 ["Pixel Data", "gdcm::NotLoaded. Address:1866 Length:131072 x(20000)"]
136 ["MR-MONO2-16-head.dcm",
137 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Imp VR, LE
139 ["Photometric Interpretation", "MONOCHROME2"],
142 ["Bits Stored", "16"],
143 ["Bits Allocated", "16"],
145 ["Pixel Representation", "1"],
146 ["Manufacturer", "GE MEDICAL SYSTEMS"],
147 ["Manufacturer's Model Name", "GENESIS_SIGNA"],
148 ["Pixel Data", "gdcm::NotLoaded. Address:1804 Length:131072 x(20000)"]
150 # MR-MONO2-12-shoulder example is present in the Jpeg section.
151 # MR-MONO2-16-knee is not present in the test suite since it is too
152 # closely related to MR-MONO2-16-head.dcm to be of interest.
153 ####################################
154 # OT modality examples:
155 ####################################
156 # OT-MONO2-8-hip is not present in the test suite since it is too
157 # closely related to OT-MONO2-8-a7 to be of interest.
158 ["OT-PAL-8-face.dcm",
159 # Interest: has a color palette
160 [#"Transfer Syntax UID", and "Manufacturer" are absent.
162 ["Photometric Interpretation", "PALETTE COLOR"],
165 ["Bits Stored", "8"],
166 ["Bits Allocated", "8"],
168 ["Pixel Representation", "0"],
169 ["Pixel Data", "gdcm::NotLoaded. Address:1654 Length:307200 x(4b000)"]
171 # OT-MONO2-8-colon is not present in the test suite since it is too
172 # closely related to OT-MONO2-8-a7 to be of interest.
173 ["OT-MONO2-8-a7.dcm",
174 [#"Transfer Syntax UID" is absent.
176 ["Photometric Interpretation", "MONOCHROME2"],
179 ["Bits Stored", "8"],
180 ["Bits Allocated", "8"],
182 ["Pixel Representation", "0"],
183 ["Manufacturer", "Philips Medical Systems"],
184 ["Pixel Data", "gdcm::NotLoaded. Address:438 Length:262144 x(40000)"]
186 ####################################
187 # US (Ultra Sound) modality examples:
188 ####################################
189 ["US-RGB-8-esopecho.dcm",
190 # Interest: RGB image
191 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Exp VR, LE
193 ["Photometric Interpretation", "RGB"],
196 ["Bits Stored", "8"],
197 ["Bits Allocated", "8"],
199 ["Pixel Representation", "0"],
200 ["Manufacturer", "Acme Products"],
201 # FIXME: 92160 / (120*256) = 3 bytes per pixel NOT 1. Maybe
202 # it has something to do with [Samples Per Pixel] = [3] ???
203 # You said it, puffy (tu l'as dit, bouffi, in french language)
204 # RGB is 3 bytes per pixel
205 # + Planar configuration (0028,0006) = 0 --> Pixels RGB
206 ["Pixel Data", "gdcm::NotLoaded. Address:904 Length:92160 x(16800)"]
208 ["US-RGB-8-epicard.dcm",
209 # Interest: Big endian transfert syntax
210 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.2"], # Big endian
211 # But ... group 0000 is LE .
213 ["Photometric Interpretation", "RGB"],
216 ["Bits Stored", "8"],
217 ["Bits Allocated", "8"],
219 ["Pixel Representation", "0"],
220 ["Manufacturer", "G.E. Medical Systems"],
221 ["Manufacturer's Model Name", "LOGIQ 700"],
222 # + Planar configuration (0028,0006) = 1 --> Plane R, Plane G, Plane B
223 ["Implementation Version Name", "OFFIS-DCMTK-311"],
224 ["Pixel Data", "gdcm::NotLoaded. Address:1012 Length:921600 x(e1000)"]
229 # The number of images is contained in the "Number of Frames" element
230 ["MR-MONO2-8-16x-heart.dcm",
231 # Interest: multi-frame
232 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
233 ["Number of Frames", "16"],
235 ["Photometric Interpretation", "MONOCHROME2"],
238 ["Bits Stored", "8"],
239 ["Bits Allocated", "8"],
241 ["Pixel Representation", "0"],
242 ["Manufacturer", "Philips"],
243 # Note: 256*256*16=1048576 (16 is the number of Frames)
244 ["Pixel Data", "gdcm::NotLoaded. Address:920 Length:1048576 x(100000)"]
246 ["NM-MONO2-16-13x-heart.dcm",
247 # Interest: NM modality, multi-frame
248 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
249 ["Number of Frames", "13"],
251 ["Photometric Interpretation", "MONOCHROME2"],
254 ["Bits Stored", "16"],
255 ["Bits Allocated", "16"],
257 ["Pixel Representation", "0"],
258 ["Manufacturer", "ACME Products"],
259 # Note: 64*64*13*2=106496
260 ["Pixel Data", "gdcm::NotLoaded. Address:1234 Length:106496 x(1a000)"]
262 ["US-MONO2-8-8x-execho.dcm",
263 # Interest: multi-frame
264 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # ExpVR, LE
265 ["Number of Frames", "8"],
267 ["Photometric Interpretation", "MONOCHROME2"],
270 ["Bits Stored", "8"],
271 ["Bits Allocated", "8"],
273 ["Pixel Representation", "0"],
274 ["Manufacturer", "Acme Products"],
275 ["Pixel Data", "gdcm::NotLoaded. Address:976 Length:122880 x(1e000)"]
277 ["US-PAL-8-10x-echo.dcm",
278 # Interest: RLE (Run Length Encoded) compression, multiframe
279 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.5"], # RLE
280 ["Number of Frames", "10"],
282 ["Photometric Interpretation", "PALETTE COLOR"],
285 ["Bits Stored", "8"],
286 ["Bits Allocated", "8"],
288 ["Pixel Representation", "0"],
289 ["Manufacturer", "ACME Products"],
290 ["Pixel Data", "gdcm::NotLoaded. Address:2428 Length:481182 x(7579e)"]
292 ["XA-MONO2-8-12x-catheter.dcm",
293 # Interest: XA modality, multi-frame
294 [ #["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"], # jpeg
295 ["Number of Frames", "12"], # 12 images
297 ["Photometric Interpretation", "MONOCHROME2"],
300 ["Bits Stored", "8"],
301 ["Bits Allocated", "8"],
303 ["Pixel Representation", "0"],
304 ["Manufacturer", "Acme Products"],
305 ["Pixel Data", "gdcm::NotLoaded. Address:1006 Length:920072 x(e0a08)"]
310 ["gdcm-MR-SIEMENS-16.acr1",
311 # Interest: good old Acr-Nema Version 1, see also Oddities below
312 [ ["Recognition Code (RET)", "ACR-NEMA 1.0"],
316 ["Bits Stored", "12"],
317 ["Bits Allocated", "16"],
319 ["Pixel Representation", "0"],
320 ["Manufacturer", "SIEMENS"],
321 ["Manufacturer's Model Name", "GBS III"],
322 # FIXME: this image looks padded at the end. The length of the file
323 # is 140288. Notice that, 256*256*2 + 1024 = 131072 + 1024 = 132096
324 ["Pixel Data", "gdcm::NotLoaded. Address:8192 Length:132096 x(20400)"],
325 # Oddities: "Study ID" and "Series Number" are empty
327 ["Series Number", ""] ] ],
328 # Oddities: "Study" and "Serie Instance UID" are not present
329 ["gdcm-MR-SIEMENS-16.acr2",
330 # Interest: Acr-Nema Version 2
331 [ ["Recognition Code (RET)", "ACR-NEMA 2.0"],
335 ["Bits Stored", "12"],
336 ["Bits Allocated", "16"],
338 ["Pixel Representation", "0"],
339 ["Manufacturer", "SIEMENS"],
340 ["Manufacturer's Model Name", "MAGNETOM VISION"],
341 ["Study Instance UID",
342 "1.3.12.2.1107.5.2.4.7630.20000918174641000"],
344 ["Series Instance UID",
345 "1.3.12.2.1107.5.2.4.7630.20000918175714000007"],
346 ["Series Number", "7"],
347 ["Pixel Data", "gdcm::NotLoaded. Address:6052 Length:524288 x(80000)"]
349 ["gdcm-US-ALOKA-16.dcm",
350 # Interest: - possesses 3 LUTS: a Green (checked), a Red and BLue.
351 # - announced as implicit VR, but really explicit VR.
352 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
354 ["Photometric Interpretation", "PALETTE COLOR"],
355 ["Segmented Green Palette Color Lookup Table Data",
356 "gdcm::NotLoaded. Address:89576 Length:113784 x(1bc78)"],
359 ["Bits Stored", "16"],
360 ["Bits Allocated", "16"],
362 ["Pixel Representation", "0"],
363 ["Manufacturer", "ALOKA CO., LTD."],
364 ["Manufacturer's Model Name", "SSD-4000"],
365 ["Pixel Data", "gdcm::NotLoaded. Address:258740 Length:614400 x(96000)"]
367 ["gdcm-MR-PHILIPS-16.dcm",
368 # Interest: - possesses a sequence
369 # - dicom file, with a recognition code of ACR-NEMA1
370 [ ["Transfer Syntax UID", "1.2.840.10008.1.2"], # Implicit VR, LE
371 ["Recognition Code (RET)", "ACR-NEMA 1.0"],
373 ["Photometric Interpretation", "MONOCHROME2"],
376 ["Bits Stored", "8"],
377 ["Bits Allocated", "16"],
379 ["Pixel Representation", "0"],
380 ["Manufacturer", "Philips Medical Systems"],
381 ["Manufacturer's Model Name", "Gyroscan Intera"],
382 ["Sequence Variant", "OTHER"],
383 ["Pixel Data", "gdcm::NotLoaded. Address:6584 Length:131072 x(20000)"]
385 ["gdcm-MR-PHILIPS-16-Multi-Seq.dcm",
386 # Interest: - possesses many sequences in group 0x0029
387 # - Big sequence 28808 bytes at (0x0029, 0x263d)
388 # - dicom file, with a recognition code of ACR-NEMA1
389 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"],
390 ["Recognition Code (RET)", "ACR-NEMA 1.0"],
392 ["Photometric Interpretation", "MONOCHROME2"],
395 ["Bits Stored", "12"],
396 ["Bits Allocated", "16"],
398 ["Pixel Representation", "0"],
399 ["Manufacturer", "Philips Medical Systems"],
400 ["Manufacturer's Model Name", "Gyroscan Intera"],
401 ["Sequence Variant", "OTHER"],
402 ["Pixel Data", "gdcm::NotLoaded. Address:35846 Length:32768 x(8000)"]
404 ["gdcm-MR-PHILIPS-16-NonRectPix.dcm",
405 # Interest: - pixels are non rectangular
406 # - private elements are in explicit VR (which is normal)
407 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
409 ["Photometric Interpretation", "MONOCHROME2"],
412 ["Bits Stored", "12"],
413 ["Bits Allocated", "16"],
415 ["Pixel Representation", "0"],
416 ["Manufacturer", "Philips Medical Systems"],
417 ["Manufacturer's Model Name", "Gyroscan Intera"],
418 ["Pixel Spacing", "0.487416\\0.194966"],
419 ["Pixel Data", "gdcm::NotLoaded. Address:5010 Length:20480 x(5000)"]
421 ["gdcm-CR-DCMTK-16-NonSamplePerPix.dcm",
422 # Interest: - Misses the "Samples Per Pixel" element which prevents
423 # e-film from reading it.
424 # - Misses the Manufacturer related info
425 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.1"], # Explicit VR, LE
427 ["Photometric Interpretation", "MONOCHROME2"],
430 ["Bits Stored", "8"],
431 ["Bits Allocated", "8"],
433 ["Pixel Representation", "0"],
434 ["Implementation Version Name", "OFFIS_DCMTK_341"],
435 ["Pixel Data", "gdcm::NotLoaded. Address:740 Length:562500 x(89544)"]
440 ["gdcm-JPEG-Extended.dcm",
441 # Interest: Jpeg compression [Extended (2,4)]
442 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.51"],
444 ["Photometric Interpretation", "MONOCHROME2"],
447 ["Bits Stored", "12"],
448 ["Bits Allocated", "16"],
450 ["Pixel Representation", "0"],
451 ["Manufacturer", "SIEMENS"],
452 ["Manufacturer's Model Name", "Volume Zoom"],
453 ["Pixel Data", "gdcm::NotLoaded. Address:2946 Length:192218 x(2eeda)"]
455 ["MR-MONO2-12-shoulder.dcm",
456 # Interest: Jpeg compression [Lossless, non-hierar. (14)]
457 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.57"],
459 ["Photometric Interpretation", "MONOCHROME2"],
462 ["Bits Stored", "12"],
463 ["Bits Allocated", "16"],
465 ["Pixel Representation", "0"],
466 ["Manufacturer", "Philips Medical Systems"],
467 ["Manufacturer's Model Name", "Gyroscan NT"],
468 ["Pixel Data", "gdcm::NotLoaded. Address:1580 Length:718948 x(af864)"]
470 ["gdcm-JPEG-LossLess3a.dcm",
471 # Interest: - Jpeg compression [Lossless, hierar., first-order
472 # pred. 14, Select. Val. 1]
473 # - contains a sequence [circa (0008,2112)]
474 # - contains additional data after the pixels ???
475 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"],
477 ["Photometric Interpretation", "MONOCHROME2"],
480 ["Bits Stored", "12"],
481 ["Bits Allocated", "16"],
483 ["Pixel Representation", "0"],
484 ["Manufacturer", "SIEMENS"],
485 ["Manufacturer's Model Name", "Volume Zoom"] ] ],
486 # FIXME: the pixel data looks like corrupted. As stated by "od -A d -c"
487 # 0002528 à 177 020 \0 O B \0 \0 ÿ ÿ ÿ ÿ þ ÿ \0 à
488 # 0002544 \0 \0 \0 \0 þ ÿ \0 à 202 ? 003 \0 ÿ Ø ÿ Ã
489 # which we interpret as follows:
490 # - 2528: (à 177, 020 \0) = (0x7fe0, 0x0010) i.e. Pixel Data tag,
491 # - 2532: OB i.e. encapsulated encoded Pixel Data,
492 # - 2534: Two bytes reserved,
493 # - 2536: ÿ ÿ ÿ ÿ = 0xffffffff i.e. data element length is undefined.
494 # - 2540: (þ ÿ, \0 à) = (0xfffe, 0xe000) i.e. basic offset table
496 # - 2544: \0 \0 \0 \0 i.e. offset table as length zero, i.e. no
497 # item value for offset table.
498 # - 2548: (þ ÿ, \0 à) = (0xfffe, 0xe000) i.e. item tag of first
499 # fragment of (encoded) pixel data.
500 # - 2552: 202 ? 003 \0 = 212866 bytes i.e. length of first fragment
501 # of (encoded) pixel data.
502 # and so the next item tag should be found at the 2556+212866 th
503 # octet i.e. at address 215422. But, as stated by od, we find:
504 # 0215408 E u Ö 026 Î É 7 ¬ Ã ¸ ó ¿ ÿ Ù \f °
505 # 0215424 ¶ 016 P Ñ 002 016
506 # and (\f °, ¶ 016) is NOT an OB item TAG which is required to be
507 # present (at least there should be a sequence delimiter), refer to
508 # PS 3.5-2001 page 50.
511 # at 9ec : ItemTag : fffe,e000
512 # at 9f0 : Basic Offset Table Item Lentgh (??) 0 x(00000000)
513 # at 9f4 : ItemTag : fffe,e000
514 # at 9f8 : fragment length 212866 x(00033f82)
515 # at 3497e : ItemTag b00c,0eb6 (should be fffe,e000 or fffe,e0dd):
517 ["gdcm-JPEG-LossLessThoravision.dcm",
518 # Interest: - Jpeg compression [Lossless, hierar., first-order
519 # pred. 14, Select. Val. 1]
520 # - encoding is sligthly different from LossLess3a.dcm ???
521 [ ["Transfer Syntax UID", "1.2.840.10008.1.2.4.70"],
523 ["Photometric Interpretation", "MONOCHROME2"],
526 ["Bits Stored", "15"],
527 ["Bits Allocated", "16"],
529 ["Pixel Representation", "0"],
530 ["Manufacturer", "Philips Medical Systems"],
531 ["Manufacturer's Model Name", "Cassette Holder Type 9840 500 35201"],
532 ["Pixel Data", "gdcm::NotLoaded. Address:3144 Length:4795668 x(492d14)"]
536 def _BaseTest(self, FileSet):
537 for entry in FileSet:
538 fileName = os.path.join(GDCM_TEST_DATA_PATH, entry[0])
539 reader = gdcmHeader(fileName)
540 assert reader.IsReadable(),\
541 "File '%s' is not readable by gdcmHeader" % fileName
543 valDict = reader.GetEntry()
544 for subEntry in entry[1]:
545 element = subEntry[0]
547 self.assertEqual(valDict[element], value,
548 ("Wrong %s for file %s (got %s, shoud be %s)"
549 % (element,fileName, valDict[element], value)) )
552 gdcmTestCase._BaseTest(self, gdcmTestCase.BarreFiles)
554 def testMultiFram(self):
555 gdcmTestCase._BaseTest(self, gdcmTestCase.MultiFrameFiles)
558 gdcmTestCase._BaseTest(self, gdcmTestCase.GdcmFiles)
561 gdcmTestCase._BaseTest(self, gdcmTestCase.GdcmJpegFiles)
565 SourceFileName = os.path.join(GDCM_TEST_DATA_PATH,
566 'gdcm-MR-PHILIPS-16-Multi-Seq.dcm')
567 Source = gdcmFile(SourceFileName);
568 Source.GetImageData()
569 TargetFileName = "junk"
570 Target = Source.WriteDcmImplVR(TargetFileName)
571 # Sign = 'a1e2abdc2f6abedd86b93c8b88db5203' # new signature (found on Win)
572 Sign = '849e722e004d3bb37b87ab6006509b8f' # new signature without field strip
573 ComputeSign = md5.new(open(TargetFileName).read()).hexdigest()
574 self.assertEqual(ComputeSign, Sign,
575 ("Wrong signature for file %s (got %s, shoud be %s)"
576 % (SourceFileName, ComputeSign, Sign)) )
577 os.unlink(TargetFileName)
579 if __name__ == '__main__':
580 if not GDCM_TEST_DATA_PATH:
581 print "GDCM_TEST_DATA_PATH (internal variable) is not setup properly."
582 print " This test suite requires that some Dicom reference files be "
584 print " For further details on installation of gdcmData, please"
585 print " refer to the developper's section of page "
586 print " http://www.creatis.insa-lyon.fr/Public/Gdcm"
588 print "gdcmData directory (used in the test suite) must be placed in"
589 print "the gdcm directory. The gdcm tree must be :"
593 print " |____gdcmData (not in gdcm by default)"
594 print " |____gdcmPython"