Skip to main content
 首页 » 编程设计

python之在 Python 中使用 SimpleITK 读取 mhd 文件时出错

2025年02月15日8qq号

我又来了,还有另一个关于 Python 中的 SimpleITK 的问题。我想绘制 .mhd 图像,但我不知道如何绘制。我正在尝试此处描述的功能 Reading *.mhd/*.raw format in python :

load_itk('/home/bianca/Documents/PythonProcessing/result-Edep.mhd') 

但它不是读取图像:

RuntimeError: Exception thrown in SimpleITK ReadImage: /tmp/SimpleITK-build/ITK/Modules/IO/Meta/src/itkMetaImageIO.cxx:483: 
itk::ERROR: MetaImageIO(0x3a83730): File cannot be read: /home/bianca/Documents/PythonProcessing/result-Edep.mhd for reading. 
Reason: Success 

我也尝试过使用 scikit 图像...

img = io.imread('/home/bianca/Documents/PythonProcessing/result-Edep.mhd', plugin='simpleitk') 

但我也收到一条错误消息

RuntimeError: Exception thrown in SimpleITK ReadImage: /tmp/SimpleITK-build/ITK/Modules/IO/Meta/src/itkMetaImageIO.cxx:483: 
itk::ERROR: MetaImageIO(0x3a84280): File cannot be read: /home/bianca/Documents/PythonProcessing/result-Edep.mhd for reading. 
Reason: Success 

即使有 medpy

from medpy.io import load 
image_data, image_header = load('/home/bianca/Documents/PythonProcessing/result-Edep.mhd') 
 
Traceback (most recent call last): 
  File "<pyshell#17>", line 1, in <module> 
    image_data, image_header = load('/home/bianca/Documents/PythonProcessing/result-Edep.mhd') 
  File "medpy/io/load.py", line 201, in load 
    raise err 
DependencyError: Loading images of type Itk/Vtk MetaImage (.mhd, .mha/.raw) requires a third-party module that could not be encountered. Reason: No module named itk. 

但我现在有 SimpleITK。我不明白这是怎么回事... =(

请您参考如下方法:

您尝试读取的文件是否有效?您可以使用其他一些图像显示工具进行检查,例如ITK-SNAP或 3D Slicer .如果这些工具中的任何一个可以打开它,请告诉我们您使用的 SimpleITK 的版本。