Freesurfer .mgz to nifti

Greetings,

I have a script that is part of my analysis and it expects aparc+aseg.nii.gz because it passes it to AFNI for resampling. The freesurfer output from fmriprep is in .mgz format(i.e. aparc+aseg.mgz). Is there a way to have fmriprep output this file as .nii.gz or does it need to be converted using a different software?

Thank you,
Yonatan

You can use mri_convert aparc+aseg.mgz aparc+aseg.nii.gz (mri_convert is a FreeSurfer command).

2 Likes

Thank you very much Steven!

1 Like

you can also use AFNI’s “@SUMA_Make_Spec_FS” which runs mri_convert under the hood and does other things to prep FS voxel and surface outputs for AFNI analyses

Hi, does anyone know how can I convert .mgz to .nii using mri_convert?

mri_convert has .nii files implemented, meaning you just have to specify an output filename that has the file ending .nii.
E.g. if you have a file T1.mgz and want to convert it to .nii, you can run
mri_convert T1.mgz T1.nii

For further information on mri_convert, see mri_convert - Free Surfer Wiki

Hi Elisabeth,

Do I run this command via terminal or just in a python script?

Hi @ShuaimingJing,
as far as I know, all freesurfer commands are run from terminal (and of course need freesurfer installed).

Gotch u. Thank you so much!