Skip to content

Variable type errors trying to use GetLUTDescriptor() #25

Description

@bal-agates

I am getting this error

$ python gdcm_lut_problem.py 
Traceback (most recent call last):
  File "/Users/brett/Brett2025/Source/Python/dicom/gdcm_lut_problem.py", line 15, in <module>
    lutDescRed = lut.GetLUTDescriptor(lut.RED, length, subscript, bitsize)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/brett/Library/Python/3.12/lib/python/site-packages/_gdcm/gdcmswig.py", line 3537, in GetLUTDescriptor
    return _gdcmswig.LookupTable_GetLUTDescriptor(self, type, length, subscript, bitsize)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: in method 'LookupTable_GetLUTDescriptor', argument 3 of type 'unsigned short &'

when trying to run this code

import sys
import gdcm

filename = "pydicom_examples/examples_palette.dcm"
reader = gdcm.ImageReader()
reader.SetFileName(filename)
if not reader.Read():
    print("Error reading file:", filename)
    sys.exit(1)
image = reader.GetImage()
lut = image.GetLUT()
length = bytearray(b'\x00\x00')
subscript = bytearray(b'\x00\x00')
bitsize = bytearray(b'\x00\x00')
lutDescRed = lut.GetLUTDescriptor(lut.RED, length, subscript, bitsize)

Help on method GetLUTDescriptor in module _gdcm.gdcmswig:

GetLUTDescriptor(type, length, subscript, bitsize) method of _gdcm.gdcmswig.LookupTable instance
    void
    gdcm::LookupTable::GetLUTDescriptor(LookupTableType type, unsigned
    short &length, unsigned short &subscript, unsigned short &bitsize)
    const

Can you suggest Python code to satisfy "unsigned short &" arguments? Is there a way to use this function in Python? I have looked at Python bytearray, struct, array, bytes. The bytearray is mutable to hopefully satisfy the &. Not sure how to satisfy the type checking for "unsigned short".

Note that my input example is the only DICOM image with PALETTE encoding I have found. This one is strange because the LUT takes 8-bits (raw) and produces 16-bits for each color. There doesn't seem to be a built-in gdcm way to decode with 8-to-16 bits so I was going try do that in numpy, thus the need to access the LUT table data directly.

I have seen in the opencv4 library they have been able to convert C function signatures like this to

[length, subscript, bitsize] = lut.GetLUTDescriptor(type)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions