This repository provides a Python function that converts 3D NIfTI medical images into a series of DICOM slices. The code is intentionally kept straightforward and minimal so you can easily adapt it to your own needs and pipelines.
- NIfTI to DICOM Conversion: Converts 3D volume data from NIfTI (
.nii
,.nii.gz
) format to standard DICOM files. - Lightweight and Adaptable: The code is kept simple for easy customization—perfect for research or clinical prototyping.
- GPL License: Distributed under the GNU General Public License (GPL), ensuring the freedom to modify and redistribute.
- Python 3.7+
- nibabel (for loading NIfTI images)
- pydicom 3.0+ (for creating and saving DICOM files)
- numpy (for numerical operations)
Below is a minimal example demonstrating how to convert a NIfTI file named input_image.nii.gz
into multiple DICOM slices in a folder called dicom_output
:
import nibabel as nib
from nifti_to_dicom import nifti_3d_to_dicom
# Load NIfTI
nifti_img = nib.load("input_image.nii.gz")
# Convert and save to DICOM
nifti_3d_to_dicom(
nifti_img=nifti_img,
output_folder="dicom_output",
PatientName="JohnDoe",
PatientID="12345678",
Modality="CT",
SeriesDescription="Simple CT Example",
StudyDescription="Demo Study",
SeriesNumber=1
)
This project is licensed under the GNU General Public License 3.0 (GPL) by
Dr. med. Hinrich Winther, Machine Learning Work Group, Institute of Diagnostic and Interventional Radiology, Hannover Medical School.
You are free to copy, modify, and distribute this software with the same license.