How do I determine the angle, scale and translation between two images after imregister?

I have one rotated, scaled, translated image and a fixed image. The output of imregister, t is shown:
[movingregistered] = imregister(fixed,moving,'similarity',optimizer,metric,'DisplayOptimization',1);
t = [1.001092e+00 -6.373544e-04 0.000000e+00;...
6.373544e-04 1.001092e+00 0.000000e+00;...
-1.351965e+00 5.672809e-01 1.000000e+00];
I need accurate subpixel knowledge of the offset and rotation of two images. Is t rotated about center pixel or upper left pixel (1,1). It is not sufficient to show the images "look" registered :) Using R2012B
What is the definition of the 9 elements of t?
Thanks, Howard

1 Comment

Your code doesn't show how t was produced. It appears nowhere in your call to imregister. Did you call imregister with a 2nd output arg that you aren't showing?

Sign in to comment.

Answers (3)

You can use imregtform to get the transformation matrix:
doc imregtform

8 Comments

The OP is using R2012B, which does not include imregtform. :-(
But it's great to discover that the issue is fixed in R2013!
Well, if I could allow myself to vent for just a moment, I really think they should back-patch this into R2012 or whenever imregister was introduced. A registration routine without the ability to return the transformation parameters is like a 3-wheeled car.
You can go into imregister and add the transformation matrix as an output.
You can go into imregister and add the transformation matrix as an output.
That was easier than I thought!
Actually, not so easy. The toolbox installs with permission barriers on imregister and its directory. I guess I could de-activate those, but I would have prefered to make my own separate local copy. No good, though, because imregister relies on private directory files.
You could make a local copy in that directory. That way it has access to the private files.
yes, I've done that now. I'm vaguely nervous, though, about tampering with factory-installed MATLAB directories. I'll be happier once I've upgraded to a version with imregtform!

Sign in to comment.

Is t rotated about center pixel or upper left pixel (1,1).
After some experimentation with code (below) that duplicates the relevant portions of IMREGISTER, I think I can safely say that the rotation is about the upper left pixel.
M=100;N=M;
A=zeros(M);
A(1:M+1:50*(M+1))=1;
%30 degree rotation
t=[ 0.8660 -0.5000 0
0.5000 0.8660 0
0 0 1.0000];
B = imtransform(A, maketform('affine',t), 'XData', [1 N], 'YData', [1 M], ...
'Size', [M N]);
figure;imagesc(A)
figure; imagesc(B+A)
If I use imtransform and then imregister I get transform matrix t which do not agree. What's up with that?
M=100;N=M; A=zeros(M);
A(1:M+1:50*(M+1))=1; %
t=[ 1.0 0 0
0 1.0 0
1.1 0 1.0000];
B = imtransform(A, maketform('affine',t), 'XData', [1 N], 'YData', [1 M], ...
'Size', [M N]);
figure; imagesc(B+A)
fixed = A;
moving = B;
[optimizer,metric] = imregconfig('monomodal'); %try monomodal
[movingregistered] = imregister(fixed,moving,'similarity',optimizer,metric,'DisplayOptimization',1, 'PyramidLevels',3);
But the output of imregister has a very different transform with cos values > 1.0
Use the resulting tform struct with imtransform.
t = [1.010712e+00 7.025940e-04 0.000000e+00;...
-7.025940e-04 1.010712e+00 0.000000e+00;...
1.817039e-01 -9.390789e-01 1.000000e+00];

1 Comment

This seems like a different question than what you originally posted. First, please confirm whether that question is still open. I thought I provided pretty convincing evidence that the rotation was about the upper left corner. If you agree, please Accept-click that answer and start a new question. If you don't agree, please explain why the question is unanswered.

Sign in to comment.

Asked:

on 19 Jun 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!