resampling with simpleitk

Hi iTK!

I am new to SimpleITK and I am working in Python. I have a NRRD volume that I want to reslice according to the origin,spacing and dimensions of a second NRRD volume. I am trying to figure this out. Is there a way to do this with SimpleITK alone or do I really need to go back and forth between SimpleITK and VTK (looking at you vtkImageReslice, and you too sitk.ResampleImageFilter…).

Or is it resampling what I need to do?

Any help would be greatly appreciated! :pray:


I believe you are looking for the ResampleImageFilter.
Any reason you think this is not the filter you are looking for?

I think you are right. A bit confused between reslicing and resampling but since what I am doing involves interpolation and just a change of coordinates I think what I meant is resampling (??)

Is there anywhere where I can see an example? I am new to SimpleITK, this is what I got so far:

    t2w = self.image_a  #T2 weighted image
    adc = self.image_b  #ADC image

    resampler = sitk.ResampleImageFilter()
    resampled = resampler.Execute(adc)

    data = sitk.GetArrayFromImage(resampled) ...

I think I got it:

OK, I am officially :heart:ing SimpleITK!


Your code resamples the image adc on to the grid defined by the t2w image, preserving the physical location of the input image because the default transform is the identity.

Are you trying to resample the image preserving it’s physical location? or are you trying to transform the physical image and then resample?

Many of the registration examples use the resample filter to apply the resulting transform:

Also in the SimpleITK Notebooks there is an example with for Transforms and Resampling.

Hi Bradley,

To answer your question: Yes. I am assuming these images are already registered. So I want to preserve their individual locations as each will have a different origin, spacing and orientation in the same space.

I do the resampling on ADC so I can obtain a view for every corresponding slice of T2W, because ADC has a much coarser spacing and also a different orientation and origin.

If that were not the case I would do registration first and then apply the resampling (right?)

Thanks for the links!


1 Like