# SimpleITK ScaleTransform understanding

**URL:** <https://discourse.itk.org/t/simpleitk-scaletransform-understanding/4313>\
**Category:** Beginner Questions\
**Tags:** interpolator, image, simpleitk, python\
**Created:** [August 5, 2021, 11:07am UTC](https://discourse.itk.org/t/simpleitk-scaletransform-understanding/4313 "2021-08-05T11:07:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theoretialperson](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@Theoretialperson](https://discourse.itk.org/u/Theoretialperson)\
**Post date:** [August 5, 2021, 11:07am UTC](https://discourse.itk.org/t/simpleitk-scaletransform-understanding/4313/1 "2021-08-05T11:07:48Z")

</div>

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,

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

```

 ![image](https://discourse.itk.org/uploads/default/original/2X/3/30db230cb6fb6cab6958c6afeb01b085f99448b6.png)

Is my understanding of how `ScaleTransform` works wrong? If e.g. you look [here](https://itk.org/ITKExamples/src/Filtering/ImageGrid/ResampleAnImage/Documentation.html), it says that ITK’s `ScaleTransform` should result in an enlarged image when the scale is larger than 1.0.

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [August 5, 2021, 1:31pm UTC](https://discourse.itk.org/t/simpleitk-scaletransform-understanding/4313/2 "2021-08-05T13:31:40Z")

</div>

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](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/21_Transforms_and_Resampling.ipynb).

---

<div class="post-metadata">

**Author:** ![Theoretialperson](https://discourse.itk.org/letter_avatar_proxy/v4/letter/t/c5a1d2/32.png) [@Theoretialperson](https://discourse.itk.org/u/Theoretialperson)\
**Post date:** [August 5, 2021, 7:37pm UTC](https://discourse.itk.org/t/simpleitk-scaletransform-understanding/4313/3 "2021-08-05T19:37:20Z")

</div>

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.
