Conversion script for conversion of TCIA DICOM data to NIfTI format (dataset: FDG-PET-CT-Lesion, doi: ).
To run the script you will need a number of python packages. Use the terminal and run sequentially:
pip3 install numpy
pip3 install dicom2nifti
pip3 install nibabel
pip3 install pydicom
pip3 install tqdm
pip3 install nilearn
in case you use a Colab or Jupyter notebook and cannot use the terminal you can perform these installations by adding a "!" in front of the commands, e.g.
!pip3 install numpy
...
DICOM data downloaded from TCIA will have the following format:
Directory structure of the original DICOM data within the folder /PATH/TO/DICOM/FDG-PET-CT-Lesions/ :
In order to run this script use the terminal and navigate to the path where the script is stored, then run:
python3 tcia_dicom_to_nifti.py /PATH/TO/DICOM/FDG-PET-CT-Lesions/ /PATH/TO/NIFTI/FDG-PET-CT-Lesions/
where
/PATH/TO/DICOM/FDG-PET-CT-Lesions/
is the directory of the DICOM data downloaded from TCIA (see above: data structure) and
/PATH/TO/NIFTI/FDG-PET-CT-Lesions/
is the path you want to store the NIfTI files in.
You can ignore the nilearn warning:
.../nilearn/image/resampling.py:527: UserWarning: Casting data from int16 to float32 warnings.warn("Casting data from %s to %s" % (data.dtype.name, aux))
or suppress warnings by running the script as (after making sure everything works):
python3 -W ignore tcia_dicom_to_nifti.py /PATH/TO/DICOM/FDG-PET-CT-Lesions/ /PATH/TO/NIFTI/FDG-PET-CT-Lesions/
The resulting NIfTI directory will have the following structure:
Running the script can take multiple hours.
Conversion script for conversion of TCIA NIfTI data (created using tcia_dicom_to_nifti.py - see above) to mha files.
To run the script you will need a number of python packages. Use the terminal and run sequentially:
pip3 install SimpleITK
pip3 install tqdm
in case you use a Colab or Jupyter notebook and cannot use the terminal you can perform these installations by adding a "!" in front of the commands, e.g.
!pip3 install SimpleITK
...
In order to run this script use the terminal and navigate to the path where the script is stored, then run:
python3 tcia_nifti_to_mha.py /PATH/TO/NIFTI/FDG-PET-CT-Lesions/ /PATH/TO/MHA/FDG-PET-CT-Lesions/
where
/PATH/TO/NIFTI/FDG-PET-CT-Lesions/
is the directory of the NIfTI data generated using tcia_dicom_to_nifti.py (see above) and
/PATH/TO/NIFTI/FDG-PET-CT-Lesions/
is the path you want to store the MHA files in.
You can ignore the nilearn warning:
.WARNING: In /tmp/SimpleITK-build/ITK/Modules/IO/Meta/src/itkMetaImageIO.cxx, line 669 MetaImageIO (0x2d9b300): Unsupported or empty metaData item intent_name of type Ssfound, won't be written to image file
or suppress warnings by running the script as (after making sure everything works):
python3 -W ignore tcia_nifti_to_mha.py /PATH/TO/NIFTI/FDG-PET-CT-Lesions/ /PATH/TO/MHA/FDG-PET-CT-Lesions/
Conversion script for conversion of TCIA NIfTI data (created using tcia_dicom_to_nifti.py - see above) to a single hdf5 file
To run the script you will need a number of python packages. Use the terminal and run sequentially:
pip3 install numpy
pip3 install h5py
pip3 install tqdm
pip3 install nibabel
in case you use a Colab or Jupyter notebook and cannot use the terminal you can perform these installations by adding a "!" in front of the commands, e.g.
!pip3 install numpy
...
In order to run this script use the terminal and navigate to the path where the script is stored, then run:
python3 tcia_nifti_to_hdf5.py /PATH/TO/NIFTI/FDG-PET-CT-Lesions/ /PATH/TO/HDF5/FDG-PET-CT-Lesions.hdf5
where
/PATH/TO/NIFTI/FDG-PET-CT-Lesions/
is the directory of the NIfTI data generated using tcia_dicom_to_nifti.py (see above) and
/PATH/TO/HDF5/FDG-PET-CT-Lesions.hdf5
is the path and filename of the hdf5 file to be created.
All scripts were tested under python 3.9 with the following package versions:
dicom2nifti==2.3.3
nibabel==3.2.2
pydicom==2.3.0
h5py==3.6.0
tqdm==4.64.0
SimpleITK==2.1.1.2
nilearn==0.9.1
numpy==1.22.3