# Transform DVF from one patient to another

**URL:** https://discourse.itk.org/t/transform-dvf-from-one-patient-to-another/5976
**Category:** Beginner Questions
**Tags:** registration
**Created:** [June 1, 2023, 11:10am UTC](https://discourse.itk.org/t/transform-dvf-from-one-patient-to-another/5976 "2023-06-01T11:10:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![RT\_newbie](https://discourse.itk.org/letter_avatar_proxy/v4/letter/r/f17d59/32.png) [@RT\_newbie](https://discourse.itk.org/u/RT_newbie)
#### Post date: [June 1, 2023, 11:10am UTC](https://discourse.itk.org/t/transform-dvf-from-one-patient-to-another/5976/1 "2023-06-01T11:10:23Z")

</div>

Hi

I have a question regarding mapping DVFs from one patient to another.  
I have two different patients. My patient A has a DVF that I would like to bring to the other patient to deform the patient with this DVF.

I register them affine (translation,rotation,scaling) and deformably, so I have a transformation matrix and a DVF to use for translating the DVF from one space to another.

Those are the thoughts behind what I want to do. However I am not really sure about its practical implementation. Is someone familiar with this problem?

Edit: To clarify my main issue is that in my understanding applying a transformation to a DVF is only transforming the grid but not the vectors in the voxels. This is where I am a bit confused about how to do this.

Thanks a lot!

---

<div class="post-metadata">

### Author: ![RT\_newbie](https://discourse.itk.org/letter_avatar_proxy/v4/letter/r/f17d59/32.png) [@RT\_newbie](https://discourse.itk.org/u/RT_newbie)
#### Post date: [August 2, 2023, 12:17pm UTC](https://discourse.itk.org/t/transform-dvf-from-one-patient-to-another/5976/2 "2023-08-02T12:17:11Z")

</div>

Okay I will try to specify a bit further and hope for advice. I think I need something like this:  
 ![image](https://discourse.itk.org/uploads/default/original/2X/e/eac8620f536cd850aa7073ec6863c04ebfa31f5a.png)

And lets say the transformations are given by the deformation field A (Maps CT of patient 2 to 1), its inverse A-1 (Maps CT of patient 1 to 2) and the to be deformed deformation field B (Maps CT x of patient 2 to the CT of patient 2 that is used for the other registrations) .

I cannot wrap my had around in which order I have to apply those. When I try as below or with changed dvfA dvfA\_inv and look at the results, I am unsure what is the correct way. Could someone help me with this please?

```auto
this_tx = sitk.DisplacementFieldTransform(dvfA.GetDimension())
this_tx .SetInterpolator(sitk.sitkNearestNeighbor)
this_tx .SetDisplacementField(dvfA)
resampler = sitk.ResampleImageFilter()
resampler.SetTransform(this_tx )
resampler.SetReferenceImage(referenceCT)
first_tx = resampler.Execute(dvfB)

dis_tx = sitk.DisplacementFieldTransform(dvfA_inv.GetDimension())
dis_tx.SetInterpolator(sitk.sitkNearestNeighbor)
dis_tx.SetDisplacementField(dvfA_inv)
resampler = sitk.ResampleImageFilter()
resampler.SetTransform(dis_tx)
resampler.SetReferenceImage(referenceCT)
second_tx = resampler.Execute(first_tx)

```
