This repository provides a Python script to convert medical imaging data in Siemens .IMA format (DICOM) into NIfTI format. The script handles both PET and CT modalities, ensures proper resampling to isotropic PET spacing, and converts associated segmentation masks into aligned binary masks.
A key feature is automatic de-duplication of CT slices to address issues such as non-uniform sampling or duplicate z-locations in Siemens DICOM series.
- Convert PET
.IMAseries into SUV-scaled, isotropic NIfTI volumes (*_PT.nii.gz). - Convert CT
.IMAseries into resampled NIfTI volumes aligned with PET grid (*_CT.nii.gz). - Convert segmentation files (
.seg.nrrd) into binary masks (*_MASK.nii.gz), resampled to the PET grid. - De-duplicates CT slices based on
ImagePositionPatientto avoid redundant or inconsistent slices. - Gaussian blur (σ ≈ 2 mm) is applied before resampling to reduce aliasing (according to this link and this link).
- Out-of-FOV voxels are set to –1000 HU (air).
- Logs all conversions (patient, modality, image geometry, spacing, origin, etc.) in CSV files.
- ROOT_DIR=/path/to/dataset/root
- OUTPUT_DIR=/path/to/save/nifti
- MASK_DIR=/path/to/original/masks
- MASK_SAVING_DIR=/path/to/save/converted/masks
Run:
python dicom2nift.py
To get the desired spacing, simply change line 12 of the code.