open-discussion > Converting .mat files to Nifty
Showing 1-4 of 4 posts
Dec 13, 2018 01:12 PM | Carlotta Fabris
Converting .mat files to Nifty
Hi everyone!
I have some .mat files that have been preprocessed. The people who did it told me they were preprocessed with BrainVoyager, but since they are .mat files I think they actually usede SPM.
Yesterday I wrote to the BrainVoyager support and they told me that probably NITRC would have benn helpful in the conversion.
Do you know how I can use this software to convert the files I have to nifty? When I open them in Matlab the only thing I see are cells containing double values and I wasn't expecting this giving that they should have been preprocessed using SPM.
I really don't know what to do, can you help me?
Thank you a lot,
Carlotta.
I have some .mat files that have been preprocessed. The people who did it told me they were preprocessed with BrainVoyager, but since they are .mat files I think they actually usede SPM.
Yesterday I wrote to the BrainVoyager support and they told me that probably NITRC would have benn helpful in the conversion.
Do you know how I can use this software to convert the files I have to nifty? When I open them in Matlab the only thing I see are cells containing double values and I wasn't expecting this giving that they should have been preprocessed using SPM.
I really don't know what to do, can you help me?
Thank you a lot,
Carlotta.
Dec 14, 2018 06:12 PM | Zeus Gracia-Tabuenca - University of Zaragoza
RE: Converting .mat files to Nifty
Hi Carlotta,
I've been losing my practise with matlab, but you can do it with R (and this one is free). You will need to install "R.matlab" and "RNifti" packages first. Then follow this code:
library(R.matlab)
#Import .mat to R object
mat <- readMat("/path/file.mat")
# This imports a list object, but the first element of the list [[1]] has the numeric data
vol <- mat[[1]]
#Then export that volume
library(RNifti)
nii <- updateNifti(vol)
writeNifti(nii,"/path/file.nii.gz"))
It worked for me, hope it works for you too.
Greetings.
I've been losing my practise with matlab, but you can do it with R (and this one is free). You will need to install "R.matlab" and "RNifti" packages first. Then follow this code:
library(R.matlab)
#Import .mat to R object
mat <- readMat("/path/file.mat")
# This imports a list object, but the first element of the list [[1]] has the numeric data
vol <- mat[[1]]
#Then export that volume
library(RNifti)
nii <- updateNifti(vol)
writeNifti(nii,"/path/file.nii.gz"))
It worked for me, hope it works for you too.
Greetings.
Dec 14, 2018 07:12 PM | Carlotta Fabris
RE: Converting .mat files to Nifty
Thank you a lot for the answer!
I will keep you updated on my progresses.
Thank you again,
Carlotta.
I will keep you updated on my progresses.
Thank you again,
Carlotta.
Dec 17, 2018 09:12 AM | Allen Waggoner
RE: Converting .mat files to Nifty
Hi Carlotta,
Since R2017b, Matlab has included the routine niftiwrite
https://www.mathworks.com/help/images/re...
So if your mat file also contains the header info, you should be able to easily write the nifti file.
If you have an older version of Matlab you could try this
https://www.mathworks.com/matlabcentral/...
Also, Freesurfer (https://surfer.nmr.mgh.harvard.edu/) comes with a Matlab library that includes a routine for writing nifti files.
Allen
Since R2017b, Matlab has included the routine niftiwrite
https://www.mathworks.com/help/images/re...
So if your mat file also contains the header info, you should be able to easily write the nifti file.
If you have an older version of Matlab you could try this
https://www.mathworks.com/matlabcentral/...
Also, Freesurfer (https://surfer.nmr.mgh.harvard.edu/) comes with a Matlab library that includes a routine for writing nifti files.
Allen