Use this skill whenever the user wants to convert DICOM files or folders to NIfTI format (.nii or .nii.gz), extract neuroimaging volumes from clinical DICOM series (MRI, CT, PET, etc.), prepare raw DICOM data for research processing pipelines, anonymize while converting, or batch-convert multiple series/studies. Triggers include: 'DICOM to NIfTI', 'dcm to nii', 'convert dicom to nii.gz', 'dcm2niix', 'extract nii from dicom', 'batch dicom to nifti', 'prepare dicom for freesurfer/fsl/spm', 'anonymized nifti conversion', or any request to transform clinical DICOM data into analysis-ready NIfTI format while preserving orientation, voxel spacing, slice timing (when available), and important metadata in the JSON sidecar.
DICOM is the universal clinical imaging format containing rich metadata, patient information, acquisition parameters, and often multi-slice series.
NIfTI (.nii/.nii.gz) is the de-facto standard in neuroimaging research — compact, orientation-aware, and directly supported by FSL, FreeSurfer, SPM, AFNI, ANTs, etc.
This skill wraps dcm2niix (latest stable release as of 2026), the most widely used and actively maintained DICOM→NIfTI converter in neuroimaging.
It produces high-fidelity 3D/4D NIfTI volumes + comprehensive JSON sidecar files containing DICOM tags (BIDS-compatible when using -b y).
Research use only — not certified for clinical diagnostic workflows.
| Task | Recommended Flags / Approach |
|---|---|
| Basic single-series conversion | dcm2niix -z y -o output/ dicom_folder/ |
| 4D fMRI/DWI/perfusion | dcm2niix -z y -f "%s_%t" -b y dicom_folder/ |
| BIDS-like naming + JSON sidecar |
-o out/ -f sub-%s_ses-%t -z y -b y |
| Lossless compression | -z y (pigz) or -z i (internal) |
| Anonymize (remove most PHI) | -x y (cautious) or -x n (aggressive) |
| Merge 2D slices into 3D volume | default behavior (auto-detected) |
| Keep slice timing / Philips diff | -t y (important for fMRI) |
| Custom output filename | -f "%p_%s_%t_%d" (patient_study_time_desc) |
| Only convert specific series | Use -m y + manual selection or post-filter |
Most reliable and fastest:
# Linux / macOS (use latest release)
wget https://github.com/rordenlab/dcm2niix/releases/latest/download/dcm2niix_lnx.zip
unzip dcm2niix_lnx.zip
chmod +x dcm2niix
mv dcm2niix /usr/local/bin/ # or add to PATH
dcm2niix --version
Windows / macOS: download from release page → https://github.com/rordenlab/dcm2niix/releases
conda install -c conda-forge dcm2niix
pip install pydicom # optional helper
# then call subprocess.run(["dcm2niix", ...])
docker pull rordenlab/dcm2niix:latest
docker run --rm -v $(pwd)/dicom:/data rordenlab/dcm2niix -z y /data
dcm2niix -z y -o ./nifti/ ./dicom/T1_MPRAGE/
# → produces T1_MPRAGE.nii.gz + T1_MPRAGE.json
dcm2niix \
-o ./nifti/ \
-f "sub-001_ses-01_task-rest_bold" \
-z y -b y -t y \
./dicom/func_rest/
dcm2niix -z y -x n -o anonymized/ dicom_study/
dcm2niix -z y -o nifti_all/ -b y ./patient_20250318/
A thin python wrapper can be placed in the skill directory:
# dcm2nii_wrapper.py
import subprocess
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--input-dir", required=True)
parser.add_argument("--output-dir", required=True)
parser.add_argument("--bids-prefix", default="sub-%p_ses-%t")
parser.add_argument("--compress", action="store_true")
parser.add_argument("--json-sidecar", action="store_true")
parser.add_argument("--anonymize", action="store_true")
args = parser.parse_args()
cmd = ["dcm2niix"]
if args.compress:
cmd += ["-z", "y"]
if args.json_sidecar:
cmd += ["-b", "y"]
if args.anonymize:
cmd += ["-x", "n"]
cmd += ["-o", args.output_dir]
cmd += ["-f", args.bids_prefix]
cmd += [args.input_dir]
subprocess.run(cmd, check=True)
python dcm2nii_wrapper.py \
--input-dir ./dicom/T1/ \
--output-dir ./nifti/ \
--bids-prefix "sub-001_ses-01_T1w" \
--compress --json-sidecar
-m y + parallel runsdependency-planner → install dependenciesOriginal & latest: https://github.com/rordenlab/dcm2niix
Documentation: https://www.nitrc.org/plugins/mwiki/index.php/dcm2nii:MainPage
Maintainer: Chris Rorden
Core algorithm: dicom → NIfTI reorientation + private tag parsing
Created At: 2026-03-18 20:55 HKT
Last Updated At: 2026-03-25 20:53 HKT
Author: chengwang9637:["$","$L3c",null,{"content":"$3d","frontMatter":{"name":"dcm2nii","description":"Use this skill whenever the user wants to convert DICOM files or folders to NIfTI format (.nii or .nii.gz), extract neuroimaging volumes from clinical DICOM series (MRI, CT, PET, etc.), prepare raw DICOM data for research processing pipelines, anonymize while converting, or batch-convert multiple series/studies. Triggers include: 'DICOM to NIfTI', 'dcm to nii', 'convert dicom to nii.gz', 'dcm2niix', 'extract nii from dicom', 'batch dicom to nifti', 'prepare dicom for freesurfer/fsl/spm', 'anonymized nifti conversion', or any request to transform clinical DICOM data into analysis-ready NIfTI format while preserving orientation, voxel spacing, slice timing (when available), and important metadata in the JSON sidecar.","license":"BSD 3-Clause (original dcm2niix license). See https://github.com/rordenlab/dcm2niix/blob/master/LICENSE for complete terms."}}]