What does the output of imregcorr mean?

I am trying to understand the output of imregcorr and could use some help. Below is the code I am working with. I have my own function called RegisterViaReddy that uses the technique explained in the reference of imregcorr to register images that differ in translation and rotation (I wrote my code before imregcorr was released). Unfortunately I cannot post RegisterViaReddy, but I understand its behavior so hopefully its details are not relevant.

Here is the sample code I am working with:

%%Start with a clean workspace
clear all;close all;clc;%#ok
%%Load image
fixedFull = double(imread('cameraman.tif'));
rows = 30:226;
cols = rows;
fixed = fixedFull(rows,cols);
%%Specify motion parameters
theta = 5;%degrees
rowshift = 1.65;%pixels
colshift = 5.32;%pixels
%%Create rotated/translated image
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'); %#ok
movingFull = RT(fixedFull, colshift, rowshift, theta);
moving = movingFull(rows,cols);
%%Show both images
%%Register images
[rowshift1, colshift1, theta1, imgReg] = RegisterViaReddy(fixed, moving);
tform1 = imregcorr(moving, fixed, 'rigid');

The function handle RT first translates an image and then rotates it. The resulting image is the same size as the input image. The outputs of my own RegisterViaReddy function are

>> [rowshift1, colshift1, theta1]ans =     -1.7600   -5.1000  -5.3402

These are nearly the opposites of the known rowshift, colshift, and theta parameters. I wrote my code this way so that


generates something that looks like the fixed image.

I do not understand how to get these parameters from the output of imregcorr (tform1). I understand that acosd(tform1.T(1,1)) is 5.1799 and is hence the rotation angle. However, tform1.T is

0.9959    0.0903         0
-0.0903 0.9959 0
4.1423 -10.3337 1.0000

How do I extract meaningful translation parameters from this? I know I can generate something that looks like the fixed image using

imwarp(moving, tform1);

but the resulting array is 214x214 whereas fixed and moving are 197x197. Is there any way to get the translation offsets that I input from the output of imregcorr?


Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

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:

% Define a pure transformation, apply this transformation to input point (w,z) = (0,0) 
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.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store