icon-lab / SynDiff

Official PyTorch implementation of SynDiff described in the paper (https://arxiv.org/abs/2207.08208).
Other
244 stars 37 forks source link

How to convert data into mat format #22

Closed LLLL1021 closed 1 year ago

LLLL1021 commented 1 year ago

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.

onat-dalmaz commented 1 year ago

To process nii MRI data slice by slice and insert 2D slices to mat files, you can use the following steps:

  1. Read the nii file using the niftiread function from MATLAB or the nibabel package from Python²³ . For example:
nii = niftiread('filename.nii');
import nibabel as nib
nii = nib.load('filename.nii')
  1. Extract the 3D array of MRI data from the nii object using the img attribute³. For example:
data = nii.img
  1. Loop over the slices along the desired dimension (e.g., z-axis) and save each slice as a mat file using the savemat function from scipy.io³. For example:
import scipy.io as sio
for i in range(data.shape[2]):
    slice = data[:,:,i]
    sio.savemat(f'slice_{i}.mat', {'slice': slice})
  1. Alternatively, you can save all the slices in one mat file as a 4D array with the first dimension being the number of subjects¹. For example:
slices = data.reshape((1, data.shape[0], data.shape[1], data.shape[2]))
sio.savemat('slices.mat', {'slices': slices})

I hope this helps.👍