moloney / dcmstack

DICOM to Nifti conversion with meta data preservation
Other
72 stars 51 forks source link

Verify element name before attempting translation #26

Closed kevlarkevin closed 9 years ago

kevlarkevin commented 9 years ago

This pull request attempts to resolve an issue with Siemens dicoms that store something other than a ['CSA Image Header Info'] in tag (0x29,0x1010).

Some siemens dicoms, such as those of image_type ['DERIVED', 'SECONDARY', 'OTHER', 'CSA 3D EDITOR'], may include '[CSA Data Info]' at tag (0x29,0x1010), instead of '['CSA Image Header Info]'. The value of this tag is not a valid csa string, and is not parseable with nibabel.nicom.csareader.read().

The proposed fix is to have the each translate functions check the element name before translating. If the element has an incorrect name, then it returns an empty dictionary.

moloney commented 9 years ago

Thanks for this. Do you perhaps have a file you can share that illustrates the issue?

kevlarkevin commented 9 years ago

Sorry for the late response.

Added an anonymized dicom that contains '[CSA Data Info]' element in tag (0x29,0x1010). Also added two very small tests that illustrate the issue.

moloney commented 9 years ago

I am not seeing the issue. The "PrivateCreator" (0x29, 0x10) value in this data set is "SIEMENS CSA NON-IMAGE" which does not match the priv_creator attribute of our translators ("SIEMENS CSA HEADER"). Thus the translators don't get run.

The private elements in a DICOM are always relative to a "PrivateCreator" element. If there was a private creator element (0x29, 0x20) with the value "SIEMENS CSA HEADER" we would be looking for the CSA Image Header at (0x29, 0x2010) and the CSA Series Header at (0x29, 0x2020) instead of the more common (0x29, 0x1010) and (0x29, 0x1020).

kevlarkevin commented 9 years ago

I'm probably doing something wrong, or misunderstanding something (or both). Here's what I get when using moloney/dcmstack@2f334de5ff96f2729d64ae6aefc8d52b7b39087b on csa_data_info.dcm.

import dcmstack, dcmstack.extract, dicom
meta = dcmstack.extract.MetaExtractor()
dcm = dicom.read_file('csa_data_info.dcm')
csa = meta(dcm)

/Users/kevlar/.virtualenvs/dev/lib/python2.7/site-packages/dcmstack/extract.py:444:
UserWarning: Exception from translator CsaImage: Number of tags `t` should be 0 < t <= 128 str(e)))

That warning got me confused; I thought it meant that the translator was being actually being run.

moloney commented 9 years ago

Ah, yes you are right. There was a bug here. Can you try with commit 6d49fe0 ?

kevlarkevin commented 9 years ago

commit 6d49fe01235c08ae63c76fa2f3943b49c9b9832d fixed it. Beat me to it. Thanks!