I have nifti (.nii.gz) scalar volumes and I wanted to convert them into DICOM format and extract information from the metadata (IOP and IPP). I had done this manually using the 3D Slicer GUI. As there are multiple nifti files that need to be converted, I wanted to automate the process using the Slicer Python interface. Please see the code below.
volume = slicer.util.loadVolume('C:/Users/shamb/Downloads/110122_CE_2ch.nii.gz')
dicomWrite = slicer.modules.createdicomseries
I am stuck after this step. Manually, I would go to the CreateDICOMSeries module, choose the input volume and select apply. Is there a way to implement these steps in the python interface?
I have also come across the DICOMExportScalarVolume from DICOMLib and tried nifti to DICOM conversion. Please see the code below:
from DICOMLib import DICOMExportScalarVolume
volume = slicer.util.loadVolume('C:/Users/shamb/OneDrive/Desktop/test/110122_CE_2ch.nii.gz')
DICOMExportScalarVolume(volumeNode = volume, studyUID = None, tags = None, directory = 'C:/Users/shamb/Downloads/')
This code snippet runs successfully and generates a DICOMExportScalarVolume object. But upon examining the DICOM metadata no information is visible. Please see the image attached.
I did not face this issue while using the CreateDICOMSeries module GUI.
I can’t figure out where I’m going wrong and would greatly appreciate some help.
Thanks in advance!
If you just need to export images then you can use the CreateDICOMSeries module. It is a CLI module that you can run from Python.
If you want to be able to export other DICOM data objects (e.g., segmentation, RT structure set, …) then you can use export plugins of the DICOM module as shown in the script repository.
Thanks a lot @lassoan this works!