# What is the code for sitk.Tramsform()?

**URL:** https://discourse.itk.org/t/what-is-the-code-for-sitk-tramsform/5495
**Category:** Uncategorized
**Created:** [November 16, 2022, 12:45pm UTC](https://discourse.itk.org/t/what-is-the-code-for-sitk-tramsform/5495 "2022-11-16T12:45:36Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![pranoy-ray](https://discourse.itk.org/user_avatar/discourse.itk.org/pranoy-ray/32/2883_2.png) [@pranoy-ray](https://discourse.itk.org/u/pranoy-ray)
#### Post date: [November 16, 2022, 12:45pm UTC](https://discourse.itk.org/t/what-is-the-code-for-sitk-tramsform/5495/1 "2022-11-16T12:45:36Z")

</div>

```auto
def make_isotropicBCC(
    image,
    interpolator=sitk.sitkLinear,
    spacing=None,
    default_value=0,
    standardize_axes=False,):
   
    original_spacing = image.GetSpacing()
    
    # Make image isotropic via resampling.
    original_size = image.GetSize()
    
    if spacing is None:
        spacing = min(original_spacing)
    
    new_spacing = [spacing] * image.GetDimension()
   
    new_size = [
        int(round(osz * ospc / spacing))
        for osz, ospc in zip(original_size, original_spacing)
    ]
    
    new_direction = tuple((0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0))#image.GetDirection()
    
    new_origin = image.GetOrigin()
    
    # Only need to standardize axes if user requested and the original
    # axes were not standard.
    if standardize_axes and not np.array_equal(np.array(new_direction), np.identity(image.GetDimension()).ravel()):
        new_direction = np.identity(image.GetDimension()).ravel()
        # Compute bounding box for the original, non standard axes image.
        boundary_points = []
        for boundary_index in list(itertools.product(*zip([0, 0, 0], image.GetSize()))):
            boundary_points.append(image.TransformIndexToPhysicalPoint(boundary_index))
        max_coords = np.max(boundary_points, axis=0)
        min_coords = np.min(boundary_points, axis=0)
        new_origin = min_coords
        new_size = (((max_coords - min_coords) / spacing).round().astype(int)).tolist()
    return sitk.Resample(
        image,
        new_size,
        sitk.Transform(),
        interpolator,
        new_origin,
        new_spacing,
        new_direction,
        default_value,
        image.GetPixelID(),
    )

```

The above is my function I built using simpleITK, I am trying to understand what is code for sitk.Transform() in the above? I could not get a GitHub link to the code, because I want to understand how the transformation and resampling works for the above function.

---

<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: [November 16, 2022, 2:58pm UTC](https://discourse.itk.org/t/what-is-the-code-for-sitk-tramsform/5495/2 "2022-11-16T14:58:35Z")

</div>

Hello @pranoy-ray,

The [Resample](https://simpleitk.org/doxygen/latest/html/namespaceitk_1_1simple.html#a785a433b01484e8390f1f2723807cf65) function used in the code expects a spatial transformation mapping points between the new image and the original image being resampled. As the intent is just to resample the original image in place, identity spatial transformation, we use the generic [Transform](https://simpleitk.org/doxygen/latest/html/namespaceitk_1_1simple.html#a785a433b01484e8390f1f2723807cf65), which by default is the identity.

---

<div class="post-metadata">

### Author: ![pranoy-ray](https://discourse.itk.org/user_avatar/discourse.itk.org/pranoy-ray/32/2883_2.png) [@pranoy-ray](https://discourse.itk.org/u/pranoy-ray)
#### Post date: [November 16, 2022, 3:05pm UTC](https://discourse.itk.org/t/what-is-the-code-for-sitk-tramsform/5495/3 "2022-11-16T15:05:38Z")

</div>

> [@zivy](#):
>
> identity spatial transformation

Wow that partly answers my question. This is interesting to me, can you share some more math (Mathematical description) on this “identity spatial transformation” and the resampling?

---

<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: [November 16, 2022, 3:11pm UTC](https://discourse.itk.org/t/what-is-the-code-for-sitk-tramsform/5495/4 "2022-11-16T15:11:03Z")

</div>

Hello @pranoy-ray,

For a detailed description of resampling in ITK, please see the [ITK software guide](https://itk.org/ItkSoftwareGuide.pdf), section 2.9.4 Resample Image Filter.

---

<div class="post-metadata">

### Author: ![pranoy-ray](https://discourse.itk.org/user_avatar/discourse.itk.org/pranoy-ray/32/2883_2.png) [@pranoy-ray](https://discourse.itk.org/u/pranoy-ray)
#### Post date: [November 17, 2022, 4:11pm UTC](https://discourse.itk.org/t/what-is-the-code-for-sitk-tramsform/5495/5 "2022-11-17T16:11:19Z")

</div>

Edited:

Hi, I have been reading the software guide. I see that Gaussian Smoothing and Intensity Windowing is applied to the input by default. How do I disable that in Python?

---

<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: [November 17, 2022, 4:14pm UTC](https://discourse.itk.org/t/what-is-the-code-for-sitk-tramsform/5495/6 "2022-11-17T16:14:09Z")

</div>

Hello @pranoy-ray,

If you are only using the resample filter, there is no intensity windowing, so nothing to disable.

---

<div class="post-metadata">

### Author: ![pranoy-ray](https://discourse.itk.org/user_avatar/discourse.itk.org/pranoy-ray/32/2883_2.png) [@pranoy-ray](https://discourse.itk.org/u/pranoy-ray)
#### Post date: [November 17, 2022, 4:15pm UTC](https://discourse.itk.org/t/what-is-the-code-for-sitk-tramsform/5495/7 "2022-11-17T16:15:54Z")

</div>

What bout Gaussian Smoothing @zivy ? Is that activated by default?

---

<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: [November 17, 2022, 4:20pm UTC](https://discourse.itk.org/t/what-is-the-code-for-sitk-tramsform/5495/8 "2022-11-17T16:20:10Z")

</div>

No. Resampling just does resampling, no additional data modifications. If you want to perform smoothing prior to resampling, as in the case of multi-scale analysis, then you need to do it explicitly with the relevant filter.

---

<div class="post-metadata">

### Author: ![pranoy-ray](https://discourse.itk.org/user_avatar/discourse.itk.org/pranoy-ray/32/2883_2.png) [@pranoy-ray](https://discourse.itk.org/u/pranoy-ray)
#### Post date: [November 17, 2022, 9:13pm UTC](https://discourse.itk.org/t/what-is-the-code-for-sitk-tramsform/5495/9 "2022-11-17T21:13:55Z")

</div>

Thank you for your reply
