# Match up two set of points in the least squares sense (procrustes command)

12 views (last 30 days)
MRR on 14 Aug 2012
Hi,
I am trying to find the best linear transformation (in the least square sense), i.e, rotation, scaling, translation and reflection, of points in a matrix Y to a different and small number of points in a matrix X.
I found procrustes command almost does what I want, but in this case I need same number of points in both matrices X and Y. What I am trying to do is a transformation from a relative system to an absolute system given by at least three points, given in matrix X.
The first figure here http://www.mathworks.se/products/statistics/examples.html?file=/products/demos/shipping/stats/cmdscaledemo.html solves the same problem, but instead number of points in X and Y matrices are equal. How could I do the same with less points as references? In the link example, the problem would be to try to execute the following (only three points are selected as references):
[D,Z] = procrustes(X(1:3,:), Y(:,1:2));
But I got the following error:
Error using procrustes (line 85) X and Y must have the same number of rows (points).
Thanks,
--M

Peter Perkins on 14 Aug 2012
MRR, perhaps I am misunderstanding your question, but you're going to have to say what you mean by "a least squares sense" if you want to compare two sets of points with different numbers of points. The goal of the PROCRUSTES function is to find a rotation/scaling/translation/reflection that makes the distances small between corresponding points. If you don't have a 1:1 correspondence between points, the criterion that PROCRUSTES minimizes doesn't apply.
The line of code you suggests that you want to take one set of points and transform them to be "near" to a subset of another set of points. That's perfectly reasonable, but you need to have the same number of points in both inputs to PROCRUSTES. In addition, that line of code seems to indicate that X has the larger number of points, which is exactly the opposite of your description in your first paragraph. From that description, I would have thought you would want to subset Y to have the same ("small") number of points as X. From there, you could get the last output of PROCRUSTES and apply the transformation to all the points in Y.
MRR on 14 Aug 2012
Hi Peter,
Thank you for your answer. X has only three points, each one with its 2 coordinates. Y(:,1:2) is a subset of matrix Y where I take the 2 first columns, as in the posted link above. Anyways without this clarification one could understand that X has more points than Y.
Coming from work I was thinking the same you said, i.e, consider a small subset of Y, equal in numbers to X, and it works, but it works because the Y subset I am choosing has a direct correspondence with X (Y are the X points transformed, and in my problem I am supposing I dont know all X but at least 3 points, which are enough provided a linear transformation is applied). So after that step I can apply the transformation obtained to the other points:
[d1,Z1,transformation1] = procrustes(X (1:3,:), Y(1:3,:))
Z_restOfPoints = transformation1.b * Y(4:length(Y),:) * transformation1.T + transformation2.c
It is important to note that: transformation2.c = transformation1.c(1:length(restOfPoints),:)
I have tested it and it seems it works and intuitively also makes sense. However I have to check its validity for a large set of points.
Regards,
--M