# Transform a point index into its respective one after registration

**URL:** https://discourse.itk.org/t/transform-a-point-index-into-its-respective-one-after-registration/2605
**Category:** Algorithms
**Created:** [January 11, 2020, 4:32am UTC](https://discourse.itk.org/t/transform-a-point-index-into-its-respective-one-after-registration/2605 "2020-01-11T04:32:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Everaldo](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b9bd4f/32.png) [@Everaldo](https://discourse.itk.org/u/Everaldo)
#### Post date: [January 11, 2020, 4:32am UTC](https://discourse.itk.org/t/transform-a-point-index-into-its-respective-one-after-registration/2605/1 "2020-01-11T04:32:40Z")

</div>

I did a registration in two steps, Affine -\> B-Spline, and now I want to know what is the correspondent index in the new space for a given index in the original space. Here is the code I’m using:

```
#Receiving the voxel coordinates
print("Please, insert the voxel coordinates (X, Y, Z): ")
voxel = [int(x) for x in input().split()]

physical_voxel = moving_volume.TransformIndexToPhysicalPoint(voxel) 
print(physical_voxel)

#Applying the transformation
transformed_point = BS_transformation.TransformPoint(Affine_transformation.TransformPoint(physical_voxel))

print(transformed_point)
fixed_index = Fixed_volume.TransformPhysicalPointToIndex(transformed_point)
print(fixed_index)
label = fixed_atlas.GetPixel(fixed_index)

```

Voxel is the index in the original space.

The problem is: I do not get the correct index in the registered space but for me everything is right. So, How to solve this?

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [January 11, 2020, 10:40pm UTC](https://discourse.itk.org/t/transform-a-point-index-into-its-respective-one-after-registration/2605/2 "2020-01-11T22:40:15Z")

</div>

Hello Everaldo,

Welcome to the ITK community! ☀

A few items to note:

> physical\_voxel = moving\_volume.TransformIndexToPhysicalPoint(voxel)

Usually, the registered transform goes from fixed to moving space, so you may need to reverse the volumes used.

> transformed\_point = BS\_transformation.TransformPoint(Affine\_transformation.TransformPoint(physical\_voxel))

A [CompositeTransform](https://itk.org/Doxygen/html/classitk_1_1CompositeTransform.html) could optionally be used to encapsulate these steps.

---

<div class="post-metadata">

### Author: ![Everaldo](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b9bd4f/32.png) [@Everaldo](https://discourse.itk.org/u/Everaldo)
#### Post date: [January 13, 2020, 5:15am UTC](https://discourse.itk.org/t/transform-a-point-index-into-its-respective-one-after-registration/2605/3 "2020-01-13T05:15:49Z")

</div>

Thanks for your reply Matt. What do you mean by “Reverse the volumes”? Do you mean assume that the coordinates VOXEL are in the fixed\_volume space and change Fixed\_volume by Moving\_volume? Or do you mean by creating an inverse transformation?

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [January 13, 2020, 5:51am UTC](https://discourse.itk.org/t/transform-a-point-index-into-its-respective-one-after-registration/2605/4 "2020-01-13T05:51:24Z")

</div>

> [@Everaldo](#):
>
> Fixed\_volume by Moving\_volume?

Yes, in the code snippet, relpace `moving_volume` with `Fixed_volume` and `Fixed_volume` with `moving_volume`.

---

<div class="post-metadata">

### Author: ![Everaldo](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b9bd4f/32.png) [@Everaldo](https://discourse.itk.org/u/Everaldo)
#### Post date: [January 13, 2020, 6:12am UTC](https://discourse.itk.org/t/transform-a-point-index-into-its-respective-one-after-registration/2605/5 "2020-01-13T06:12:47Z")

</div>

Matt, I’ve made the changes you said, but I’m getting some errors. Here is the code I’m using:

```
#Receiving the voxel coordinates
print("Please, insert the voxel coordinates (X, Y, Z): ")
voxel = [int(x) for x in input().split()]

physical_voxel = fixed_volume.TransformIndexToPhysicalPoint(voxel) 
print(physical_voxel)

#Applying the transformation
transformed_point = BS_result.TransformPoint(Affine_result.TransformPoint(physical_voxel))

print(transformed_point)
fixed_index = moving_volume.TransformPhysicalPointToIndex(transformed_point)
print(fixed_index)
label = fixed_volume.GetPixel(fixed_index)

print(label)

```

When I test with the entry (192, 160, 58), I get the fixed\_index (81, 127, -13) which cause an error. Is my code right or I didn’t understand what you said?

---

<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: [January 13, 2020, 4:45pm UTC](https://discourse.itk.org/t/transform-a-point-index-into-its-respective-one-after-registration/2605/6 "2020-01-13T16:45:50Z")

</div>

Look at this [issue](https://github.com/InsightSoftwareConsortium/ITK/issues/1556) in the bug tracker, and its soon-to-be-proposed fix. It should be instructive on what you might be doing wrong in the registration, and how to fix it.

Side note: voxel coordinates entered are IJK, not XYZ as your message indicates.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [January 13, 2020, 4:58pm UTC](https://discourse.itk.org/t/transform-a-point-index-into-its-respective-one-after-registration/2605/7 "2020-01-13T16:58:22Z")

</div>

> [@Everaldo](#):
>
> fixed\_index = moving\_volume.TransformPhysicalPointToIndex(transformed\_point) print(fixed\_index) label = fixed\_volume.GetPixel(fixed\_index)

Should be:

```auto
moving_index = moving_volume.TransformPhysicalPointToIndex(transformed_point)
print(moving_index)
label = moving_volume.GetPixel(moving_index)

```

Or, invert the transform if the label from the fixed volume is desired.
