使用Python中的SimpleITK读取mhd文件时出错

时间:2017-07-24 20:04:22

标签: python image-processing computer-vision itk simpleitk

我在这里再次提到有关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。我不明白发生了什么...... =(

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

MHD文件通常需要一个mhd标头和一个包含图像数据的原始文件-您是否都在同一目录中,而mhd标头指向该数据?