我正在尝试学习如何使用pydicom来读取和处理dicom图像。我使用的是Python 3。
import dicom
import numpy
ds = pydicom.read_file(lstFilesDCM[0])
print(ds.pixel_array)`我得到一个错误的NameError: name 'pydicom' is not defined。如果我改变了
ds = pydicom.read_file(lstFilesDCM[0])至
ds = dicom.read_file(lstFilesDCM[0])(改为使用dicom.read_file ),我得到以下错误:
NotImplementedError: Pixel Data is compressed in a format
pydicom does not yet handle. Cannot return array我还验证了pydicom是否正确安装和更新。
我该如何解决这个问题?
发布于 2017-11-28 05:58:29
您正在尝试调用以前未导入的类:
使用:
import pydicom
import numpy
ds = pydicom.read_file(lstFilesDCM[0])
print(ds.pixel_array)或
import dicom
ds = dicom.read_file("the_name_of_file.dcm")文档:http://pydicom.readthedocs.io/en/stable/pydicom_user_guide.html
发布于 2017-11-28 06:20:41
如果您想获得像素数据,我建议使用ImageMagick套件中的convert程序。您可以使用subprocess模块从Python调用此程序。(参见下面的example,我在这里将它们转换为JPEG格式),或者您也可以使用Python bindings之一。
如果您想要操作图像,使用绑定可能更好。但请注意,并不是所有的绑定都转换为ImageMagick版本7。
https://stackoverflow.com/questions/47520486
复制相似问题