Could Someone Give me Advice on Optimizing Image Resampling in ITK for Large Datasets?

Hello there,

I am currently working on a project involving the processing of high resolution medical images; and I have run into some performance concerns when resampling large datasets using ITK. Specifically; I am using ResampleImageFilter to transform and interpolate volumetric data. While the filter works well on smaller images; I have noticed a significant slowdown as the image dimensions increase.

Are there any best practices to improve the performance of ResampleImageFilter for large 3D images? I am already using a linear interpolator to reduce computation but am open to other suggestions. Would multi threading settings or ITK pipeline options improve execution time? If so; what configurations should I explore? :thinking:

Is there an alternative resampling method in ITK or another library that might be faster for large datasets? :thinking:

Also, I have gone through this post; https://discourse.itk.org/t/resample-to-same-spacing-and-size-and-align-to-same-origin-cybersecurity which definitely helped me out a lot.

I am particularly interested in strategies others have used when working with volumetric images that are gigabytes in size.

Thanks in advance for your help and assistance. :innocent:

Couple you please provide a sample of the code you are using to resample? Also what are the sizes of images you are happy with the performance and what are the sizes and pixel type of images that are under performing.

Also please provide examples of the performance that you are getting, so that we can determine if we can reproduce your performance issue.

Also, what is your computer memory size? If the operation is forcing use of swap memory, that could explain the slowdown. The computation time is expected to increase linearly with number of voxels.

1 Like

Hello @roberrttt,

Here’s some SimpleITK Python code that will facilitate a more quantitative discussion:

import SimpleITK as sitk
import timeit

image_size = [512, 512, 50]
sigma = [20, 40, 80]
image = sitk.GaussianSource(outputPixelType = sitk.sitkFloat32,
                            size = image_size,
                            sigma = sigma,
                            mean = [sz/2 for sz in image_size])

new_size = [2*sz for sz in image_size]
new_spacing = [((osz - 1) * ospc) / (nsz - 1) for ospc, osz, nsz in zip(image.GetSpacing(), image.GetSize(), new_size)]

resample_filter = sitk.ResampleImageFilter()
resample_filter.SetNumberOfThreads(2)
print(resample_filter.GetNumberOfThreads())
resample_filter.SetInterpolator(sitk.sitkLinear)
resample_filter.SetOutputOrigin(image.GetOrigin())
resample_filter.SetSize(new_size)
resample_filter.SetOutputSpacing(new_spacing)

time_results = timeit.repeat(lambda: resample_filter.Execute(image), number = 1, repeat=10)

print(time_results)
1 Like