I used these scripts to convert the PROSTATEx-Seg-HiRes DICOM dataset to a more friendly nii format. This dataset is not straightforward to convert for various reasons, for example, you can use dcm2niix to convert the mri images but not the segmentations, there isn't a one-to-one relation between segmentation slices and mri slices and so on. Remember: this code is far from perfect, it's not well engineered, and it was written for personal necessity. For a much cleaner code with automated downloads of data and tools see this gist.
-
Download the dataset with classic directory names option (both mri and segmentations).
-
Create a new folder (for example named ProstateX) with two sub-folders in it, one for the mri images and one for the segmentations.
-
Place all the folders (ProstateX-0004, ecc...) in the respective sub-folder. Do this for both the mri images and the segmentations. Your folder structure should look like this (truncated for clarity):
ProstateX ├───mri │ ├───ProstateX-0004 │ ├───ProstateX-0007 │ ├───ProstateX-0009 │ └───ProstateX-... └───seg ├───ProstateX-0004 ├───ProstateX-0007 ├───ProstateX-0009 └───ProstateX-...
-
Run rename_all_folders.py two times: the first time the dcm_path variable should point to the mri sub-folder, the second time it should point to the segmentations sub-folder.
-
Download the dcm2niix executable (dcm2niix.exe) and store it where you can use it.
-
Run mri2nii.py adjusting the various paths in it. dcm_dataset_path should point to the mri sub-folder, nii_dataset_path to your preferred output folder and converter to dcm2niix.exe.
-
Run seg2nii.py adjusting the various paths in it. dcm_dataset_path should point to the segmentations sub-folder, and nii_dataset_path should point to the same location as before.
-
Enjoy the converted dataset!