tessl install tessl/pypi-dcm2niix@1.0.5Command-line application that converts medical imaging data from DICOM format to NIfTI format with BIDS support
dcm2niix is a command-line application with Python bindings that converts medical imaging data from the DICOM format to the NIfTI format. The tool is specifically designed for neuroimaging data and handles vendor-specific DICOM interpretations. It generates BIDS-compliant JSON sidecars containing metadata in a vendor-agnostic, human-readable format.
pip install dcm2niixpip install dcm2niixfrom dcm2niix import main
# Convert DICOM folder to NIfTI
exit_code = main(["/path/to/dicom/folder"])# Basic conversion
dcm2niix /path/to/dicom/folder
# Compressed output with BIDS JSON
dcm2niix -z y -b y -o /output/folder /input/folderSee Quick Start Guide for detailed instructions.
dcm2niix wraps a high-performance C++ binary via Python subprocess:
from dcm2niix import main, bin, bin_path, __version__main(args, **run_kwargs): Execute dcm2niix binary with argumentsbin: Path to dcm2niix binary (string)bin_path: Path object pointing to binary__version__: Package version stringdcm2niix [options] <in_folder>Common options:
-o <dir>: Output directory-f <pattern>: Filename pattern-z <y/i/n>: Compression mode-b <y/n/o>: BIDS sidecar generation-i <y/n>: Ignore derived/localizer images-v <0/1/2>: Verbosity level| Code | Meaning | Action |
|---|---|---|
| 0 | Success | None |
| 2 | No valid DICOM files | Verify input directory |
| 4 | Corrupt DICOM file | Identify and remove corrupt files |
| 5 | Input folder invalid | Check path and permissions |
| 6 | Output folder invalid | Check write permissions |
| 8 | Partial success | Review verbose output |
→ Complete Exit Code Reference
| Option | Values | Default | Description |
|---|---|---|---|
-o | <dir> | input dir | Output directory |
-z | y/i/n | n | Compression (y=pigz, i=internal, n=none) |
-b | y/n/o | y | BIDS JSON (y=create, n=skip, o=only) |
-f | <pattern> | %f_%p_%t_%s | Filename pattern |
-i | y/n | n | Ignore derived/localizer images |
-v | 0/1/2 | 0 | Verbosity (0=minimal, 2=debug) |
Common placeholders for -f option:
%p: Protocol name%s: Series number%i: Patient ID%t: Study time%d: Series description%e: Echo number→ Complete Placeholder Reference
Generates BIDS-compliant JSON sidecars with:
Process multiple DICOM directories using YAML configuration files via dcm2niibatch executable.
from dcm2niix import main
exit_code = main([
"-z", "y", # Compress output
"-b", "y", # Generate BIDS JSON
"-ba", "y", # Anonymize
"-o", "/bids/output",
"/dicom/input"
])from dcm2niix import main
exit_code = main(["/input/folder"])
if exit_code == 0:
print("Success")
elif exit_code == 2:
print("No valid DICOM files found")
elif exit_code == 4:
print("Corrupt DICOM file detected")→ Complete Error Handling Guide
from dcm2niix import main
from pathlib import Path
for subject_dir in Path("/data/subjects").iterdir():
output_dir = Path("/data/nifti") / subject_dir.name
output_dir.mkdir(parents=True, exist_ok=True)
main(["-z", "y", "-b", "y", "-o", str(output_dir), str(subject_dir)])Step-by-step instructions for common tasks:
Real-world scenarios and use cases:
Complete API specifications and detailed documentation:
No output files generated
Wrong orientation
ImageOrientationPatientDICOM field in BIDS JSONMultiple unwanted files
-i y to ignore derived/localizer images-n <CRC> to convert specific series only→ Complete Troubleshooting Guide
-z y with pigz for fast parallel compression-a y for organized PACS data (assumes series in same folder)-d 1 for shallow directory search when data is organized-i y to skip derived/scout images→ Performance Optimization Guide
-p y for precise float scaling (required for quantitative analysis)--diffCyclingModeGE to override if neededfrom dcm2niix import __version__
print(__version__)dcm2niix --version