我正在尝试在 opencv-python 中显示 DICOM 图像。我正在使用 pydicom 库,然后添加 API 来使用 DOTNET 创建一个完整的 DICOM 查看器,该查看器运行 python(当然,C# 使用流程实例调用 python!!) 。我无法转换或查看未压缩的 DICOM 图像。每当我尝试加载或修改像素数组时。我收到错误消息。
import dicom
import cv2
import numpy
df=dicom.read_file("IM-0001-0002.dcm")
df.pixel_array
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
df.pixel_array
File "C:\Python27\lib\site-packages\dicom\dataset.py", line 394, in pixel_array
return self._get_pixel_array()
File "C:\Python27\lib\site-packages\dicom\dataset.py", line 376, in _get_pixel_array
raise NotImplementedError("Pixel Data is compressed in a format pydicom does not yet handle. Cannot return array")
NotImplementedError: Pixel Data is compressed in a format pydicom does not yet handle. Cannot return array
请建议我转换图像的好方法,使 cv2.imshow() 函数显示图像
提前致谢!!
尝试pydicom
错误的原因之一可能是:使用的 .dcm 文件可能包含不支持的格式(例如,在 pydicom 的情况下,pillow 不支持 JPEG 2000)。这个问题是可以解决的。我遇到了同样的问题(我使用 pydicom 而不是 dicom)我想您会从解决我的问题的解决方案中得到一些指导:
第一平台a信息:
我正在使用:pydicom 读取 .dcm 文件、Python 3.6、Anaconda 和 Ubuntu、15 GB RAM
解决方案:
-
安装pydicom使用这个命令:
pip install -U pydicom
.
信息可以在这里找到:(链接:https://pydicom.github.io/pydicom/dev/getting_started.html https://pydicom.github.io/pydicom/dev/getting_started.html)
蟒蛇是必要的。为什么?请查看pydicom的官方文档(https://pydicom.github.io/pydicom/dev/getting_started.html https://pydicom.github.io/pydicom/dev/getting_started.html)其中提到“要安装 pydicom 以及压缩像素数据的图像处理程序,我们鼓励您使用 Miniconda 或 Anaconda”
-
如果您使用的是 Ubuntu,请直接打开终端。如果您使用的是 Windows,则在 Anaconda Navigator 上从此处启动终端转到环境。在其上执行以下命令:
pip install -U git+https://github.com/pydicom/pydicom.git
conda install pydicom --channel conda-forge
conda install -c conda-forge gdcm
交叉检查:
现在重新启动笔记本,然后尝试使用 pydicom 执行代码。它将显示输出。
另外,还可以使用Matplotlib来显示,如下所示:
import matplotlib.pyplot as plt
import pydicom
filename = 'IM-0001-0002.dcm'
ds = pydicom.dcmread(filename)
plt.imshow(ds.pixel_array, cmap=plt.cm.bone)
我希望它能帮助你。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)