Dear All,
I have some linear transforms that are packed into a composite transform. Is there a way of calculating a single affine transform that would be the result of the composition ? I haven’t found any function to do this…
Thanks for your help,
Yann
With linear transforms, you could go through all of them using composite->GetNthTransform
, get their 4x4 matrices, and multiply them together. If you started with an identity 4x4, you will end up with you composite transform in a single 4x4 matrix. Some typecasting to affine transform might be involved.
There is no function to do this directly in ITK, but a while ago I wrote a tool to handle some simple operations with ITK transforms (available here). You can compile it and call compose
if you have only 2 affine transforms to combine, or call concatenate
for N transforms (this option also handles non-rigid transforms and generates a displacement field (or deformation field?). You can read the code to see the different options or run the program without any option.
Thanks both ! I explored a bit further, and found the a compose()
function in itk::MatrixOffsetTransformBase
.
So I wrote this simple code that I share in case other people need it:
#include "itkAffineTransform.h"
#include "itkCompositeTransform.h"
// ... //
//compoTform
typedef itk::AffineTransform< Type, Dimension > AffineType;
AffineType::Pointer tformResult = AffineType::New();
tformTest->SetIdentity();
size_t nTform = compoTform->GetNumberOfTransforms();
for (size_t i = nTform; i-- > 0 ; ) {
tformResult->Compose( static_cast< const AffineType * >( compoTform->GetNthTransformConstPointer(i) ) );
}