Skip to main content

DCM2NIIX Python package

Project description

dcm2niix

Build

About

dcm2niix is designed to convert neuroimaging data from the DICOM format to the NIfTI format. This web page hosts the developmental source code - a compiled version for Linux, MacOS, and Windows of the most recent stable release is included with MRIcroGL. A full manual for this software is available in the form of a NITRC wiki.

The DICOM format is the standard image format generated by modern medical imaging devices. However, DICOM is very complicated and has been interpreted differently by different vendors. The NIfTI format is popular with scientists, it is very simple and explicit. However, this simplicity also imposes limitations (e.g. it demands equidistant slices). dcm2niix is also able to generate a BIDS JSON format sidecar which includes relevant information for brain scientists in a vendor agnostic and human readable form. The Neuroimaging DICOM and NIfTI Primer provides details.

JavaScript/WebAssembly

To view the WASM specific README, please click here. The rest of this README is for the dcm2niix CLI program.

License

This software is open source. The bulk of the code is covered by the BSD license. Some units are either public domain (nifti*.*, miniz.c) or use the MIT license (ujpeg.cpp). See the license.txt file for more details.

Dependencies

This software should run on macOS, Linux and Windows typically without requiring any other software. However, if you use dcm2niix to create gz-compressed images it will be faster if you have pigz installed. You can get a version of both dcm2niix and pigz compiled for your operating system by downloading MRIcroGL.

Image Conversion and Compression

