Converting DICOM Images to NIFTI Images

Note: While I will try to be verbose in my how-to guides of imaging, I assume any readers have at least basic knowledge of the command line (Terminal) and bash. If you feel lost with some of the bash references and need some additional info, here is a good beginner’s guide to bash.

Usually the first step to process structural MRI data is to convert the DICOM files from the MR scanner into a more useable format. The current “best” format for files is NIfTI. There are other formats but this is a file format that is widely used and very useable. There are problems with it (specifically with how some software deal handle it but that is a topic for a later time).

One of the best tools to convert DICOM files to NIfTI is Chris Rorden’s dcm2nii (see also his profile on the NITRC website for contact info). This is a command line tool (there is also a graphical user interface version) that wil convert just about any DICOM image to an appropriate NIfTI. dcm2nii is part of the MRIcron package – the most recent version of the software can be downloaded from this link from the NITRC website. There are Linux, Macintosh, and Windows versions of the software (as well as source code if you care to build your own version). This software is available to download for free.

After the software is downloaded and extracted, it can be run from wherever its location is. In other words, this is not “installed” software, it is run from whatever location it is saved to (for example, it could be saved in /Applications/mricronmac/ or in /Users/bbunny/neuroimaging/).

See the screenshot for an example of dcm2nii location.

In order to run dcm2nii from Terminal, move into the directory where dcm2nii is (e.g., using the command line type: cd /Applications/mricronmac/ - again, this should be where the actual dcm2nii program is on your computer).

Next, in Terminal type: ./dcm2nii and press return (enter).

This will bring up some text like this:

It gives an example of how to run the program. Also notice my default preferences. I edited the dcm2nii.ini file to have those defaults because I’ve found that they work the best for the work I do. You can also run dcm2nii from anywhere in Terminal by typing: /[path to mricronmac]/dcm2nii where [path to mricronmac is replaced with the full path to where dcm2nii is – e.g., /Applications/mricronmac/ (check out this post to see how to be able to run a program without typing in the whole path to it). I’ve found it easiest to run dcm2nii from within the folder of DICOM files I want to convert to NIfTI images. To do this first you need to move to the directory where your raw DICOMs are (I typically make a temporary copy of the files so I am not doing anything with the originals, just to prevent any potential issues): for example, /Users/Shared/DWI/blindnum001/DATA/64dir_DWI. Now from within this directory you can run dcm2nii and convert the images with the following command (or whatever is the equivalent on your computer):

/Applications/mricronmac/dcm2nii –a y –d n –e n –f y –g y –i n –r n –x n /Users/Shared/DWI/blindnum001/DATA/64dir_DWI/image001.dcm

Note: you do not need to include all those options (–a y –d n –e n –f y –g y –i n –r n –x n), I included them just to show what are the defaults that I run with dcm2nii. If you have edited the dcm2nii.ini file or if you want to use other defaults or options, go ahead – those are just the options I prefer. After the conversion completes you should have one or more NIfTI files in the same directory where your dicoms are. For diffusion weighted data you should have three files: the .nii.gz (if you selected the gzip option), a .bval, and a .bvec. The only times I’ve not had dcm2nii create bval or bvec files (and I have verified that the dicom files are not corrupted) is when I did not change the default options for dcm2nii, which resulted in overly long NIfTI file names; that, for some reason, prevented the bval and bvec files from being created. That is why I make sure output filename is only the input filename. I’ve never had any conversion issues since setting that option.

There is your conversion. You are all done with this step of neuroimaging!

Alternatively, you can use the graphical user interface for dcm2nii:

First you want to make sure your preferences look something like this:

In the GUI under File select DICOM to NifTi and locate the dicoms you wish to convert in the dialogue box that appears. After you select the files and push Open the conversion will run. When it is finished verify that you have a .nii.gz file and .bvec and .bval files. The bval file is a simple text file that includes all the b-values of the diffusion scan (e.g., for a 64 direction scan with one b0 image there will be 65 numbers in there – one 0 and 64 1000s or whatever your b weighting was for your scan. 1000 is pretty typical). I prefer using the command line because it can speed up the process but either way will result in NIfTI images.

Now we are ready to move on to another step in image processing.

About Jared Tanner

I have a a PhD in Clinical and Health Psychology with an emphasis in neuropsychology at the University of Florida. I previously studied at Brigham Young University. I am currently a Postdoctoral Associate at the University of Florida. I spend the bulk of my research time dealing with structural magnetic resonance images of the brain. My specialty is with traditional structural MR images, such as T1-weighted and T2-weighted images, as well as diffusion weighted images. I also look at the cognitive and behavioral functioning of individuals with PD and older adults undergoing orthopedic surgery. Funding for the images came from NINDS K23NS060660 (awarded to Catherine Price, University of Florida). Brain images may not be used without my written permission (grant and software requirements).

5 comments on “Converting DICOM Images to NIFTI Images

  1. ** Important!! **

    dcm2niigui *needs* to be run under Rosetta on Snow Leopard.

    good luck,

    firas

  2. Thanks for the tip about length of DTI file names. I was wondering why the conversion suddenly wasn’t outputting bval and bvec files. Thanks.

  3. Jared:

    When using dcm2nii, I always obtain – for each T1 image – three .nii.gz files: one for coronal, one for sagittal, and another for axial.
    Is there a way to output that as a single file to work on, for example, to segment using FSL’s FIRST?

    Any ideas would be greatly appreciated.

  4. Are each of the .nii.gz files complete? It’s possible that the preferences of your dcm2nii are creating the multiple files. By default dcm2nii will create a reoriented image orthogonal to the acquisition plane as well as a cropped image. Are these the images you are getting out?

  5. Hello Jared,
    sorry about my BIG delay.
    I’m getting three images, all three of them contain the full brain but only one of them won’t contain the neck, and another will not be in the classic “order” starting by the axial but the saggital cut first on fslview.
    I can get FSL to segment only two of those, and they measure different… So I’m not sure of which should I use as a trustable measure. Any ideas?

    Thanks a lot in advance!

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge