MATLAB Answers


Find matching points from two coordinate systems

Asked by Yangfan Peng on 7 Oct 2019
Latest activity Commented on by Matt J
on 10 Oct 2019
I have 10 points with x and y coordinate (cell locations imaged with microscope). I have used two different methods to image these cells, so I have two sets of coordinates that could be rotated, sheared, shifted, mirrored to each other. I would like to assign each point from one coordinate system to the matching point in the other coordinate system. How can I do that? In theory, some kind of transformation optimizing minimum distance between the points would be desirable.
In the end I would like to assign properties I obtained from the cells in one method to properties obtained with the other method.
Thank you.


Generally speaking, it is an impossible problem. For example, suppose there were 3 points in each image with the A-points forming an equilateral triangle and the B-points an equilateral triangle in a different position. Then there is no unique matching between the points that can be determined purely from their relative spacing - the symmetry among the points is too perfect. There would have to be some a priori known asymmetry among the points in order to match them.
What if just find closest pairs of points? Using pdist2() for example?
I always have 7-10 points and they are mostly asymmetric. I would like to rotate/mirror the coordinates in a way that the points can be closest to each other. How can I combine pdist2() with the transformation part?

Sign in to comment.

2 Answers

Answer by Bruno Luong
on 8 Oct 2019

Look for the literature of image registration.
For simple rotation/scaling/translation you can use Matt J's submission
For more complex deformation, you need to apply spline deformation
There are a bunch of intermediate method for camera which take into account for camera cushion distortion or higher order. Pick one that is suitable for your need.


Thank you for the suggestions. I used the fitgeotrans function and got the transformation object. But how do I go from there to determine which point matches to which other point? See above for detailed description of the problem.

Sign in to comment.

Answer by Matt J
on 8 Oct 2019
Edited by Matt J
on 8 Oct 2019

If the shear component of the deformation isn't too strong, the matchpoints function defined below might work. It will sort the rows of B to correspond with A and also return the corresponding permutation indices. It relies on absor, mentioned by Bruno, which you will have to download
function [permIndices,Bsorted]=matchpoints(A,B)
% A: an Nx2 matrix of points
% B: an Nx2 matrix of points from A transformed and unordered
% permIndices: permutation indices of rows of B thought to match A
% Bsorted: the Nx2 permuted version of B
B3=B.'; B3(3,:)=0;
reg=absor( Lb,La,'doScale',1);
if nargout>1
function L=landmarks(P)
G=pdist2(P,P); G(~G)=nan;
[i,j]=find( G==min(G(:)) ,1);
if norm(I-K)<norm(J-K)
Applying it to your example data, I obtain,
A = [376 455;421 489;465 537;353 512;355 535;329 571;377 593;417 598;482 575;355 634];
B = [168 88;107 138;69 194;126 229;163 232;199 267;272 239;228 210;235 155;215 68];
hold on
hold off


Why so many times edited? Do you have some problems?
Just making improvements.

Sign in to comment.