tform3

clear
close all
load imgdata

im = im2double(imread(filename));
imshow(im);

% reduce figure size
pos = get(gcf,"Position");
pos(3:4) = [size(im,2) size(im,1)]*0.2;
set(gcf,"Position",pos);
tf = fitgeotrans(imgPoints,worldPoints*10,'projective');
format short g
TA = tf.T
fprintf('norm(TA) = %g\n',norm(TA));
TA =
      0.63487     0.056575   0.00020729
    -0.022398      0.47434  -1.9766e-05
      -1594.4      -277.67            1
norm(TA) = 1618.41
w = transformPointsForward(tf,imgPoints(12,:))/10
display('should match');
w2 = worldPoints(12,:)
w =
       3.0112       9.0008
should match
w2 =
     3     9
[xf1, xf1_ref] = imwarp(im,tf,'fillValue',[0.5 0.5 1]);
imshow(imresize(xf1,0.2)); title('Projective transformed output using tform')
xf1_ref
xf1_ref = 
  imref2d with properties:

           XWorldLimits: [-1741.6 681.35]
           YWorldLimits: [-277.49 1003.5]
              ImageSize: [1281 2423]
    PixelExtentInWorldX: 1
    PixelExtentInWorldY: 1
    ImageExtentInWorldX: 2423
    ImageExtentInWorldY: 1281
       XIntrinsicLimits: [0.5 2423.5]
       YIntrinsicLimits: [0.5 1281.5]
% choose a truncated region to display (worldpoints extend 0 to 210)
% xf1_ref.XWorldLimits = [-15 225];
% xf1_ref.YWorldLimits = [-15 225];
xf1_ref.XWorldLimits = [-90 300];
xf1_ref.YWorldLimits = [-90 300];
xf1_ref.ImageSize = [600 600];
[xf2 xf2_ref] = imwarp(im,tf,'OutputView',xf1_ref,'FillValues',[0.5 0.5 1]);
xf2_ref
imshow(xf2)
xf2_ref = 
  imref2d with properties:

           XWorldLimits: [-90 300]
           YWorldLimits: [-90 300]
              ImageSize: [600 600]
    PixelExtentInWorldX: 0.65
    PixelExtentInWorldY: 0.65
    ImageExtentInWorldX: 390
    ImageExtentInWorldY: 390
       XIntrinsicLimits: [0.5 600.5]
       YIntrinsicLimits: [0.5 600.5]
% use the dlt algorithm
tf2 = dlt(imgPoints,worldPoints*10);
format short g
TB = tf2.T
fprintf('norm(TB) = %g\n',norm(TB));
TB =
  -0.00039223  -3.5166e-05  -1.3024e-07
   1.3841e-05  -0.00029289   1.2327e-08
      0.98508      0.17211  -0.00061125
norm(TB) = 1
% ratio of elements (after adjusting T(3,3))
format short g
fact = TA(3,3)/TB(3,3)
TC = TB * fact

ratio = TC./TA
format short
fact =
        -1636
TC =
      0.64169     0.057532   0.00021308
    -0.022643      0.47917  -2.0166e-05
      -1611.6      -281.57            1
ratio =
       1.0107       1.0169       1.0279
        1.011       1.0102       1.0203
       1.0108        1.014            1