Linking together single fMRI volumes and extracting time series.
Posted on 15. Feb, 2010 by admin in How To
In the MRI scanner we use at the AMI center (Signa VH/i 3.0T with Excite II upgrade (General Electric, Milwaukee, WI) and – I believe – in all MRI scanners, EPI volumes are saved one after the other with increasing number as filenames. While it is possible to process them like that with SPM or FSL, sometimes it is more practical to join them together into a 4D volume (with “time” being the 4th dimension). To achieve this, FSL has an utility called fslmerge. Simply open the terminal, go to the folder with all the images (hdr and img files) to join and type:
fslmerge -t output.nii *.img
This will create a 4D volume (output.nii.gz). This is very handy because now (once unzipped) you can load it with Matlab using the NIFTI tools, and easily extract voxel time series out of your 4D image so that you can perform your favorite time-varying method.
Things can be a little bit more complex if the images you are joining are not following an exact numbering. One way is to rename them, the other way is to use bash scripting in the terminal to join only the images that we want.
Suppose that you need to take only certain volumes because they are the one you are interested to analyze (e.g. one experimental condition). You can then prepare an xls file with only the volumes that you want to join (one filename per row). Save the file as volumes.csv (text only, no field delimiters) in the same folder with the volumes you want to join.
Open a terminal window and go into that folder then type:
files="";
for file in $(cat volumes.csv);do
files=$files+" "+$file;
done
fslmerge -t output.nii $files
(if you want to check that everything is fine you could type echo $files before running fslmerge).




