The data I have is for a specific patient so given confidentiality, I cannot share it, however here is the code for a file xyz.hdf5, I tried to print as much info as possible. If there anything else I can provide please tell me to.
#importing
import h5py
import nrrd
import numpy as np
#Read the hdf5 file
f = h5py.File('xyz.hdf5','r')
print('File name is:')
print(f.name)
print('File keys are:')
print(list(f.keys()))
Out:
File name is:
/
File keys are:
[‘volume’]
#Slicing file into ndarray
data = f['volume'][:10]
print(data.shape)
Out:
(10, 42, 73, 304)
#Copying data to NRRD file (readable by Slicer)
f_nrrd_name = 'xyz.nrrd'
nrrd.write(f_nrrd_name, data, index_order = 'C')
# Read the data back from file
readdata, header = nrrd.read(f_nrrd_name)
print(readdata.shape)
Out:
(304, 73, 42, 10)