Issues with TransformContinuousIndexToPhysicalPoint for anisotropic images

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.

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(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?

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 or is this something you implemented yourself?


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? :slight_smile:

Than you very much!

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 (also available: video recording).