The past few days have seen my fMRI analysis server taken over by a Linux virtual machine. I have installed FSL, and have been using MELODIC to plough my way through ICA analyses of fcMRI data, a first for me.

One of the annoyances I have had to deal with as part of this project has been the difference in input data required for SPM, for which my preprocessing stream is targeted, and FSL, for which it is not. Specifically, this difference has necessitated the conversion of data runs from 3D NIFTI files to a single 4d NIFTI file. FSL has a utility for this (fslmerge), but being the Linux novice that I am, I have struggled to script the merging within the virtual machine.

Thankfully, SPM has a semi-hidden utility for this conversion.

SPM's 3d to 4d NIFTI conversion tool
SPM's 3d to 4d NIFTI conversion tool

The GUI is located within the Batch Editor’s SPM>Util menu, and be default saves the specified 3D NIFTI images to a single 4D NIFTI image within the same directory. It doesn’t gzip the output image, like the fslmerge script, but, it’s scriptable using the ‘View>Show .m Code’ menu option, and it’s good enough for me.


6 thoughts on “Converting 3D nifti images to a 4D image with SPM

  1. Cool. A related question – have you found a way of getting SPM to use/recognise 4D files in its pre-processing and analysis routines? Someone mentioned to me once that there was a simple little hack, but I’ve never managed to work it out. I got used to using 4D images in FSL and now when I have to use SPM all the millions of 3D images just seem so…. messy. Thanks!

    • According to;c5f8805c.0705 it’s as straightforward as changing the value in the box below the default filter setting (.*) from “1” to “1:x” where x is the maximum number of volumes you would like SPM to check for in the 4D file, e.g. 1:1000.

      I’ve had a brief try in SPM8 and it seems to work. Finding this out may have just cemented my conversion to the neat and tidy 4D NIFTI file!

      • Awesome – thanks. I had a poke around the jiscmail list a while ago looking for this trick, but didn’t manage to find that one – nice. Would be nice if they put something in the defaults file in a future version so you could just use 4D files without having to muck around with the file selector every time.

  2. Thanks for the instructions! Do you know of a way of converting/combining 3D NIFTI files into a 4D using R?


Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>