Conversion from DICOM

From CCN Wiki
Jump to navigation Jump to search

MRI Scanners generate and save data to a native file type. These files may be proprietary, but can be converted to standard .nii files using a conversion utility.

to3d

This is an AFNI utility that converts a series of 2D DICOM or similar files, assuming sequential filenames, to a 3D file type.

Preparation

Organization

The first step will be to ensure that all the DICOM files are grouped by series. That is, it may be that your working directory contains DICOM files from multiple sequences (e.g., the folder may contain files from a scout image, and a T1 and T2 weighted scan). It makes sense to reorganize the data so that each directory contains only DICOM files from a single series.

Naming

Each DICOM file represents a 2D slice of a volume. The to3d program assembles a series of 2D slices to create a single 3D volume. Because the script infers the sequence order from the order in which the files are provided, the file names should reflect their position in the sequence. The files are likely to be sequentially numbered (e.g., file1.dcm, file2.dcm, ..., fileN.dcm), however you should check that the list of file names reflects their sequence. In particular, if there are more than 9 files, it matters whether the file numbers are zero-padded. For example:

$ ls -1 *.dcm
file10.dcm
file1.dcm
file2.dcm
file3.dcm
file4.dcm
file5.dcm
file6.dcm
file7.dcm
file8.dcm
file9.dcm

Here we see that there are 10 slices, numbered 1-10, but as listed, the 10th slice comes before the 1st slice, which will likely cause the slices to be reconstructed out of order. Basically, the person's chin will be moved to the top of their head, or something similar. We need to change how the sequence of numbers is formatted by zero-padding it. I have written a script called renumber.sh that can be found in the ubfs Scripts/Shell folder. The syntax of the file usage:

renumber.sh fileprefix fileextension

In the above example:

renumber.sh file .dcm

This will create a new subdirectory called renumbered that contains a renumbered copy of each of the files:

cd renumbered/
ls -1
file001.dcm
file002.dcm
file003.dcm
file004.dcm
file005.dcm
file006.dcm
file007.dcm
file008.dcm
file009.dcm
file010.dcm

Now the files are listed in the correct sequence.

Running to3d

The to3d command will try to launch a GUI window unless you provide an output file name as a file prefix. We generally want to convert our data to .nii (or .nii.gz) files:

to3d -prefix T1.nii file*.dcm

After this executes, you will have a new .nii file in your working directory. Of course, the file prefix you choose will depend entirely on the meaning of the data. T1.nii might be an appropriate name for T1-weighted anatomical data. FLAIR.nii would be a better name for data from a FLAIR image.