This tool converts DICOM files to NIfTI format and programmatically harmonizes the resulting JSON sidecar to ensure compliance with BIDS (Brain Imaging Data Structure) metadata standards.
Version v0.7.0 introduces a generalized and extensible slice-order framework, legacy acquisition preservation, metadata provenance tracking, and improved CLI consistency.
Gabriele Amorosino (gabriele.amorosino@utexas.edu)
If you use this software in your research or pipeline, please include the following in your papers' acknowledgments:
This work was developed by Gabriele Amorosino in the Laboratory of Franco Pestilli at the University of Texas at Austin. This work was supported by the following grant: NIH R01HD114489, CRCNS: Dense longitudinal neuroimaging to evaluate learning in childhood (Principal Investigator S. Vinci Booher) Awards Wellcome 226486/Z/22/Z and NIH NINDS U24-NS140384 to F. Pestilli and NIH NINDS UM1-NS132207 to K. Ugurbil.
If this tool contributes to your research, please cite:
Amorosino, G., Vinci-Booher, S., & Pestilli, F.
Advancing FAIR data by facilitating the conversion of DICOM to NIfTI.
In preparation.
- Uses
dcm2niixfor robust DICOM → NIfTI conversion. - Produces
.niiimages with accompanying.jsonmetadata sidecars. - Supports both single DICOM files and directory-based acquisitions.
-
Automatically updates and validates required BIDS fields.
-
Integrates metadata from:
- JSON sidecar (primary source)
- DICOM headers (fallback)
- Optional Philips Exam Card files
-
Ensures consistent unit handling and structured metadata output.
-
update_json_sidecar.pyallows post-hoc correction of an existing JSON file. -
Useful when:
- Metadata is incomplete
- Conversion occurred externally
- Additional compliance steps are required
The tool can compute and/or harmonize:
SliceTimingTotalReadoutTimeEffectiveEchoSpacingPhaseEncodingDirectionPhaseEncodingDirectionSource(provenance annotation)
Metadata is resolved in the following order:
- JSON sidecar (primary)
- DICOM header (fallback)
- Exam Card (Philips-specific fallback)
This structured hierarchy increases robustness when working with partially exported datasets.
v0.7.0 introduces a flexible acquisition modeling system.
-
legacyPreserves original lab-specific acquisition logic (MB=3 protocol). -
ascendingStandard multi-band grouping in ascending shot order. -
interleavedEven–odd shot ordering. -
steppedGeneralized cyclic stepping with configurable step size.
-
--slice-order-stepallows explicit control of stepping behavior. -
Default behavior:
legacy→ step = 4 (backward compatible)- all other modes → step = 1
-
--slice-orderallows direct specification of acquisition groups. -
Validation ensures:
- full slice coverage
- no duplicates
- correct MB grouping
If --compute-slice-timing is enabled:
-
Slice timing is reconstructed using:
- TR
- Number of slices
- Multi-band factor
- Derived slice-order
Supports:
- Automatic modes
- Stepped acquisitions
- Manual slice order definitions
Determined via:
- Manual override (
--phase-encoding-direction) - Exam Card logic (Philips)
- DICOM InPlanePhaseEncodingDirection
New in v0.7.0:
- Adds metadata field:
"PhaseEncodingDirectionSource": "manual" | "computed"This provides explicit provenance of the value.
Computed using:
- JSON
PhaseEncodingSteps+EffectiveEchoSpacing - Philips formula (Chris Rorden approach)
- Exam Card bandwidth + EPI factor
- Fallback to existing
EstimatedTotalReadoutTime
Automatic ms → seconds normalization is applied when necessary.
git clone <repository-url>
cd <repository-folder>python3 -m venv env
source env/bin/activate
pip install -r requirements.txtconda env create -f res/config/fixSidecar.yml
conda activate fixSidecarRun the script to convert DICOM files and update their metadata:
python dcm_convert.py <dicom_file> <output_dir> [options]Or use the standalone script to update an existing NIfTI JSON sidecar:
python update_json_sidecar.py <dicom_file> <json_file> <output_file> [options]-
<dicom_file>Path to a DICOM file or a directory containing DICOM files. -
<output_dir>Directory where the converted NIfTI file and updated JSON sidecar will be saved.
-
--no-fmriSkip JSON-sidecar update (useful for structural or non-fMRI data). -
--exam-card <path>Path to a Philips Exam Card file for additional metadata extraction. -
--compute-slice-timingEnable calculation ofSliceTiming. -
--compute-total-readoutEnable calculation ofTotalReadoutTime. -
--slice-order "<json_string>"Provide a custom slice acquisition order as a JSON-formatted string. Example:--slice-order "[[0,12,24],[1,13,25],[2,14,26]]" -
--slice-order-mode legacy|ascending|interleaved|steppedAutomatic slice-order strategy (used only if--slice-orderis not provided).legacy– preserves original lab-specific MB=3 behaviorascending– sequential MB groupinginterleaved– even–odd shot orderingstepped– generalized cyclic stepping
-
--slice-order-step <int>Step size for slice-order calculation. Used for:slice-order-mode=steppedslice-order-mode=legacy(defaults to 4 if not specified)
-
--tmp-dir <path>Specify a temporary directory for intermediate processing. -
--scanner-type <type>Define scanner type (default:"Philips"). -
--flip-phase-encoding-directionToggle the sign of the inferred phase encoding direction. -
--phase-encoding-direction <dir>Manually provide the BIDSPhaseEncodingDirection. Examples:j,j-,i,i-If provided, automatic inference is skipped and provenance is recorded. -
--versionDisplay tool version, Python version, and platform information.
-
<dicom_file>Path to the DICOM file. -
<json_file>Path to the existing JSON sidecar file. -
<output_file>Path where the updated JSON file will be written.
-
--exam-card <path>Path to a Philips Exam Card file. -
--compute-slice-timingEnable calculation ofSliceTiming. -
--slice-order "<json_string>"Provide a custom slice acquisition order (overrides automatic modes). -
--slice-order-mode legacy|ascending|interleaved|steppedAutomatic slice-order strategy if--slice-orderis not provided. -
--slice-order-step <int>Step size used for:steppedmodelegacymode (defaults to 4)
-
--phase-encoding-direction <dir>Manually specifyPhaseEncodingDirection. -
--flip-phaseToggle the sign of the inferred phase encoding direction. -
--versionDisplay script version and system information.
python dcm_convert.py example_dicom_folder output_directorypython dcm_convert.py example_dicom_folder output_directory \
--compute-slice-timing \
--slice-order-mode stepped \
--slice-order-step 3python dcm_convert.py example_dicom_folder output_directory \
--phase-encoding-direction "-j"python update_json_sidecar.py example.dcm existing.json updated.json \
--compute-slice-timing \
--slice-order-mode interleavedBoth scripts support:
--versionWhich reports:
- Tool version
- Python version
- Platform information
- Requires
dcm2niixavailable in system PATH. - Designed and validated primarily on Philips 3T Ingenia CX systems.
- Cross-scanner use should be validated carefully.
This software was developed and tested using data from the Philips 3T Ingenia CX MRI Scanner at the Vanderbilt University Institute of Imaging Sciences (VUIIS). Application to other scanners may require verification of acquisition assumptions and output correctness.
We thank Eric Wilkey and Elton (Ellie) Cross for testing and helpful feedback that improved this tool.