Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUT Descriptor tag with no value yields TypeError #1049

Closed
deeuu opened this issue Feb 10, 2020 · 3 comments · Fixed by #1050
Closed

LUT Descriptor tag with no value yields TypeError #1049

deeuu opened this issue Feb 10, 2020 · 3 comments · Fixed by #1050
Labels

Comments

@deeuu
Copy link

deeuu commented Feb 10, 2020

Describe the bug
I have a DICOM image with the following tag (copied from ImageJ)

0028,1101  Red Palette Color Lookup Table Descriptor: 

which corresponds to the raw data element, produced by DataElement_from_raw:

RawDataElement(tag=(0028, 1101), VR='US', length=0, value=None, value_tell=1850, is_implicit_VR=False, is_little_endian=True)

Because this tag is matched by the LUT Descriptor tags and the value is empty (None), the following line:

if raw.tag in _LUT_DESCRIPTOR_TAGS and value[0] < 0:

results in

TypeError: 'NoneType' object is not subscriptable

Expected behavior

Given that I discovered this by parsing what seems to be a set of faulty DICOMs (mangled pixel data), I'm not sure if an error should be raised if the colour attribute value is not provided.

However, given that value can be None for other tags, the simple fix is

try:
    if raw.tag in _LUT_DESCRIPTOR_TAGS and value[0] < 0:
        # We only fix the first value as the third value is 8 or 16
        value[0] += 65536
except TypeError:
    pass

(or test if value is iterable).

Your environment

Darwin-19.3.0-x86_64-i386-64bit
Python  3.7.6 | packaged by conda-forge | (default, Jan  7 2020, 22:05:27)
[Clang 9.0.1 ]
pydicom  1.4.1

Many thanks!

@scaramallion
Copy link
Member

scaramallion commented Feb 10, 2020

LUT Descriptor and the Red/Green/Blue Palette Color LUT Descriptor elements are all type 1 or 1C, so nope they're not supposed to be empty. But I should've known better than to assume conformance...

Anyway, thanks! It'll be fixed soon.

@deeuu
Copy link
Author

deeuu commented Feb 10, 2020

Excellent, thank you!

@scaramallion
Copy link
Member

You can also workaround the issue by deleting the element before doing anything else:

ds = dcmread('filename.dcm')
del ds[0x00281101]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants