SimpleITK ScaleTransform understanding

I want to scale a 3D image by some factor, and I was expecting that the scale factor in ScaleTransform would give me a zoomed-out image when the scale factor is smaller than 1.0. Unfortunately this is not the case. I get the inverse behavior. See example code below, and resulting image slice,

image_center = 0.5 * np.array(image.shape)[::-1]                                                                                                                                                                                                                                    
scale = sitk.ScaleTransform(3, 1.8 * np.ones(3))                                                                                 
sitk_image = sitk.GetImageFromArray(patch)                                                                                      
sitk_image_scaled = sitk.Resample(sitk_image, scale, sitk.sitkBSpline, 0.0, useNearestNeighborExtrapolator=True)

Is my understanding of how ScaleTransform works wrong? If e.g. you look here, it says that ITK’s ScaleTransform should result in an enlarged image when the scale is larger than 1.0.

Hello @Theoretialperson,

Welcome to SimpleITK!

Your understanding of the ScaleTransform is correct, the misunderstanding is with how resampling works.

Given a point \mathbf{p}=[x,y,z] and the scaling of 1.8, it will be mapped to \mathbf{p'}=[1.8x,1.8y,1.8z]. When you are doing the resampling the new image is created as intensity(p) = intensity(p'), thus for a scale factor >1 it is a zoomed out version and for scale factors 0<s<1 it is zoomed in.

For detailed examples of resampling take a look at this Jupyter notebook.

1 Like

Thanks @zivy ,

Indeed I was suspicious that the problem lied in my understanding of the interpolation. When I more carefully visualise sampling the image using the scaled points, I see that when the points are scaled down (scale < 1.0) it will sample from a small area in the center of the image. While when the inverse is true, many of the points will end-up outside the image and the rest will sample a low resolution version of the original image, giving the result above.