Eric,

I had been meaning to answer this question days ago and I finally came up for air. Hopefully this answer will still be of use.

There are several issues at play here:

1) The Image Processing Toolbox uses a different convention for the transformation matrix than many references you will find (they are a transponse of each other). The IPT convention is the transpose of many reference sources and is:

tx = 1.65;

ty = 5.32;

T = [1 0 0; 0 1 0; tx ty 1];

w = 0;

z = 0;

xy = [w z 1]*T

This means that for a rigid transformation, the tform object returned by imregcorr is off the form:

tform = [cos(theta) sin(theta) 0; sin(theta) -cos(theta) 0; tx ty 1];

With the rotation matrix in the upper 2x2 and the translation in the last row.

2) In the operation you are synthetically applying to your input image and then attempting to recover, you apply a translation via imtransform and THEN you perform a rotation by using imrotate.

The transformation matrix returned by imregtform is an affine transformation consisting of a linear portion A (the upper 2x2 which includes rotation and scale) and an additive portion b (the last row which applies the translation.

In an affine transformation, the linear part of the transformation is applied prior to the additive part of the transformation: T(x) = Ax + b;

All of this together means that the transformation returned by imregtform has a different interpretation than your implementation of Reddy. This assumes the order of operations used to transform the moving was rotation followed by translation, not the other way around as you have defined it.

Another way of seeing this is to note that transformations can be composed by matrix multiplication, and that matrix multiplication is non-commutative, meaning that the order in which you apply rotation/translation matters.

theta = 5;

Trotate = [cosd(theta) -sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1];

Translate = [1 0 0; 0 1 0; 1.65 5.32 1];

Translate*Trotate

Trotate*Translate

3) Take a look at the example for imregtform. It uses imwarp to apply a given affine transformation matrix and then demonstrates how this transformation can be recovered, effectively doing exactly what your code is trying to do.

With the subscripting you are doing along with your transformation operations, it's not immediately obvious to me what the effective affine transformation matrix that you are applying to your input image is, so I'm not sure what the expected result is. Unfortunately, I don't have time to do this right now.

4) If you want to use imwarp to apply a geometric transformation to an image and reference the output image to the coordinate system of another image, then you will need to use the 'OutputView' option of imwarp to guarantee that the output image is the same size as the fixed image. Again, this is shown in the examples for imregtform.

5) If you want to look at the result that imregtform is giving as a registration and compare it to your implementation, here is the code to do that based on your example:

clear all;close all;clc;

fixedFull = double(imread('cameraman.tif'));

rows = 30:226;

cols = rows;

fixed = fixedFull(rows,cols);

theta = 5;

rowshift = 1.65;

colshift = 5.32;

RT = @(img,colshift,rowshift,theta) imrotate( imtransform(img, maketform('affine', [1 0 0; 0 1 0; colshift rowshift 1]), 'bilinear', 'XData', [1 size(img,2)], 'YData', [1 size(img,1)], 'FillValues', 0),theta,'crop');

movingFull = RT(fixedFull, colshift, rowshift, theta);

moving = movingFull(rows,cols);

figure;

imshowpair(moving,fixed,'montage');

tform1 = imregcorr(moving, fixed, 'rigid');

movingReg = imwarp(moving,tform1,'OutputView',imref2d(size(fixed)));

figure, imshowpair(movingReg,fixed);