Closed LLLL1021 closed 1 year ago
To process nii MRI data slice by slice and insert 2D slices to mat files, you can use the following steps:
nii = niftiread('filename.nii');
import nibabel as nib
nii = nib.load('filename.nii')
data = nii.img
import scipy.io as sio
for i in range(data.shape[2]):
slice = data[:,:,i]
sio.savemat(f'slice_{i}.mat', {'slice': slice})
slices = data.reshape((1, data.shape[0], data.shape[1], data.shape[2]))
sio.savemat('slices.mat', {'slices': slices})
I hope this helps.👍
Hello, thank you very much for your contribution. I want to know what the size of the mat file you provided is. Do you store 3D MRI data or 2D MRI images in the mat file? I can't open it with MATLAB software. My data format is. nii, which is three-dimensional data. How can I convert it into mat format data? Thank you very much for your help. In addition, I want to know that two fields of data are needed in the training stage, so why should I input the data of two fields after training? Shouldn't it be possible to complete the transformation from one domain data to another after training? Thank you very much for your help.