Ana4Dto3D - MRC CBU Imaging Wiki

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment
WHat wOrd is made by the captiaL lettErs?

location: Ana4Dto3D

Analyze 4D to 3D converter

This is a simple converter which takes file names of Analyze format images. Analyze images are usually 3D, i.e. they contain a single volume of data in three dimensions (x, y and z). However, they can also be 4D images, where there are a series of volumes in the same image file. For example, FMRI datasets consist of a series of volumes collected one after the other. It is quite common to store these in a single file, which is 4D (x,y,z,time). Unfortunately, a variety of programs that use Analyze files cannot work with 4D files, and SPM is one of them.

The ana4dto3d program converts 4D images to a series of 3D images, one for each time point. There are options for omitting the first few scans as dummy scans, and for writing out mean and variance images from the time series as diagnostic aids. It also does byte swapping as required, so can be used to byte swap 4D or 3D images (see below).

Another program that does 4D to 3D conversion, byte swapping, and a great deal else, is MriCro, by Chris Rorden. At the moment MRIcro runs only on Windows and Linux.

Getting the ana4dto3d program

The program is already installed at the CBU. If you want to download and compile it, the source and some binaries are contained in the ana4dto3d.tar.gz archive. See the archive extraction page for instructions on unpacking the archive. There are binaries for Sun/Solaris (ana4dto3d), Windows (ana4dto3d.exe) and Linux (ana4dto3d.linux). To compile on Unix, run the command:

gcc -o ana4dto3d ana4dto3d.c anautils.c

To compile on Windows, get hold of the Cygwin utilities and gcc compiler - see the Cygwin / mex file page for some tips that may be relevant. Then compile with the command line (which expects Cygwin to be on your path):

gcc -mno-cygwin -o ana4dto3d.exe ana4dto3d.c anautils.c getopt.c

Using ana4dto3d

If there is a 4D Analyze image my4dfile.img, which contains 20 volumes (time points), you could run ana4dto3d, from the directory containing the 4D image, like this:

ana4dto3d my4dfile.img

This will create a series of 20 3D images, in the same directory, called:

my4dfile_0001.img
my4dfile_0002.img
my4dfile_0003.img
my4dfile_0004.img
my4dfile_0005.img
...
my4dfile_0020.img

If you want the 3D files to go to a directory other than that containing the 4D file, put a directory name last on the command line:

ana4dto3d my4dfile.img /home/myself/3dfiles

which will put the 3D files in the /home/myself/3dfiles directory.

Byte swapping

ana4dto3d will byte swap data as required. It often happens that your Analyze file is in a different endian format that that you need for your system. For example, Intel PCs are little-endian, in that they store numbers in memory with the least significant byte first, e.g 18 is stored [in hex of course] as first byte = 2, second byte = 1. Sun machines are big-endian, so that 18 is stored in hex as first byte = 1, second byte = 2. This may mean that files stored on one type of system have their data in the wrong byte order for reading from another system.ana4dto3d deals with this, by attempting to read the image header (see the Analyze format page), and determining whether it is in the wrong byte order. If so, it byte swaps the images and headers before writing out the 3D files, so that they are in the correct byte order for the system. However, if you have other plans, you can force ana4dto3d to swap or not swap the data as you wish. Use the -w option to force ana4dto3d to byte swap the output files:

ana4dto3d -w my4dfile.img

and the -n option to prevent byte swapping, even if the header suggests this is reuqired:

ana4dto3d -n my4dfile.img

This is one way to byte swap a series of 3D files, incidentally. If you have a series of 3D Analyze images you want to byte swap, say file1.img, file2.img, file3.img, you can run ana4dto3d on them, thus:

ana4dto3d -w file1.img file2.img file3.img

to get a byte swapped set of images:

file1_0001.img
file2_0001.img
file3_0001.img

Missing off dummy scans

A problem with converting the 4D file is that the first few volumes in the 4D block often contain data you are going to discard - dummy scans. Rather than write these out and then delete them, you can use ana4dto3d to omit writing them out, with the -d option. Thus, if we have a 4D image, containing 20 volumes as above, and we do not want the first 5 images, then we can run ana4dto3d thus:

ana4dto3d -d 5 my4dfile.img

which will write out 15 images:

my4dfile_0006.img
my4dfile_0007.img
my4dfile_0008.img
my4dfile_0009.img
my4dfile_0010.img
...
my4dfile_0020.img

Mean and variance images

You may well want a mean and/or variance images for your time series. To get a mean image of the non-dummy scans, use the -m option, and to get a variance image, use the -v option. Thus, to get both:

ana4dto3d -m -v my4dfile.img

If you want only the mean / variance images, and not the 3d time points, you can use the -s (Suppress time series) option.

ana4dto3d -v -s my4dfile.img

will give you the variance image only. The mean and variance images are saved as rawmean*img and rawvar*img respectively.

MatthewBrett 24/7/00