# Issues with TransformContinuousIndexToPhysicalPoint for anisotropic images

**URL:** https://discourse.itk.org/t/issues-with-transformcontinuousindextophysicalpoint-for-anisotropic-images/5588
**Category:** Algorithms
**Tags:** python, simpleitk
**Created:** [December 22, 2022, 10:31am UTC](https://discourse.itk.org/t/issues-with-transformcontinuousindextophysicalpoint-for-anisotropic-images/5588 "2022-12-22T10:31:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![nifti](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/edb3f5/32.png) [@nifti](https://discourse.itk.org/u/nifti)
#### Post date: [December 22, 2022, 10:31am UTC](https://discourse.itk.org/t/issues-with-transformcontinuousindextophysicalpoint-for-anisotropic-images/5588/1 "2022-12-22T10:31:39Z")

</div>

Hi all,

I have a very basic question regarding the `TransformContinuousIndexToPhysicalPoint()` function.  
I have two images:

- isotropically sampled image (1x1x1)
- anisotropically acquired image (0.2x0.2x5)

I would like to obtain the physical coordinates of both images, however I do not get the results of the coordinates grids for anistropically sampled images that I expect. I have illustrated this in the code snippet below. This should clarify my problem.

```auto
import SimpleITK as sitk

import numpy as np

image = sitk.ReadImage(args.image)

image = sitk.Cast(image, sitk.sitkFloat32)

image_spacing = image.GetSpacing()

image_origin = image.GetOrigin()

image_data = sitk.GetArrayFromImage(image)

(x, y, z) = image.GetSize()

coord1 = image.TransformContinuousIndexToPhysicalPoint((0,0,0))

coord2 = image.TransformContinuousIndexToPhysicalPoint((0,0,1))

x1, y1, z1 = image.TransformContinuousIndexToPhysicalPoint((0,0,0))

x2, y2, z2 = image.TransformContinuousIndexToPhysicalPoint((x,y,z))

xmin = np.amin([x1, x2])

xmax = np.amax([x1, x2])

ymin = np.amin([y1, y2])

ymax = np.amax([y1, y2])

zmin = np.amin([z1, z2])

zmax = np.amax([z1, z2])

local_bound_x = [xmin, xmax]

local_bound_y = [ymin, ymax]

local_bound_z = [zmin, zmax]

print("Image:")

print(f'Spacing: {image_spacing}')

print("X:", local_bound_x)

print("Y:", local_bound_y)

print("Z:", local_bound_z)

res = tuple(map(lambda i, j: i - j, coord1, coord2))

print(f'Physical Coordinates [0,0,0]: {coord1}')

print(f'Physical Coordinates [0,0,1]: {coord2}')

print(f'Difference coord1 - coord2: {res}')

```

**Results for isotropic image:**

Spacing: (1.0, 1.0, 1.0)

X: [-97.0, 96.0]

Y: [-97.0, 132.0]

Z: [-78.0, 115.0]

Physical Coordinates [0,0,0]: (96.0, 132.0, -78.0)

Physical Coordinates [0,0,1]: (96.0, 132.0, -77.0)

Difference coord1 - coord2: (0.0, 0.0, -1.0)

→ This behaves as I expected.

**Results for anistropic image:**

Spacing: (0.2083333283662796, 0.2083333283662796, 5.0)

X: [-56.08902359008789, 63.94401697175637]

Y: [-71.00065914028002, 66.02693176269531]

Z: [-62.45258712768555, 43.568669158926525]

Physical Coordinates [0,0,0]: (-56.08902359008789, 66.02693176269531, -62.45258712768555)

Physical Coordinates [0,0,1]: (-56.087482356984445, 65.29397413920222, -57.50660181161718)

Difference coord1 - coord2: (-0.0015412331034454496, 0.7329576234930926, -4.9459853160683664)

→ I would have expected the following difference

**Difference coord1 - coord2: (0.0, 0.0, -5.0)**

_Why do the anistropic and isotropic physical scanner coordinates behave differently?_ How can I correct this?

---

<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: [December 22, 2022, 2:54pm UTC](https://discourse.itk.org/t/issues-with-transformcontinuousindextophysicalpoint-for-anisotropic-images/5588/2 "2022-12-22T14:54:26Z")

</div>

Hello @nifti,

Before looking at the line you highlighted, there is something going on in the resampling from non-isotropic to isotropic.

If this was done correctly then the expectation is that the origins of the two images be the same. The physical coordinates of index `[0,0,0]` should be the same for both images and they are significantly different. Are you using the `make_isotropic` function from [this notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/05_Results_Visualization.ipynb) or is this something you implemented yourself?

---

<div class="post-metadata">

### Author: ![nifti](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/edb3f5/32.png) [@nifti](https://discourse.itk.org/u/nifti)
#### Post date: [December 22, 2022, 4:39pm UTC](https://discourse.itk.org/t/issues-with-transformcontinuousindextophysicalpoint-for-anisotropic-images/5588/3 "2022-12-22T16:39:02Z")

</div>

Hi @zivy

Thank you very much for the prompt reply - I haven’t done any resampling at this point, I just looked at two totally different images - one is brain (isotropic), one is spine (anisotropic) - so the absolute coordinates should not be comparable at all. However, my question should be still valid - I would expect a different result for the difference of coordinates in the anisotropic case? 🙂

Than you very much!

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 22, 2022, 5:50pm UTC](https://discourse.itk.org/t/issues-with-transformcontinuousindextophysicalpoint-for-anisotropic-images/5588/4 "2022-12-22T17:50:44Z")

</div>

Your anisotropic image seems to have non-identity direction. But the norm of the difference vector is very close to 5.0.

Maybe take a look at [Metadata Preservation for Brain Registration tutorial](https://insightsoftwareconsortium.github.io/GetYourBrainStraight/HCK01_2022_Virtual/Tutorials/MetadataPreservation/MetadataPreservation.html) (also available: [video recording](https://drive.google.com/file/d/14-Kgt-VoqAHKJHLQBVuOAB-u7w7ve2N4/view?usp=sharing)).
