Difficulty fitting translation and rotation between two matrices of coordinate points
Show older comments
My current effort seems like a simple one, but for the life of me I cannot get a working version, with or without builtin functions.
In this example, I have two sets of points where one is a simple rotation of the other. My real world application will have to worry about rotation, translation, and potentially minor radial distortion issues (scaling based on radial distance). I need to be able to fit one set to another and extract (at least) the rotation and x and y translation of the transform. Later I hope to check non-linear radial distortions.
I tried using regionprop stuff via Centroid and Orientation to rotate around, but translation seems to get messed up, since the centroid and the rotaiton isn't about the center of the "image".
Over the weekend I learned about fitgeotrans and am trying to get that, or some similar family of functions to work. (Looks like having 2022b would give me more potentially useful tools, but alas, I have 2020b). Using fitgeotrans gives me a tform that includes a significant scaling factor, which isn't real. There should just be a rotation of ~30 degrees and maybe a translation of a few pixels.
ROTFID = [140,45;-96,-32;-58,186;60,-184;111,96;-76,-67;127,-146;-126,148;63,123;-43,-88;167,-83;-165,85];
FID = [99,109;-67,-76;-143,132;145,-130;49,138;-32,-96;184,-63;-182,65;-6,138;7,-98;-185,-9;187,11];
tform = tform = fitgeotrans(ROFID,FID, 'similarity');
%Regardless of Forward,Inverse, Fid or ROFID, the answer is clearly wrong
%with an unwanted and incorrect scale factor
answ = transformPointsForward(rform,ROFID);
I tried using imwrap and similar, with and without a reference via imref2d. I also tried a suggestion involving worldToIntrinsic which I did not understand and did not work.
I'd be happy to share my regionprop centroid/orientation half-solution, but I'm confident that solution will not proof robust in final application.
To show the above code gives a poor result:
figure
p1 = scatter(FID(:,1),FID(:,2));
hold;
p2 = scatter(ROFID(:,1),ROFID(:,2));
p3 = scatter(answ(:,1),answ(:,2));
p1 and p2 are rotations of eachother about 0,0. p3 has a strange scaling effect. I cannot seem to suppress it. I cannot seem to extract just the rotation and translation and apply it to the points (for visualizing purposes)
I can use something like this to get the angle, and translation from the matrix:
u = [0 1];
v = [0 0];
[x, y] = transformPointsForward(tform,u,v);
dx = x(2) - x(1);
dy = y(2) - y(1);
angle = (180/pi) *atan2(dy,dx);
translation = [tform.T(3,1) tform.T(3,2)];
%scale can also be gotten here, which is how I know it is wrong.
%scale
scale = 1 / sqrt(dx^2+dy^2);
There could be some shear in here I have not calculated, but the true answer should be 0. All I did was rotate the points in another program.
I hope I have been thorough in my end-goal and efforts so far. Thank you for reading and thinking.
Accepted Answer
More Answers (0)
Categories
Find more on Region and Image Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!