DICOM provides many ways to store/compress image data, known as transfer syntaxes. The COMPILE.md file describes details on how to enable different options to provide support for more formats.

  • The base code includes support for raw, run-length encoded, and classic JPEG lossless decoding.
  • Lossy JPEG is handled by the included NanoJPEG. This support is modular: you can compile for libjpeg-turbo or disable it altogether.
  • JPEG-LS lossless support is optional, and can be provided by using CharLS.
  • JPEG2000 lossy and lossless support is optional, and can be provided using OpenJPEG or Jasper.
  • GZ compression (e.g. creating .nii.gz images) is optional, and can be provided using either the included miniz or the popular zlib. Of particular note, the Cloudflare zlib exploits modern hardware (available since 2008) for very rapid compression. Alternatively, you can compile dcm2niix without a gzip compressor. Regardless of how you compile dcm2niix, it can use the external program pigz for parallel compression.
  • Zstandard compression (creating .nii.zst images via -z s) is optional, and can be enabled with -DUSE_ZSTD=ON (CMake) or ZSTD=1 make (Makefile). Zstandard offers a favorable compression/speed tradeoff compared to gzip.
  • Siemens physio recordings stored as DICOM (XA30/XA60 PhysioLogging Raw Data Storage SOPs carrying a gzipped XML payload, and legacy CMRR Multi-Band VE11C PMU DICOMs carrying a raw binary blob in the Siemens CSA Non-Image Storage SOP) are extracted to BIDS-compliant _recording-<label>_physio.tsv.gz files with companion .json sidecars (cardiac/respiratory/ecg/external_trigger streams), rather than skipped as non-image. For CMRR streams that carry firmware-detected R-wave / respiratory peaks, the TSV is 3 columns — [<signal>, trigger, <signal>_trigger] — where column 2 is BIDS-canonical scanner volume triggers (byte-compatible with bidsphysio) and column 3 carries the per-stream physiological events. The EXT stream is the one exception: its peak column is named external_trigger_peak rather than external_trigger_trigger. The sibling regression set dcm_qa_physio documents the column layout, the VALUE=2048 trigger-sentinel encoding, and the deliberate divergence from bidsphysio (which remains the canonical post-processor for richer cases).
  • MR spectroscopy (Siemens VB/VE/XA SVS + single-DICOM Enhanced CSI, Philips classic + Enhanced SVS, UIH SVS + single-DICOM 2D/3D MRSI) is converted to BIDS-MRS compliant complex-float NIfTI + .json sidecars (including _mrsi suffix and a 4×4 VOI matrix emitted when sufficient source VOI metadata is present). Multi-DICOM classic Siemens CSI/MRSI is not supported. Non-square UIH MRSI grids produce correct dim/payload alignment matching spec2nii (dcm2niix deliberately mirrors spec2nii's transposed affine/data-shape coupling for byte parity). Philips classic 2× payloads emit a paired <stem>_mrsref.nii.gz water-reference companion; standalone water-reference acquisitions (wrsoff / no_Water_Suppression series-naming) are relabeled _mrsref with WaterSuppressed: false. Vendor-sequence-state-specific reshapes / splits (CMRR sLASER DKD reference-scan ordering, Philips MEGA-PRESS edit ON/OFF interpretation) are intentionally NOT done in C — dcm2niix ships raw bundled NIfTIs. The sibling Python tool tools/mrs_post.py (pydicom + numpy) consumes those outputs to produce spec2nii-equivalent split / reshaped files when desired. Ported from spec2nii (BSD-3-Clause, William Clarke, U. Oxford). MRS regression / validation corpus lives in the sibling dcm_qa_mrs repo — current parity: 23/40 PASS bare, 30/40 PASS via --with-mrs-post, 10 SKIP bounded by spec2nii reference availability.

ReproIn one-pass naming (-f %H)

dcm2niix can emit ReproIn/heudiconv-style BIDS filenames in a single pass via the -f %H format specifier, with the optional -bi (subject), -bv (session), and -br (project subdirectory) flags. A companion script tools/reproinx.py handles cross-series concerns (fmap pairing, _scans.tsv, B0FieldIdentifier/B0FieldSource, session backfill, root scaffolding, plus cross-series reclassification such as short reverse-PE EPIs to fmap/_epi and rescue of session-first/suffix-last protocols that the one-pass parser cannot name) and accepts --anonymize, --strict, --keep-derivatives, --no-convert, --min-volumes/-N, and --shift-dates (BIDS-recommended date de-identification: per-subject shift to 1925 preserving relative timing) flags. The anonymisation flag -ba has three modes: y (default; strip dates and patient PII), n (keep both), o (omit patient PII only — keep acquisition timestamps so reproinx's _scans.tsv and fmap closest-time pairing still work). See REPROIN.md for the full grammar, defaults, privacy considerations, and known limitations.

Versions

See releases for recent release notes. See the VERSIONS.md file for details on earlier releases.

Contribute

dcm2niix is developed by the community for the community and everybody can become a part of the community. Pull requests should target the development branch — master is reserved for tagged stable releases.

Running

Command line usage is described in the NITRC wiki. The minimal command line call would be dcm2niix /path/to/dicom/folder. However, you may want to invoke additional options, for example the call dcm2niix -z y -f %p_%t_%s -o /path/output /path/to/dicom/folder will save data as gzip compressed, with the filename based on the protocol name (%p) acquisition time (%t) and DICOM series number (%s), with all files saved to the folder "output". For more help see help: dcm2niix -h.

See the BATCH.md file for instructions on using the batch processing version.

Install

There are a couple ways to install dcm2niix

  • Github Releases provides the latest compiled executables. This is an excellent option for MacOS and Windows users. However, the provided Linux executable requires a recent version of Linux (e.g. Ubuntu 14.04 or later), so the provided Unix executable is not suitable for very old distributions. Specifically, it requires Glibc 2.19 (from 2014) or later. Users of older systems can compile their own copy of dcm2niix or download the compiled version included with MRIcroGL Glibc 2.12 (from 2011, see below).
  • Run the following command to get the latest release version for Linux, Macintosh or Windows:
    • curl -fLO https://github.com/rordenlab/dcm2niix/releases/latest/download/dcm2niix_lnx.zip
    • curl -fLO https://github.com/rordenlab/dcm2niix/releases/latest/download/macos_dcm2niix.pkg
    • curl -fLO https://github.com/rordenlab/dcm2niix/releases/latest/download/dcm2niix_win.zip
  • Latest development builds are available as artifacts from GitHub Actions for Linux, Macintosh, and Windows.
  • MRIcroGL (NITRC) or MRIcroGL (GitHub) includes dcm2niix that can be run from the command line or from the graphical user interface (select the Import menu item). The Linux version of dcm2niix is compiled on a holy build box, so it should run on any Linux distribution.
  • If you have a MacOS computer with Homebrew or MacPorts you can run brew install dcm2niix or sudo port install dcm2niix, respectively.
  • If you have Conda, conda install -c conda-forge dcm2niix on Linux, MacOS or Windows.
  • If you have pip, python -m pip install dcm2niix on Linux, MacOS or Windows.
  • On Debian Linux computers you can run sudo apt-get install dcm2niix.

Build from source

It is often easier to download and install a precompiled version. However, you can also build from source.

Build command line version with cmake (Linux, MacOS, Windows)

cmake and pkg-config (optional) can be installed as follows:

Ubuntu: sudo apt-get install cmake pkg-config

MacOS: brew install cmake pkg-config or sudo port install cmake pkgconfig

Once these tools are available, you can compile with cmake:

git clone https://github.com/rordenlab/dcm2niix.git
cd dcm2niix
mkdir build && cd build
cmake -DZLIB_IMPLEMENTATION=zlib-ng -DUSE_JPEGLS=ON -DUSE_OPENJPEG=GitHub ..
make

dcm2niix will be created in the bin subfolder. To install on the system run make install instead of make - this will copy the executable to your path so you do not have to provide the full path to the executable.

In rare case if cmake fails with the message like "Generator: execution of make failed", it could be fixed by sudo ln -s `which make` /usr/bin/gmake.

Building the command line version without cmake

This is the simplest way to compile dcm2niix on a Linux or MacOS computer. Be warned that this minimal version will not be able to extract DICOM images compressed with the (rarely used) JPEG2000 or JPEG-LS formats.

git clone https://github.com/rordenlab/dcm2niix.git
cd dcm2niix/console
make
./dcm2niix

Referencing

  • Li X, Morgan PS, Ashburner J, Smith J, Rorden C (2016) The first step for neuroimaging data analysis: DICOM to NIfTI conversion. J Neurosci Methods. 264:47-56. doi: 10.1016/j.jneumeth.2016.03.001. PMID: 26945974

Alternatives

  • BIDS-converter hosts Matlab and Python scripts for PET images, supporting DICOM and ECAT (ecat2nii) formats.
  • dcm2nii is the predecessor of dcm2niix. It is deprecated for modern images, but does handle image formats that predate DICOM (proprietary Elscint, GE and Siemens formats).
  • Python dcmstack DICOM to Nifti conversion with meta data preservation.
  • dicm2nii is written in Matlab. The Matlab language makes this very scriptable.
  • dicom2nifti uses the scriptable Python wrapper utilizes the high performance GDCMCONV executables.
  • dicomtonifti leverages VTK.
  • dimon and to3d are included with AFNI.
  • dinifti is focused on conversion of classic Siemens DICOMs.
  • DWIConvert converts DICOM images to NRRD and NIfTI formats.
  • mcverter a great tool for classic DICOMs.
  • mrd2nii converts ISMRMRD data into NIfTI images.
  • mri_convert is part of the popular FreeSurfer package.
  • MRtrix mrconvert is a useful general purpose image converter and handles DTI data well. It is an outstanding tool for modern Philips enhanced images.
  • nanconvert uses the ITK library to convert DICOM from GE and proprietary Bruker to standard formats like DICOM.
  • Plastimatch is a Swiss Army knife - it computes registration, image processing, statistics and it has a basic image format converter that can convert some DICOM images to NIfTI or NRRD.
  • Simple Dicom Reader 2 (Sdr2) uses dcmtk to read DICOM images and convert them to the NIfTI format.
  • SlicerHeart extension is specifically designed to help 3D Slicer support ultra sound (US) images stored as DICOM.
  • spec2nii converts MR spectroscopy to NIFTI.
  • SPM12 is one of the most popular tools in the field. It includes DICOM to NIfTI conversion. Being based on Matlab it is easy to script.

Links

dcm2niix is a core dependency of BIDS converters:

The following tools exploit dcm2niix

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dcm2niix-1.0.20260724.tar.gz (754.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

dcm2niix-1.0.20260724-cp38-abi3-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.8+Windows x86-64

dcm2niix-1.0.20260724-cp38-abi3-musllinux_1_2_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

dcm2niix-1.0.20260724-cp38-abi3-musllinux_1_2_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ ARM64

dcm2niix-1.0.20260724-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

dcm2niix-1.0.20260724-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

dcm2niix-1.0.20260724-cp38-abi3-macosx_11_0_arm64.whl (941.6 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

dcm2niix-1.0.20260724-cp38-abi3-macosx_10_9_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.8+macOS 10.9+ x86-64

File details

Details for the file dcm2niix-1.0.20260724.tar.gz.

File metadata

  • Download URL: dcm2niix-1.0.20260724.tar.gz
  • Upload date:
  • Size: 754.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for dcm2niix-1.0.20260724.tar.gz
Algorithm Hash digest
SHA256 33cce4cf2977fd17b3ebdaad2903668f2a937ffb3107235a7a8899e2fba4e0c8
MD5 ad3052fba61d2179b3ba25695ae5c5aa
BLAKE2b-256 723ec59ff7d1abbd3160a97234a8df3bd11eaa2ed10baa159d51404990f996ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for dcm2niix-1.0.20260724.tar.gz:

Publisher: release.yml on rordenlab/dcm2niix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dcm2niix-1.0.20260724-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for dcm2niix-1.0.20260724-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bc089bdc040383948d4a39e9374171456a553d2099b188846f5f1b75f0bd79df
MD5 7174c140425e2a276d953df16346eb08
BLAKE2b-256 63ce0fbdf9f5f06ddb09b6a874e62695504f5ce97f3604ed552810cf88fa2ead

See more details on using hashes here.

Provenance

The following attestation bundles were made for dcm2niix-1.0.20260724-cp38-abi3-win_amd64.whl:

Publisher: release.yml on rordenlab/dcm2niix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dcm2niix-1.0.20260724-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for dcm2niix-1.0.20260724-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c36e3d00bb46deec9dac16d80dca640601962e01caef394dae5cea86e6b58fd0
MD5 918c644e2df90072c92a047793de54f6
BLAKE2b-256 a459e4969ca5e1b6fb71878ee19799ab74a00e94f467da4605485d6606da734c

See more details on using hashes here.

Provenance

The following attestation bundles were made for dcm2niix-1.0.20260724-cp38-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on rordenlab/dcm2niix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dcm2niix-1.0.20260724-cp38-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for dcm2niix-1.0.20260724-cp38-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 ec45752ba61992f7ceabf909632c90a113fa3484bc8c49415391e66785819dd8
MD5 16d0044f59504aa99644f03ba534ab33
BLAKE2b-256 62bde4203c14ac6f8a2e9955ee6b47d727322cba2602039eab30a38deba9df3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for dcm2niix-1.0.20260724-cp38-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on rordenlab/dcm2niix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dcm2niix-1.0.20260724-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for dcm2niix-1.0.20260724-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 92381fab09e97f517d2f1120b0d4d8c00f0ed9dddabc70a56abd4e003ec59344
MD5 6699659b31b90ea21a9c1476c09cb736
BLAKE2b-256 ede69665e8cf8c7b37d5cf646dfa2941804388e11bf79c66576a8e85b5144f62

See more details on using hashes here.

Provenance

The following attestation bundles were made for dcm2niix-1.0.20260724-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on rordenlab/dcm2niix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dcm2niix-1.0.20260724-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for dcm2niix-1.0.20260724-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a2e6f4a5c19395f9bf4f29e76c46e0eb3fc538c757bf86a2c25ac8c18a7807f0
MD5 7ce54226f0ac19cf5972827f2345ef32
BLAKE2b-256 73de55aa5aeda045a9c9437a8ea8ebeb1e5e5f1cb582f5b2dd11969ceaa477b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for dcm2niix-1.0.20260724-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on rordenlab/dcm2niix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dcm2niix-1.0.20260724-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dcm2niix-1.0.20260724-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 71961b21a011e1f188cbc8b558f5dde0cd6f26fac4a1278758f15fa5c3d7aea8
MD5 5b41e52a95ac0ff09b7dc1031c9b02fe
BLAKE2b-256 98f3b8557f256aa7c5ad911a63cd613fd43d62be43a0d3fbdb5bb5794112d033

See more details on using hashes here.

Provenance

The following attestation bundles were made for dcm2niix-1.0.20260724-cp38-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on rordenlab/dcm2niix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dcm2niix-1.0.20260724-cp38-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for dcm2niix-1.0.20260724-cp38-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 51af5a71679b1c62e4d12f3d6c829a5f938bfc1cb1c44ee70857552ac09e3415
MD5 fdc2e2a8f0894de125b98315a4acdb90
BLAKE2b-256 409ac756c7705082159e54cc98986d260f9c4d4aef700e320271fc6e187e918d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dcm2niix-1.0.20260724-cp38-abi3-macosx_10_9_x86_64.whl:

Publisher: release.yml on rordenlab/dcm2niix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page