Using imtransform and then imregister to undo the transform the imregister result is a 't' transform different from the original imtransform 't'.

1 view (last 30 days)
If I transform an image using 't' and then imregister to recover original image the 't' is different.
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);
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];

Answers (1)

Matt J
Matt J on 11 Jul 2013
Edited: Matt J on 11 Jul 2013
The accuracy of the registration doesn't seem terrible. The translation was estimated to sub-pixel accuracy. No registration algorithm is infinitely accurate, of course, because the solution is not closed-form.
However, if you use the 'rigid' or 'translation' transform type instead of 'similarity', you'll probably reach a more accurate result (only when your transformations are truly of those types, of course).
  2 Comments
Howard
Howard on 11 Jul 2013
Edited: Matt J on 11 Jul 2013
I tried "rigid" and "translation" and t was even farther off.
t = [1.000000e+00 0.000000e+00 0.000000e+00;...
0.000000e+00 1.000000e+00 0.000000e+00;...
4.999931e-01 -6.089329e-01 1.000000e+00];
The original t was:
t=[ 1.0 0 0
0 1.0 0
1.1 0 1.0000];
The signs are different and x and y seem to be swapped in this and above example). Matlab users need to see how 't' is defined for imtransform and imregister in this simple example. Thanks.
Matt J
Matt J on 11 Jul 2013
Edited: Matt J on 11 Jul 2013
Your object is too "thin" compared to your pixel size for your transformation to be (approximately) invertible. IMTRANSFORM garbles your pixel intensities with interpolation error. Try instead with the following
A((1:M+1:50*(M+1)))=1; %
A=imdilate(A,ones(10));
t=[ 1.0 0 0
0 1.0 0
5.1 0 1.0000];
When I run with this data (and use 'translation' as well), the output of imregister I get is,
t =
1.0000 0.0000 0
0.0000 1.0000 0
5.0104 -0.0968 1.0000

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!