ImagingDataCommons / highdicom

High-level DICOM abstractions for the Python programming language
https://highdicom.readthedocs.io
MIT License
172 stars 37 forks source link

Failure to create GSPS when reference DICOM uses "MultiValue" for WindowCenter, WindowWidth #210

Closed delton137 closed 1 year ago

delton137 commented 1 year ago

When I go to create a GSPS using hd.pr.GrayscaleSoftcopyPresentationState() I get an error for certain DICOM where WindowWidth and WindowCenter are not floats in the reference DICOM.

Here's the error I get:

~/anaconda3/lib/python3.8/site-packages/highdicom/pr/content.py in _get_softcopy_voi_lut_transformations(referenced_images)
   1456 
   1457             if has_width:
-> 1458                 by_window[(
   1459                     ref_im.WindowWidth,
   1460                     ref_im.WindowCenter,

TypeError: unhashable type: 'MultiValue'

I fixed it using the following code:

        if isinstance(image_dataset.WindowWidth, pydicom.multival.MultiValue):
            image_dataset.WindowWidth = image_dataset.WindowWidth[0]
        if isinstance(image_dataset.WindowCenter, pydicom.multival.MultiValue):
            image_dataset.WindowCenter = image_dataset.WindowCenter[0]

This fix worked for two offending DICOM, but there is one more where I'm still getting the error. To get rid of the error there, I created the GSPS with my own windowing settings (using the argument voi_lut_transformations=[SoftcopyVOILUTObject]).

CPBridge commented 1 year ago

Thanks @delton137 ! I had a quick look and I think this is a simple fix. Can you try the branch in #211 and see whether that fixes the issue?

For now, the best solution is probably to manually specify the voi_lut_transformations, as you suggest.

hackermd commented 1 year ago

Why would these attributes have a multiplicity greater than one?

pieper commented 1 year ago

Why would these attributes have a multiplicity greater than one?

It's not uncommon for an image to have multiple WW/WC values in the header. They could be soft tissue and lung windows for example.

CPBridge commented 1 year ago

C.11.2.1.2.2, with reference to WindowCenter and WindowWidth:

If multiple values are present, both Attributes shall have the same number of values and shall be considered as pairs. Multiple values indicate that multiple alternative views may be presented.

delton137 commented 1 year ago

I just tested @CPBridge's fix (#211) and it works! Yes, it seems multiple window settings may be saved in the DICOM.