在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文件的数据集的方式?
相关文章:
1. django ObjectDoesNotExist 和 DoesNotExist的用法2. Django-imagekit的使用详解3. Django中的AutoField字段使用4. Python+Appium实现自动化测试的使用步骤5. Docker+nacos+seata1.3.0安装与使用配置教程6. 快速解决Django关闭Debug模式无法加载media图片与static静态文件7. Django ORM filter() 的运用详解8. Java智能卡基础篇——未来Java平台的新发展9. Java基础之详解HashSet的使用方法10. Laravel中数据库迁移操作的示例详解
