Convert DICOM files to NIFTI files

This recipe provides code for converting DICOM (.dcm) files to NIFTI (.nii) files

dcm2niix

  • This recipe converts dicom to nifti files using the program dcm2niix
  • https://github.com/rordenlab/dcm2niix
  • The only required argument for dcm2niix is the location of the folder with the DICOM files to convert, which is always the final argument provided.
# install dcm2niix (for mac)
curl -fLO https://github.com/rordenlab/dcm2niix/releases/latest/download/dcm2niix_mac.zip

# convert dicom files found in dicomdir, output to outdir
dcm2niix -o ~/outdir ~/dicomdir

dcm2niibatch (batch conversions)

dcm2niibatch batch_config.yml

dcm2niix_afni (AFNI)

1
2
#!/bin/bash 
dcm2niix_afni -o ~/outputdir ~/dicomdir

dicom2nifti (python)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# install using pip
pip install dicom2nifti

# Run
import dicom2nifti

# run from commandline:
dicom2nifti /dicom_directory /output_directory

# run from python: 
dicom2nifti.convert_directory(dicom_directory, output_directory, compression=True, reorient=True)

Recipe made by Bari Fuchs

These recipes may also be of interest