How to convert dicom files to nrrd

You can load DICOM from python like this

from DICOMLib import DICOMUtils
DICOMUtils.openDatabase('path/to/tempDatabase') # For batch processing it's better to use a  temporary database
DICOMUtils.loadPatientByUID(patientUID)

You can load patients by name, UID, and patient ID (an incremental integer Slicer assigns to imported patients), see https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMLib/DICOMUtils.py#L105-L110

Then you can save NRRD like this

slicer.util.saveNode(node, 'fileName.nrrd')

For this you’ll need the MRML node which you can get in several ways, depending how you want your batch script to operate (for example dynamically with onNodeAdded, by getting the last volume node from the scene, or simply by closing scene after each save and get the only volume node)

2 Likes