我试图用以下代码读取一个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如果有人知道怎么解决,谢谢。
发布于 2015-08-24 23:36:06
我认为它可能很简单,因为您的版本的PIL不支持16位图像类型。numpy类型的字符串"<u2"是一个"uint16",这很可能是dicom图像的位深度。如果您使用的是真正的PIL,则可能需要切换到枕头。
发布于 2017-01-08 18:20:20
我不相信PIL (或枕头)支持DICOM映像,因为它们在支持的文件列表上没有提到。
我以前使用过比迪科姆,它运行得很好。
DICOM是一个复杂的标准。仅仅阅读原始的像素数据(7 FE0,0010)通常是不够的。例如,您可能希望将斜坡(0028,1053)和截取(0028,1052)值应用于原始像素数据,以便得到带有适当单位和偏移量的浮点值。
https://stackoverflow.com/questions/32192302
复制相似问题