tessl install tessl/pypi-dcm2niix@1.0.5Command-line application that converts medical imaging data from DICOM format to NIfTI format with BIDS support
Complete reference for all dcm2niix command-line options. All options can be passed through the Python API via main(args=[...]).
dcm2niix [options] <in_folder>| Option | Values | Default | Description |
|---|---|---|---|
-o | <dir> | input dir | Output directory |
-f | <pattern> | %f_%p_%t_%s | Filename pattern |
-z | y/i/n/3/o | n | Compression mode |
-e | n/y/o/j/b | n | Export format |
-b | y/n/o | y | BIDS sidecar |
-ba | y/n | y | Anonymize BIDS |
-i | y/n | n | Ignore derived |
-m | n/y/0/1/2 | 2 | Merge 2D slices |
-v | n/y/0/1/2 | 0 | Verbosity |
-x | y/n/i | n | Crop 3D |
-l | y/n/o | o | 16-bit scaling |
-p | y/n | y | Philips precise |
-n | <CRC> | none | Series filter |
-s | y/n | n | Single file mode |
-d | 0-9 | 5 | Search depth |
-a | y/n | n | Adjacent DICOMs |
-w | 0/1/2 | 2 | Name conflicts |
Control output file compression.
-1-2-3-4-5-6-7-8-9Gzip compression level (1=fastest, 9=smallest). Default: 6.
Usage:
dcm2niix -9 -z y /input/folderPerformance Impact:
Recommendation: Use default (6) unless storage is critical (then use 9).
-z <y/i/n/3/o>Gzip compression mode:
y = use pigz (parallel gzip, fastest)i = internal compression (miniz or zlib)n = no compression3 = no compression, force 3D outputo = optimal pigz (Unix only, auto-selects best method)Default: n (no compression).
Mode Comparison:
| Mode | Speed | CPU Usage | Requirements |
|---|---|---|---|
y | Fastest | Multi-core | pigz installed |
i | Medium | Single-core | None |
n | N/A | Minimal | None |
o | Variable | Multi-core | pigz (Unix only) |
Installation:
# macOS
brew install pigz
# Ubuntu/Debian
sudo apt-get install pigz
# CentOS/RHEL
sudo yum install pigzPython Usage:
from dcm2niix import main
# Use pigz compression
exit_code = main(["-z", "y", "-9", "/input/folder"])Specify where files are saved and in what format.
-o <directory>Output directory path. If omitted, files are saved to the input folder.
Behavior:
Examples:
# Absolute path
dcm2niix -o /data/nifti/output /data/dicom/input
# Relative path
dcm2niix -o ./output ./input
# Same as input (default)
dcm2niix /data/dicomPython Usage:
from dcm2niix import main
from pathlib import Path
output_dir = Path("/output/nifti")
output_dir.mkdir(parents=True, exist_ok=True)
exit_code = main(["-o", str(output_dir), "/input/dicom"])-e <format>Export format:
n = NIfTI (.nii or .nii.gz, default)y = NRRD (.nrrd, N-dimensional rectilinear grid)o = MGH/MGZ (.mgh/.mgz, FreeSurfer format)j = JNIfTI (.jnii, JSON-based NIfTI, requires compile support)b = BJNIfTI (.bnii, Binary JSON NIfTI, requires compile support)Default: n (NIfTI).
Format Details:
| Format | Extension | Use Case | Compression |
|---|---|---|---|
| NIfTI | .nii.gz | Neuroimaging (standard) | Yes (with -z) |
| NRRD | .nrrd | Scientific visualization | Optional |
| MGH | .mgz | FreeSurfer workflows | Yes (built-in) |
| JNIfTI | .jnii | JSON-readable | Optional |
| BJNIfTI | .bnii | Binary JSON | Yes |
Examples:
# NIfTI (default)
dcm2niix -e n -z y /input
# NRRD for visualization
dcm2niix -e y /input
# MGH for FreeSurfer
dcm2niix -e o -z y /inputPython Usage:
from dcm2niix import main
# Export to MGH format
exit_code = main(["-e", "o", "/freesurfer/input"])Customize output filenames using pattern templates.
-f <pattern>Filename pattern using placeholders. Default: %f_%p_%t_%s (folder_protocol_time_series).
Available Placeholders:
Patient Identifiers (anonymized when -ba y):
%i = Patient ID (0010,0020)%n = Patient name (0010,0010)%w = Weird/personal data (DOB, gender, weight, institution - PHI)Study Identifiers:
%g = Accession number (0008,0050)%x = Study ID (0020,0010)%k = Study instance UID (0020,000D)%t = Study time (formatted from 0008,0020 and 0008,0030)%l = Local procedure step description (0040,0254)Series Identifiers:
%s = Series number (0020,0011)%j = Series instance UID (0020,000E)%d = Series description (0008,103E)%p = Protocol name (0018,1030)%z = Sequence name (0018,0024)%q = Sequence number (if compiled with mySegmentByAcq)Instance Identifiers:
%r = Instance number (0020,0013)%u = Acquisition number (0020,0012)%e = Echo number (0018,0086)%y = Youth in series (GE RawDataRunNumber or TemporalPosition)Hardware Identifiers:
%m = Manufacturer (short: GE, Ph, Si, To, UI, NA)%v = Vendor (long: Siemens, Philips, GE, etc.)%a = Antenna/coil name (Siemens-specific, 0051,100F)File/Folder Identifiers:
%f = Folder name (directory containing first DICOM)%b = Basename (filename of first DICOM file)Other:
%c = Comments (DICOM tag 0020,4000)%h = Hazardous/experimental BIDS naming (ReproIn format)%o = Media object instance UID (0002,0003)Pattern Examples:
# Simple: protocol and series number
dcm2niix -f %p_%s /input
# Output: T1_MPRAGE_5.nii
# BIDS-style with subject
dcm2niix -f sub-%i_%p /input
# Output: sub-12345_T1_MPRAGE.nii
# Detailed with timestamp
dcm2niix -f %p_%t_%s_%e /input
# Output: T1_MPRAGE_20230115143022_5_1.nii
# Manufacturer and protocol
dcm2niix -f %m_%v_%p /input
# Output: Si_Siemens_T1_MPRAGE.niiPython Usage:
from dcm2niix import main
# BIDS-compliant naming
exit_code = main([
"-f", "sub-%i_ses-%x_%p_%s",
"-o", "/bids/output",
"/dicom/input"
])Warning about PHI:
%w includes DOB, gender, weight - contains PHI (Protected Health Information)%i and %n are patient identifiers - use -ba y to anonymize-ba y and -bi to override subject ID-w <0/1/2>Name conflict behavior when output file already exists:
0 = skip duplicates (don't convert)1 = overwrite existing file2 = add suffix to create new file (default)Default: 2 (add suffix).
Behavior Details:
| Mode | Action | Use Case |
|---|---|---|
| 0 | Skip | Avoid reprocessing, faster re-runs |
| 1 | Overwrite | Update outputs, replace old versions |
| 2 | Add suffix | Preserve both versions, comparison |
Suffix Pattern:
filename_i.niifilename_j.niifilename_k.niiExamples:
# Skip existing files (fast re-run)
dcm2niix -w 0 /input
# Overwrite existing files
dcm2niix -w 1 /input
# Create new files with suffix (default)
dcm2niix -w 2 /inputPython Usage:
from dcm2niix import main
# Only convert new files
exit_code = main(["-w", "0", "/input"])
# Exit code 0 even if files were skipped--terseOmit filename postfixes for multi-volume datasets.
Warning: Can cause files to overwrite each other if multiple volumes exist.
Disabled Postfixes:
_e1, _e2 (multi-echo)_c1, _c2 (multi-coil)_i, _j (name conflicts)_r1, _r2 (multiple repetition times)Retained Postfixes:
_real, _imaginary, _ph (complex data - essential)_ADC, _fieldmaphz (derived volumes - essential)_MoCo, _Eq, _Tilt (processing indicators - important)Use Case: Single-echo, single-volume datasets where postfixes are redundant.
Example:
# Without --terse (default)
dcm2niix /single/echo/t1
# Output: T1_MPRAGE_5.nii
# With --terse
dcm2niix --terse -f %p /single/echo/t1
# Output: T1_MPRAGE.niiPython Usage:
from dcm2niix import main
exit_code = main(["--terse", "-f", "%p", "/input"])Brain Imaging Data Structure (BIDS) compliance.
-b <y/n/o>BIDS JSON sidecar generation:
y = create JSON sidecar alongside NIfTI (default)n = no JSON sidecaro = only JSON, no NIfTI fileDefault: y.
JSON Sidecar Contains:
Mode Comparison:
| Mode | NIfTI | JSON | Use Case |
|---|---|---|---|
y | ✓ | ✓ | Standard conversion with metadata |
n | ✓ | ✗ | Minimal output, no metadata needed |
o | ✗ | ✓ | Metadata extraction only |
Examples:
# Standard BIDS (default)
dcm2niix -b y /input
# No JSON metadata
dcm2niix -b n /input
# Only extract metadata
dcm2niix -b o /inputPython Usage:
from dcm2niix import main
# Metadata extraction only
exit_code = main(["-b", "o", "/input"])
# Creates .json files, no .nii files-ba <y/n>Anonymize BIDS JSON output by removing patient identifying information. Default: y (anonymize).
Removed Fields When Enabled:
Retained Fields:
Examples:
# Anonymized (default)
dcm2niix -ba y /input
# Include patient info
dcm2niix -ba n /inputPython Usage:
from dcm2niix import main
# Non-anonymized for internal use
exit_code = main(["-b", "y", "-ba", "n", "/internal/data"])HIPAA Compliance: -ba y removes direct identifiers but may not fully de-identify data. Review HIPAA Safe Harbor or Expert Determination methods for complete de-identification.
-bi <subject_id>BIDS subject ID override. Sets the subject identifier in output filenames and JSON metadata.
Effect:
-f filename pattern for BIDS naming-b y)Example:
# Set subject ID
dcm2niix -bi sub-001 -f sub-%bi_%p /input
# Output: sub-sub-001_T1_MPRAGE.nii
# Better: let -f handle prefix
dcm2niix -bi 001 -f sub-%bi_%p /input
# Output: sub-001_T1_MPRAGE.niiPython Usage:
from dcm2niix import main
subject_ids = ["001", "002", "003"]
for subj in subject_ids:
exit_code = main([
"-bi", f"sub-{subj}",
"-f", f"sub-{subj}_%p",
"-o", f"/bids/sub-{subj}",
f"/dicom/{subj}"
])-bv <session_id>BIDS session/visit identifier. Sets the session identifier in output filenames and JSON metadata.
Effect:
-bi for full BIDS pathsExample:
# Set session ID
dcm2niix -bi 001 -bv ses-01 -f sub-%bi_%bv_%p /input
# Output: sub-001_ses-01_T1_MPRAGE.niiPython Usage:
from dcm2niix import main
# Multi-session study
for subject in subjects:
for session in sessions:
exit_code = main([
"-bi", subject,
"-bv", session,
"-f", f"sub-{subject}_ses-{session}_%p",
"-o", f"/bids/sub-{subject}/ses-{session}",
f"/dicom/{subject}/{session}"
])Control how dcm2niix searches for DICOM files.
-d <0-9>Directory search depth. How many levels deep to search for DICOM files in subdirectories. Default: 5.
Values:
0 = only search specified folder, no subdirectories1-9 = search N levels deepPerformance Impact:
Examples:
# Flat directory
dcm2niix -d 0 /flat/dicom/folder
# Deep nesting
dcm2niix -d 9 /deeply/nested/structurePython Usage:
from dcm2niix import main
# Fast conversion of organized data
exit_code = main(["-d", "1", "/organized/pacs/export"])-a <y/n>Adjacent DICOMs mode. When enabled, assumes all images from the same series are in the same folder, allowing faster conversion. Default: n (search all folders).
Behavior:
| Mode | Behavior | Performance | Safety |
|---|---|---|---|
y | Assume series in same folder | Fast | Requires organized data |
n | Search all folders for series | Slow | Safe for mixed data |
When to Use:
y: PACS exports where each series has its own subfoldern: Mixed data, unknown organization, research archivesExamples:
# Fast mode for PACS export
dcm2niix -a y -d 1 /pacs/export
# Safe mode for mixed data
dcm2niix -a n -d 5 /research/archivePython Usage:
from dcm2niix import main
# Optimized for organized PACS data
exit_code = main(["-a", "y", "-d", "1", "/pacs/export"])-q <y/l/n>Directory search reporting:
y = show number of DICOMs found (default)l = list all DICOM files found with details (including CRC)n = no search reporting (quiet)Default: y.
List Mode Output Format:
Found 240 DICOM files in /dicom/folder
Series 001: T1_MPRAGE [52301] - 176 files
Series 002: T2_FLAIR [52305] - 32 files
Series 003: BOLD_fMRI [52310] - 240 filesUse Cases:
y: Standard feedbackl: Identify series CRC for selective conversionn: Batch processing scripts, minimal outputExamples:
# List all series with CRC values
dcm2niix -q l /dicom/folder
# Quiet mode for scripts
dcm2niix -q n /dicom/folderPython Usage:
from dcm2niix import main
import re
# Get series list
result = subprocess.run(
[bin, "-q", "l", "/dicom/folder"],
capture_output=True,
text=True
)
# Parse CRC values
series_crcs = re.findall(r'\[(\d+)\]', result.stdout)-s <y/n>Single file mode. Only convert the specified DICOM file, don't search for other files in the folder. Default: n.
Behavior:
y: Convert only the specified file (may be incomplete if part of series)n: Search folder for related files to build complete volumeUse Cases:
Warning: Output may be incomplete if the file is part of a multi-slice volume.
Examples:
# Convert single file
dcm2niix -s y /path/to/image.dcm
# Convert complete series (default)
dcm2niix -s n /path/to/folderPython Usage:
from dcm2niix import main
# Test single DICOM file
exit_code = main(["-s", "y", "/test/sample.dcm"])Filter which images are converted.
-n <CRC>Only convert series matching this CRC number. Can be specified up to 16 times to convert multiple specific series.
Workflow:
-q l to list series and their CRC values-n <CRC> to convert only those seriesExamples:
# Step 1: List series
dcm2niix -q l /dicom/folder
# Output shows: Series 001: T1_MPRAGE [52301]
# Step 2: Convert specific series
dcm2niix -n 52301 /dicom/folder
# Multiple series
dcm2niix -n 52301 -n 52305 -n 52310 /dicom/folderPython Usage:
from dcm2niix import main
# Convert multiple specific series
series_to_convert = ["52301", "52305", "52310"]
args = []
for crc in series_to_convert:
args.extend(["-n", crc])
args.append("/dicom/folder")
exit_code = main(args)-i <y/n>Ignore derived, localizer, and 2D images. When enabled, skips secondary captures, scout images, and 2D slices. Default: n (include all images).
Filtered Image Types:
Use Cases:
Examples:
# Include all images (default)
dcm2niix -i n /mixed/data
# Ignore derived and scouts
dcm2niix -i y /mixed/dataPython Usage:
from dcm2niix import main
# Clean conversion, primary sequences only
exit_code = main(["-i", "y", "/pacs/export"])-m <n/y/0/1/2>Merge 2D slices from the same series:
n or 0 = don't merge slices, create separate file for each slicey or 1 = merge all slices from series into volume2 = auto mode (default, smart merging)Default: 2 (auto).
Auto Mode Logic:
Use Cases:
n: Manual inspection, quality controly: Force merge despite parameter variations (use with caution)2: Recommended, intelligent mergingExamples:
# Don't merge, one file per slice
dcm2niix -m n /2d/slices
# Force merge all
dcm2niix -m y /2d/slices
# Auto mode (default)
dcm2niix -m 2 /2d/slicesPython Usage:
from dcm2niix import main
# Keep slices separate for QC
exit_code = main(["-m", "n", "/qc/slices"])Options affecting image data processing.
-l <y/n/o>16-bit integer range scaling:
y = losslessly scale to use full dynamic range (INT16: -32768 to 32767)n = no scaling, but convert UINT16 to INT16o = original, preserve exact values and data type (default)Default: o (original).
Mode Comparison:
| Mode | Scaling | Data Type | Use Case |
|---|---|---|---|
y | Full range | INT16 | Visualization, improved contrast |
n | None | INT16 | Type conversion only |
o | None | Original | Quantitative analysis |
Important: Mode y is lossless - original values can be recovered using stored scale factors in NIfTI header.
Examples:
# Preserve exact pixel values (default)
dcm2niix -l o /quant/analysis
# Maximize dynamic range
dcm2niix -l y /visualizationPython Usage:
from dcm2niix import main
# Quantitative analysis - preserve exact values
exit_code = main(["-l", "o", "/dwi/data"])-x <y/n/i>Crop 3D acquisitions:
y = crop excess slices from 3D volumesn = don't crop (default)i = ignore (neither crop nor rotate 3D acquisitions)Default: n.
What Cropping Does:
Mode Comparison:
| Mode | Crop | Rotate | Use Case |
|---|---|---|---|
y | ✓ | ✓ | Remove padding, standard orientation |
n | ✗ | ✓ | Keep all slices, standard orientation |
i | ✗ | ✗ | Preserve exactly as acquired |
Examples:
# Crop excess slices
dcm2niix -x y /3d/mprage
# Keep all slices (default)
dcm2niix -x n /3d/mprage
# No processing
dcm2niix -x i /3d/mpragePython Usage:
from dcm2niix import main
# Crop 3D structural scans
exit_code = main(["-x", "y", "/structural/t1"])-p <y/n>Philips precise float scaling. Use true floating-point values rather than display scaling. Default: y (use precise scaling).
Scaling Types:
| Mode | Values | Use Case |
|---|---|---|
y | Precise (RWV) | Quantitative analysis (required) |
n | Display | Visual inspection only |
Critical for:
Examples:
# Precise scaling (default, recommended)
dcm2niix -p y /philips/dwi
# Display scaling (not recommended)
dcm2niix -p n /philips/visualPython Usage:
from dcm2niix import main
# Quantitative Philips DWI - must use precise scaling
exit_code = main(["-p", "y", "-l", "o", "/philips/dwi"])Control metadata handling.
-c <text>Comment string stored in NIfTI aux_file field (maximum 24 characters). Use empty string "" to anonymize the comment field (0020,4000).
Storage:
Examples:
# Add study identifier
dcm2niix -c "VIP_Study" /input
# Anonymize comment field
dcm2niix -c "" /input
# Project and visit
dcm2niix -c "PRJ_001_V1" /inputPython Usage:
from dcm2niix import main
# Add study code
exit_code = main(["-c", "STUDY_XYZ", "-b", "y", "/input"])Special operational modes.
-r <y/n>Rename mode. Rename DICOM files using the naming pattern instead of converting them. Default: n (convert).
Behavior:
-f pattern for new namesExamples:
# Rename DICOMs without converting
dcm2niix -r y -f %p_%s /dicom/folderPython Usage:
from dcm2niix import main
# Organize DICOM archive
exit_code = main(["-r", "y", "-f", "%p_%s_%i", "/archive"])-g <y/n/o/i>Generate defaults file:
y = generate configuration filen = don't generate (default)o = only (reset and write defaults, don't convert)i = ignore (reset to defaults, then proceed with conversion)Default: n.
Configuration File Location:
~/.dcm2nii.ini or similarHKEY_CURRENT_USER\Software\dcm2niiExamples:
# Generate config file
dcm2niix -g y /input
# Reset to defaults and convert
dcm2niix -g i /inputControl console output verbosity.
-v <n/y/0/1/2>Verbose output level:
n or 0 = minimal output, errors only (default)y or 1 = standard output with warnings2 = logorrheic (verbose debugging information)Default: 0 (minimal).
Level Comparison:
| Level | Output | Use Case |
|---|---|---|
| 0 | Errors only | Production, scripts |
| 1 | Warnings + progress | Interactive use |
| 2 | Full debug info | Troubleshooting |
Examples:
# Minimal output (default)
dcm2niix -v 0 /input
# Standard verbosity
dcm2niix -v 1 /input
# Debug mode
dcm2niix -v 2 /inputPython Usage:
from dcm2niix import main
# Debug conversion issues
exit_code = main(["-v", "2", "/problem/folder"], capture_output=True, text=True)--progress <y/n>Report progress information in Slicer format. Default: n.
Output Format:
Example:
dcm2niix --progress y /inputControl output byte order.
--big-endian <y/n/o>Byte order for NIfTI output:
y = big-endian (byte-swapped on x86/x64)n = little-endiano = optimal/native (default, matches platform)Default: o (native).
Recommendation: Use default (o) unless specific compatibility required.
Example:
# Force big-endian
dcm2niix --big-endian y /inputControl image axis orientation.
-y <y/n>Flip Y-axis (rows):
y = flip rows (non-standard)n = don't flip (default, standard RAS+ orientation)Default: n (standard RAS+ orientation).
Note: Default behavior already applies proper DICOM LPS to NIfTI RAS+ conversion. This option provides additional control for edge cases only.
Example:
# Standard orientation (default)
dcm2niix -y n /inputSpecialized options for edge cases.
-j <y/n>Compare GE slice timing from DICOM tag (0021,105E). For debugging and validation of GE diffusion sequences. Default: n.
--ignore_trigger_timesDisregard DICOM trigger time tags (0018,1060 and 0020,9153). Useful when trigger timing is incorrect or unreliable.
--diffCyclingModeGE <0/1/2/3>GE diffusion gradient cycling mode override. Typically auto-detected. Values: 0-3 (undocumented, for advanced users).
Example:
dcm2niix --diffCyclingModeGE 0 /ge/dwi/folder--xmlEnable Slicer XML format features for integration with 3D Slicer.
Information commands.
-hShow help message with all options and exit.
Example:
dcm2niix -h--versionReport dcm2niix version information and exit.
Output Includes:
Example:
dcm2niix --versionPython Usage:
from dcm2niix import main
# Returns exit code 3 (version report)
exit_code = main(["--version"])-uUp-to-date version check (Unix/macOS only). Checks GitHub for the latest release and reports if update is available.
Example:
dcm2niix -uBIDS-Compliant Research Dataset:
dcm2niix -z y -b y -ba y -i y -f sub-%i_%p -o /bids/output /dicom/inputHigh-Quality Quantitative Analysis:
dcm2niix -l o -p y -x n -b y -o /analysis/output /philips/inputFast Batch Processing:
dcm2niix -z y -a y -d 1 -i y -w 0 -v 0 -o /output /organized/inputDebugging Conversion Issues:
dcm2niix -v 2 -q l -m 2 /problem/folderMinimal Output for Visualization:
dcm2niix -z y -l y -b n -i y -o /viz/output /inputOn Unix/macOS systems, default settings can be stored in a configuration file. Location varies by platform.
Generate Configuration:
dcm2niix -g oReset to Defaults:
dcm2niix -g i /inputWindows Configuration:
Stored in registry: HKEY_CURRENT_USER\Software\dcm2nii