4DCT dicom import and save

I found many helpful topics on the discourse, but still have yet to find a full soluiton:

I have 100+ 4dct scans in dicom format, I’d like to import them and save as .nrrd or .seq.nrrd

When loaded using the import dicom from folder in the module, the volume loads as a sequence, and can be saved which generates a .nrrd and .seq.nrrd

Attempting to batch process this, I used similar functions written fro 3dct, but I’m running into unwanted functionality:

def importDICOM(dicomDataDir) -> list:
 
  loadedNodeIDs = []
  from DICOMLib import DICOMUtils

  with DICOMUtils.TemporaryDICOMDatabase() as db:
    DICOMUtils.importDicom(dicomDataDir, db)
    patientUIDs = db.patients()
    for patientUID in patientUIDs:
      loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUID))
    
    loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUIDs[0]))

  return loadedNodeIDs

The DICOMUtils loadPatienBytUID seems to generate a duplicate node.. which makes parsing and saving the appropriate volumes tricky

I can add some more screenshots later today - but any suggestions are welcome!

It looks like you are on the right track. Different CTs might or might not be detected as sequences depending on the header tags. You can interate through and see which ones are not and check them interactively. You might need to go a level lower and use the sequence plugin directly.

Thanks @pieper

I dug deeper using the DICOM module , based on the recommendation on another topic to view

slicer.util.selectModule("DICOM")
browserWidget = slicer.modules.DICOMWidget.browserWidget
browserWidget.importDirectory(vol_pth)
#loadables, loadablesByPlugin = selectLoadables(browserWidget)

patient = slicer.dicomDatabase.patients()[0]
studies = slicer.dicomDatabase.studiesForPatient(patient)
series = [slicer.dicomDatabase.seriesForStudy(study) for study in studies]
seriesUIDs = [uid for uidList in series for uid in uidList]
browserWidget.onSeriesSelected(seriesUIDs)
browserWidget.examineForLoading()

loadables = browserWidget.loadableTable.loadables

loadablesByPlugin = browserWidget.loadablesByPlugin
for plugin in loadablesByPlugin:
  print(plugin.loadType)

For my 4DCT, is it sufficient to only use the Volume Sequnce import plugin lodable?

Yes, if you want to load everything as a sequence then yes only use the sequence plugin. By default the high level code picks the loadables that have the highest confidence (i.e. the plugin’s heuristics indicate that the data in question matches the intent of the plugin. You can look at the examine portion of the plugins to see what they are looking for in the data. Sequences in particular can be encoded many ways so the heuristics are not always right. But if you know your data is 4dct, then you should ensure that the sequence plugin is used.

consider using dcm2niix