Nifty file process
20221024
使用nibabel库
import nibabel as nib
nifti_data_object = nib.load(‘example.nii.gz’)
nifti_image_data = nifti_data_object.get_fdata()
print(nifti_data_object)
plt.figure(figsize=(8, 8))
plt.imshow(a_nifti[:,:,80], 'gray', interpolation='none')
plt.imshow(b_nifti[:,:,80], 'jet', alpha=0.5, interpolation='none')
plt.show()
nifti_data_header = nifti_data_object.header
# Write nii data
nifti_data_object = nib.Nifti1Image(nifti_image_data, np.eye(4))
nib.save(nifti_data_object, ‘example.nii.gz’)