# How to apply transform to strictly a subset of an image?

**URL:** https://discourse.itk.org/t/how-to-apply-transform-to-strictly-a-subset-of-an-image/4195
**Category:** Beginner Questions
**Tags:** simpleitk, registration, python
**Created:** [June 10, 2021, 1:35am UTC](https://discourse.itk.org/t/how-to-apply-transform-to-strictly-a-subset-of-an-image/4195 "2021-06-10T01:35:19Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jingxuan](https://discourse.itk.org/user_avatar/discourse.itk.org/jingxuan/32/1768_2.png) [@jingxuan](https://discourse.itk.org/u/jingxuan)
#### Post date: [June 10, 2021, 1:35am UTC](https://discourse.itk.org/t/how-to-apply-transform-to-strictly-a-subset-of-an-image/4195/1 "2021-06-10T01:35:19Z")

</div>

Hello. I have some conceptual understanding of registration and very little of its math so I’m looking for a practical solution. Thank you in advance for any help offered.

Say I registered 3D image A to 3D image B in a 2-step process by first finding the best-fit affine transform and then a deformation field on top of that. Applying these two transforms (affine first then dense deformable as a composite transformation) will warp the whole of image A to the space of image B.

How do I use this composite transformation to now map an arbitrary subset of image A to that of image B? For example, how do I warp a 2D slice of image A to the space of image B? What if I just wanted to map a point (1D)?

One solution is to put that subset of points into the same 3D space of image A and then apply the transform as I would on a full image of A. I have tried this and it works as it should. However, that’s costly in terms of memory and, I suspect, computationally. How do I strictly work on an arbitrary and smaller subset of image A?

---

<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: [June 10, 2021, 1:19pm UTC](https://discourse.itk.org/t/how-to-apply-transform-to-strictly-a-subset-of-an-image/4195/2 "2021-06-10T13:19:29Z")

</div>

Hello @jingxuan,

Assuming the following registration configuration:  
image A - used as fixed image in registration.  
image B - used as moving image in registration.  
T\_A^B - the final transformation (composite or any other type). Maps points from image A’s coordinate system to image B’s coordinate system.

Most often we resample image B onto the grid defined by image A. If you want to define a different grid, possibly smaller than the whole of image A, you need to define it in terms of: origin, spacing, direction cosine matrix, and size. The origin and direction cosine matrix are with respect to the coordinate system of image A. So a point on this grid is always ^AP. Please see [this jupyter notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/21_Transforms_and_Resampling.ipynb) for various approaches to defining a resampling grid. Note that you can also resample using an arbitrary set of points that are not defined by a grid (see section **Resampling at a set of locations** in that notebook).
