Python type errors with GetLUTDescriptor()
Cross-platform DICOM implementation
Brought to you by:
malat
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')
lut.GetLUTDescriptor(lut.RED, length, subscript, bitsize)
You can find the test data file here
The python help for this function says:
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
I have tried many things with length, subscript and bitsize including bytes, ctypes, cython, struct but I cannot find a pattern that works. Can you suggest something to change in this python code or does something in SWIG need to change?
Maybe ??? change the python signature to:
[length, subscript, bitsize] = lut.GetLUTDescriptor(lut.RED)
I think this type of signature change is sometimes done in wxWidgets or opencv4 but I do not know how they do it?
Similar type problems with LookupTable.decode()
For the above my system info is:
macOS 14.7,2 arm64
Python 3.12.8 (MacPorts installed)
python-gdcm 3.0.24.1 (pip installed)