您的位置:首页技术文章
文章详情页

在python中读取* .mhd / *。raw格式

【字号: 日期:2022-08-07 14:08:13浏览:2作者:猪猪
如何解决在python中读取* .mhd / *。raw格式?

最简单的方法是使用SimpleITK(MedPy也将ITK用于.mhd / .raw文件)。命令

pip install SimpleITK

适用于许多python版本。要读取.mhd /.raw,可以从kaggle使用此代码

import SimpleITK as sitkimport 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文件的数据集的方式?

标签: Python 编程
相关文章: