如何解决在python中读取* .mhd / *。raw格式?
最简单的方法是使用SimpleITK(MedPy也将ITK用于.mhd / .raw文件)。命令
pip install SimpleITK
适用于许多python版本。要读取.mhd / .raw,可以从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
解决方法
谁能告诉我如何读取包含python中的 .mhd / .raw文件的数据集的方式?
本文来自网友发布,不代表我们立场,转载联系作者并注明出处: