# Transform DVF from one patient to another

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!

Okay I will try to specify a bit further and hope for advice. I think I need something like this:

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?

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)