【问题标题】:pydicom is not definedpydicom 未定义
【发布时间】:2017-11-27 21:56:07
【问题描述】:

我正在尝试学习如何使用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 已正确安装和更新。

我该如何解决这个问题?

【问题讨论】:

  • 你说import dicom然后尝试使用pydicom。哪个是正确的?
  • 我是根据 pydicom pydicom.readthedocs.io/en/latest/working_with_pixel_data.html 的文档执行此操作的,但无论哪种方式,pydicom 似乎都无法正常工作。正如@serafeim 指出的那样,这可能是因为数据不兼容。我认为数据是标准格式。没想到会不兼容。我会检查并发布我发现的内容。
  • 错误:像素数据以 pydicom 尚未处理的格式压缩表明数据与库不兼容。如果可能,添加一些数据以尝试找到解决方案
  • 是否有任何文档描述了兼容的像素数据类型?该数据直接来自超声心动图机。这是超声波数据。我正在尝试弄清楚如何检查它的兼容性。
  • 存储库中的工作代码中添加了许多压缩数据处理程序,但这些还没有正式发布。要使用存储库代码(相当稳定),请使用pip install git+https://github.com/pydicom/pydicom.git 安装并使用import pydicom

标签: python dicom pydicom


【解决方案1】:

你正在尝试调用一个你之前没有导入过的类:

用途:

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

【讨论】:

  • 我也试过了,但是当我尝试导入它时,我得到“没有名为 pydicom 的模块”。我正在使用 jupyter notebook,我什至尝试重新启动内核。
  • @你安装了 dicom 和 pydicom 吗?另请参阅我修改后的答案
  • 我是从这个网站学习的:http://pydicom.readthedocs.io/en/latest/working_with_pixel_data.html,如果你注意到他们所做的正是我所做的。而且我还提到了我得到NotImplementedError' when I used dicom.read_file`的问题
  • 我无法访问该网站。但是你能试试我在回答中建议的第二件事吗?另外,请务必阅读和使用官方文档。其他一些在线教程经常包含错误
  • pydicom.readthedocs.io/en/latest/working_with_pixel_data.html 上面说过,我已经试过你的第二种方法,得到了NotImplementedError。我编辑了我的问题以重新格式化它,使其更加明显。
【解决方案2】:

如果你想获得像素数据,我建议使用ImageMagick 套件中的convert 程序。您可以使用 subprocess 模块从 Python 调用此程序。 (参见 example,我将它们转换为 JPEG 格式),或者您可以使用 Python bindings 之一。

如果您想处理图像,最好使用绑定。但请注意,并非所有绑定都已转换为 ImageMagick 版本 7。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-25
    • 2010-10-21
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 2016-02-01
    • 1970-01-01
    相关资源
    最近更新 更多