From pydicom data format to simpleITK

Is there a way for me to load a list of pydicom images straight into simpleITK in python without having to save them locally first?
I’m working on a auto-segmentation project where I receive two pydicom lists ( one PET and one CT), they are in the format list<pydicom.dataset.FileDataset>. The script that runs the auto-segmentation usually takes a PET path and a CT path, but as they aren’t actually saved locally, that’s not a possibility. Is there a way for me to modify the code below, such that it takes the two lists and not two file paths?
Thank you very much

    print('Reading PET..')
    reader = sitk.ImageSeriesReader()
    dicom_names = reader.GetGDCMSeriesFileNames(PET_path)
    reader.SetFileNames(dicom_names)
    
    reader.MetaDataDictionaryArrayUpdateOn()
    reader.SetOutputPixelType(sitk.sitkFloat32)
    imagePET = reader.Execute()
    
    print('Reading CT..')
    reader = sitk.ImageSeriesReader()
    dicom_names = reader.GetGDCMSeriesFileNames(CT_path)
    reader.SetFileNames(dicom_names)
    
    reader.MetaDataDictionaryArrayUpdateOn()
    reader.LoadPrivateTagsOn()
    imageCT = reader.Execute()

Looking at the pydicom docs, it looks like you can convert the pixel data into a numpy array. Then you can use SimpleITK’s GetImageFromArray function to convert the numpy array into a SimpleITK Image. You’d lose any meta-data information though. You’d have to transfer that over yourself.

2 Likes