Qualcuno può dirmi il modo in cui posso leggere un set di dati contenente .mhd/ .raw file in python?Lettura formato * .mhd/*. Raw in python
5
A
risposta
5
Il modo più semplice è quello di utilizzare SimpleITK (MedPy utilizza ITK per .mhd file/.raw troppo). Comando
pip install SimpleITK
funziona per molte versioni python. Per la lettura .mhd/.RAW è possibile utilizzare questo codice 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
È possibile tenta di utilizzare MedPy o questo mhd_utils script
3
Uso skimage può essere ancora più facile dopo aver installato SimpleITK
import skimage.io as io
img = io.imread('file.mhd', plugin='simpleitk')
Questo darà una matrice NumPy con z, y, x ordinamento.
BTW, [questo] (http://stackoverflow.com/questions/37989196/how-do-i-open-mhd-file-corresponding-to-a-raw-file-in-blender-3d-tool) la domanda è la stessa. Qualcuno può unirli? – savfod