任何人都可以告訴我,我可以閱讀包含.mhd/ .raw文件在Python中的數據集?閱讀* .mhd/*。原始格式在python
5
A
回答
5
最簡單的方法是使用SimpleITK(MedPy使用ITK的.mhd/.RAW文件也是如此)。命令
pip install SimpleITK
適用於許多python版本。對於閱讀.mhd/.RAW您可以使用此代碼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
你可以嘗試使用MedPy或本mhd_utils script
3
使用skimage安裝SimpleITK
import skimage.io as io
img = io.imread('file.mhd', plugin='simpleitk')
後,這會給你與Z A numpy的陣列可能會更容易,Y, x排序。
相關問題
- 1. 閱讀原始文件C++
- 2. 如何在原始格式
- 3. 閱讀原始粘貼在C++
- 4. 在Python中閱讀原始二進制圖像
- 5. 閱讀Python中的JSON格式文件
- 6. 閱讀Python中的格式化多行
- 7. 閱讀格式90
- 8. 閱讀JSON格式
- 9. 閱讀ePub格式
- 10. 閱讀Android原始文本文件
- 11. 閱讀原始文件與Unicode字符
- 12. 閱讀原始音頻文件
- 13. 閱讀PE32 +部分的原始數據
- 14. 閱讀原始內容的PDF文件
- 15. 閱讀在Python
- 16. 閱讀在Python
- 17. 閱讀在Python
- 18. 閱讀在python
- 19. Python在原始模式標準輸入打印添加空格
- 20. 閱讀HITRAN文件格式
- 21. 如何閱讀JSON格式
- 22. 文件閱讀格式
- 23. 閱讀DICOM文件格式
- 24. 閱讀某種格式
- 25. 閱讀半格式數據
- 26. 閱讀UTF-8格式
- 27. 閱讀MathType MTEF格式
- 28. 閱讀格式從文件
- 29. 以html格式閱讀excel
- 30. 使用Python中的SimpleITK讀取mhd文件時出錯
順便說一句,[this](http://stackoverflow.com/questions/37989196/how-do-i-open-mhd-file-corresponding-to-a-raw-file-in-blender-3d-tool )問題是一樣的。有人可以合併它們嗎? – savfod