2016-05-18 114 views

答えて

5

最も簡単な方法は、SimpleITKを使用することです。コマンド

pip install SimpleITK 

は多くのPythonバージョンで動作します。 .mhdを読み取るための/あなたはこのコードを使用すると、これは、zであなたにnumpyの配列を与えるSimpleITK

import skimage.io as io 
img = io.imread('file.mhd', plugin='simpleitk') 

インストール後も簡単かもしれskimageを使用してfrom kaggle

import SimpleITK as sitk 
import numpy as np 
''' 
This funciton reads a '.mhd' file using SimpleITK and return the image array, origin and spacing of the image. 
''' 

def load_itk(filename): 
    # Reads the image using SimpleITK 
    itkimage = sitk.ReadImage(filename) 

    # Convert the image to a numpy array first and then shuffle the dimensions to get axis in the order z,y,x 
    ct_scan = sitk.GetArrayFromImage(itkimage) 

    # Read the origin of the ct_scan, will be used to convert the coordinates from world to voxel and vice versa. 
    origin = np.array(list(reversed(itkimage.GetOrigin()))) 

    # Read the spacing along each dimension 
    spacing = np.array(list(reversed(itkimage.GetSpacing()))) 

    return ct_scan, origin, spacing 
+0

BTW、[this](http://stackoverflow.com/questions/37989196/how-do-i-open-mhd-file-corresponding-to-a-raw-file-in-blender-3d-tool )質問は同じです。誰かをマージできますか? – savfod

0

(MedPyがあまりにも.mhd /た.rawファイルに対してITKを使用しています)あなたはMedPyを使用しようとすることができたり、このmhd_utils script

3

を使用することができます.RAW、Y、 xソーティング。

関連する問題