在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. Python 的 __str__ 和 __repr__ 方法對比2. IntelliJ IDEA設置默認瀏覽器的方法3. Spring security 自定義過濾器實現Json參數傳遞并兼容表單參數(實例代碼)4. IntelliJ IDEA設置背景圖片的方法步驟5. docker /var/lib/docker/aufs/mnt 目錄清理方法6. Python TestSuite生成測試報告過程解析7. 學python最電腦配置有要求么8. JAMon(Java Application Monitor)備忘記9. Python Scrapy多頁數據爬取實現過程解析10. Python OpenCV去除字母后面的雜線操作
