I’m fairly new to the SimpleITK API and I’m using it right now to load a CT and PET image, and resample the PET to the same coordinate system and size as the CT (for a deep learning algorithm).
Right now my code is:
reader = sitk.ImageSeriesReader() # loading CT dicom_names = reader.GetGDCMSeriesFileNames(pathToCTDicomFiles) reader.SetFileNames(dicom_names) imageCT = reader.Execute() # Loading PET dicom_names = reader.GetGDCMSeriesFileNames(pathToPETDicomFiles) reader.SetFileNames(dicom_names) imagePET = reader.Execute() # Resampling the PET image pet_resampled = sitk.GetArrayFromImage(sitk.Resample(imagePET, imageCT))
The problem is that each time I loop over this part for a new image, the memory usage increases until the program crashes after 2 or 3 iterations. I run the code in Spyder 4.1 with python 3.7 on Ubuntu 18.04 with 32 GB of ram.
I have tried using del and gc.collect(), but it does nothing in this case.
Any suggestions for better use of the API are also very welcome, e.g. only load the the metadata for the CT or something like this.