Dicom 图像错误
Dicom Image error
我正在尝试使用以下代码读取 dicom 图像:
import dicom
from PIL import Image
Ima = dicom.read_file("MR000000.dcm")
f = Ima.pixel_array
sa = Image.fromarray(f)
sa.show()
但我收到以下错误:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 1926, in fromarray
mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1), '<u2')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "lala.py", line 8, in <module>
sa = Image.fromarray(f)
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 1929, in fromarray
raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type
谁知道怎么解决,谢谢
我认为这可能很简单,因为您的 PIL 版本不支持 16 位图像类型。 numpy 类型字符串 "<u2"
是一个 "uint16",这很可能是您的 dicom 图像的位深度。如果您使用的是正版 PIL,您可能需要切换到 Pillow
我不认为 PIL(或 Pillow)支持 DICOM 图像,因为 their supported files list 上没有提到它们。
我以前用过pydicom,效果很好。
DICOM 是一个复杂的标准。只需将原始 pixel data (7FE0,0010) is usually not enough. For example, you may want to apply the slope (0028,1053) and intercept (0028,1052) 值读取到原始像素数据,以便获得具有适当单位和偏移量的浮点值。
我正在尝试使用以下代码读取 dicom 图像:
import dicom
from PIL import Image
Ima = dicom.read_file("MR000000.dcm")
f = Ima.pixel_array
sa = Image.fromarray(f)
sa.show()
但我收到以下错误:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 1926, in fromarray
mode, rawmode = _fromarray_typemap[typekey]
KeyError: ((1, 1), '<u2')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "lala.py", line 8, in <module>
sa = Image.fromarray(f)
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 1929, in fromarray
raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type
谁知道怎么解决,谢谢
我认为这可能很简单,因为您的 PIL 版本不支持 16 位图像类型。 numpy 类型字符串 "<u2"
是一个 "uint16",这很可能是您的 dicom 图像的位深度。如果您使用的是正版 PIL,您可能需要切换到 Pillow
我不认为 PIL(或 Pillow)支持 DICOM 图像,因为 their supported files list 上没有提到它们。
我以前用过pydicom,效果很好。
DICOM 是一个复杂的标准。只需将原始 pixel data (7FE0,0010) is usually not enough. For example, you may want to apply the slope (0028,1053) and intercept (0028,1052) 值读取到原始像素数据,以便获得具有适当单位和偏移量的浮点值。