# concatenating dense deformation fields

I was wondering if it is possible to concatenate two dense deformation fields in ITK python or SimpleITK.
Having

B = T2 ( T1 ( A(x) ) )

In which T1, and T2 are both dense deformation fields (both with size ofImage A and with vector type voxels), is it possible to derive

B = T ( A(x) )

which would be concatenation of T1 and T2.
I know there is a CompositeTransform class but does AddTransform, add the deformation fields or it applies the first one and then the second one.

My reason for concatenation of dense fields is that in my registration framework I predict a dense deformation field at each iteration, but I donâ€™t want to resample the images to avoid interpolation artifacts as a result of multiple resampling.

That might be as simple as adding the deformation fields together using AddImageFilter. If that doesnâ€™t work, report. Also, someone else with more experience with deformation fields might offer more/better adivce.

Problem is adding two deformation fields is not the same as concatenating them. AddImageFilter doesnâ€™t work

You could iterate through all of the points of the final deformation field, and calculate its transform vector via CompositeTransform's TransformPoint method.

The SimpleITK/ITK composite transform does not combine the transform. It applies one transformation then the other.

I believe this can be accomplished with ResampleImageFilter with one transformâ€™s displacement field image being the input image and the other being transform. Careful attention is needed to determine the proper order.

1 Like

I suppose ResampleImageFilter can handle vector type input image and proper interpolation. right?

1 Like

Yes it can!

1 Like

Applying one transformation on the result of the other is the correct way of combining/concatenating two transforms.

ITK handles these composite transforms correctly as long as you only need to compute forward transform and you only try to compute the displacement in a region that is inside of all displacement fields in the transform. Inverse transform computation, especially near the region boundaries may not work reliably (and no inverse can be computed outside the displacement field regions).

Composite transforms are very well supported in 3D Slicer (ITK composite transforms can be read, written, visualized, applied to any kind of data types, resampled to a combined displacement field, etc.), so you can use 3D Slicer for testing, validation, and even batch processing from Python.

3 Likes

Is there any correct way to avoid multiple resampling of the image as a result of applying multiple transformation? So, instead of T2 ( T1( A(x) ) we go straight to T( A(x) ) since in the former we are resampling twice (and even more, if we have more than 2 dense deformations) and in the latter we are resampling once (no matter how many deformations)