I need to convert mutiple .nii files into one .nii.gz file.
In Matlab, I used gzip('*.nii'), but it creates multiple nii.gz files for each single nii file. How could I create one combined nii.gz file from many .nii files?
Thanks in advance
I need to convert mutiple .nii files into one .nii.gz file.
In Matlab, I used gzip('*.nii'), but it creates multiple nii.gz files for each single nii file. How could I create one combined nii.gz file from many .nii files?
Thanks in advance
If you download the Tools for NIfTI and Analyze Images library to
/tmp/tools4niftiand copy, say two instances of the T1 MNI template, e.g., from the FSL directories:/tmp$ cp $FSLDIR/data/standard/MNI152_T1_2mm.nii.gz ./copy1.nii.gz/tmp$ cp $FSLDIR/data/standard/MNI152_T1_2mm.nii.gz ./copy2.nii.gzthen you can concatenate the binary data using standard matlab functions and use the library to write the result:
You load as many
ims as you want and you can add as many arguments as you want to thecatcommand as well -- or put the whole operation in a for-loop.The library is not mine but I use it a lot, because it can load
.nii.gzfiles without additional explicit (de-)compression commands.