dcm2niix is primarily designed to convert DICOM images into NIfTI images. However, it does include a primitive ability to organize and rename DICOM images without converting them. This can be useful, as DICOM images are often stored with random file names that make it difficult to recognize the images.
dcm2niix renames and copies the DICOM images, but the current version does not copy or create a new DICOMDIR file. Most users ignore these files. However, you should not use this feature if you wish to preserve your DICOMDIR files.
Note that this feature only copies your DICOM images with a new filename. It does not modify the contents of the DICOM header. This means it will not compress or anonymize your files. Free tools for these functions include dcmcjpeg, gdcmanon and gdcmconv.
In addition, this tool assumes that the DICOM images can be uniquely identified by the filenaming argument you provide.
The command line argument -r y
instructs dcm2niix to rename your DICOM files rather than convert them. It does not delete your DICOM images, but rather creates a copy with the organization specified by the filenaming argument -f
. Here is an example where the DICOM images will be sorted into folders, with the folder name reflecting the study time (%t
) and series number (%s
), each DICOM image will be named based on the image number (%r
) which will be padded with zeros to fill 5 characters.
dcm2niix -r y -f %t_%s/%5r.dcm -o ~/out ~/in
Therefore, the 9th DICOM image from series 3 acquired on 4 February 2012 would be saved as ~/out/20120204084424_3/00009.dcm.
It is very important that your file naming disambiguates all your images. For example, consider a naming scheme that only used the image number (-f %r.dcm
) and was applied to multiple series (each which had an image number 1,2,...). When there are naming conflicts, dcm2niix will terminate with an error message, e.g. Error: File naming conflict. Existing file /home/c/dcm/1.dcm
.
A special situation is the fieldmaps generated by Siemens scanners. Users often acquire gradient-echo fieldmaps so they can undistort EPI images. These fieldmaps acquire two (or more) echoes. Unfortunately, Siemens will give each of these echoes an identical series and image number. DICOM tools that are unaware of this often overwrite some of the images from each echo. To combat this situation, dcm2niix will add the post-fix _e2
to the second echo. Therefore, if you converted a series with -f %s_%4r
your fieldmap might generate files named 5_0001.dcm
and 5_0001_e2.dcm
. Note you could also explicitly number each echo (-f %s_%4r_%e
), though in this case all your series (not just the fieldmaps) will have the echo appended.
An advantage of using dcm2niix is simplicity: it is a free, single file executable that you can download that is available for MacOS, Linux and Windows that you can run from the command line. On the other hand, this simplicity means it is fairly inflexible. You may want to consider a DICOM renamer built in your favorite scripting language.
- dicomsort is a Python script.
- rename_dir is a Matlab script that requires the proprietary Image Processing Toolbox.
- dicm2nii includes the Matlab script rename_dicm that does not require any additional toolboxes.
- [DICOMSort provides a nice graphical interface]https://dicomsort.com/downloads.html), providing a nice alternative for scripting and command line solutions.