I am using vtkProcrustesAlignmentFilter to align 2 polydata objects that have the same number of points. I wanted to get the transform matrix out from this filter. I can do this using the following code:
but the output it essentially an identity matrix (diagonals are 1, off diagonal terms are very close to zero). This is not the correct transform between the initial polydata objects. To me it appears to be maybe the transform from the last iteration. Does this sound correct? And how would I get the overall transform, not just from the final iteration?
I don’t think vtkProcrustesAlignmentFilter can be applied to 2 pointsets, as it computes transforms to their mutual mean.
If points are matched between the two polydata (not just the number of points are equal but Nth point in one polydata corresponds to Nth point in the other polydata) then you can compute transformation between them using vtkLandmarkTransform (for rigid, similarity, or affine transform) or vtkThinPlateSplineTransform (for non-linear warping transform).
If points between the two polydata are not matched then you can use vtkIterativeClosestPointTransform to match points of one polydata to surface of the other polydata. This class requires quite good initial alignment, otherwise it can stuck into a local optimum.
If all the above fail then you can compute distance map images from the polydata and compute the transform between them using intensity-based image registration (e.g., using ITK or Elastix). This method requires you to connect a couple of filters, but it does not require point correspondence, not overly sensitive to good initial values, and works for deformable registration, too.
Thanks for your response. I have tried both vtkLandmarkTransform and vtkIterativeClosestPoint. They both work well, for matched number of points and non-matched points, respectively.
The reason I asked this question is that vtkProcrustesAlignmentFilter appears to do a good job aligning the two polydata objects and is very fast compared to vtkIterativeClosestPoint. But I need to get the relative transform between the 2 objects, which procrustes gives but the values are nonsense. Not sure why anyone would want to use procrustes if you can’t get the transform.
If this is the case, then I may just not use procrustes. If I really want the transform, I guess I can calculate it myself, knowing the initial and final positions of the polydata objects relative to each other.