In short, ECC image alignment algorithm estimates the geometric transformation (warp) between the input and the template
image and it returns the warped input image which must be close to the template one, as it is shown below. The estimated
trasnformation is the one that maximizes the correlation coefficient between the template and the warped input image.
Find please below both Matlab and OpenCV implementations of the ECC algorithm. Note that the code is provided "as is" without any kind of warranty. The use and the redistribution of the code is only permitted for academic purposes.
Update 13-May, 2012:
ECC deals with most of 2D planar transformations, i.e. translation, euclidean, affine, homography. Both versions (Matlab, OpenCV) are compatible with any type of the above transformations.
Download the Matlab code from here.
The current Matlab implementation is also available in Matlab Central.
Example of using ECC for 40 iteration in a single level (no multi-resolution):
>>img=imread('image.pgm');
>>tmplt=imread('template.pgm');
>>result=ecc(img, tmplt, 1, 40, 'homography');
for help type:
>>help ecc
or see the M-file ecc_demo.m.
Note that the real transform between the above images is a homography. Homographies are usually under-estimated using an affine or any other 2d model.
Acknowledgements: Many thanks to Mark Asbach (Fraunhofer IAIS) for his contribution to code refactoring. The algorithm is really fast because of Mark's skills!
Find under my BitBucket account another implementation of the algorithm that runs even faster since Jacobian matrix is computed by block processing! Download the Windows executable file. This version deals with affine and homography transformations.
The executable files have been developed using VC++ 2008 (express edition) and have been tested under WinXP 32bit and Win7 64bit platforms. You need to recompile the files if you are working on other OS.
Example of use:
X:> ecc -t template.pgm -i image.pgm -o warp.ecc -m homography
or run the executable file without arguments to see help and more options.
Note that after the execution, the file warp.ecc and the image warped.png will be written in the disk. The first contains the estimated warp matrix saved in YAML format (see below) and the second is the warped input image.
The warp initialization or the output file should have the following YAML format:
%YAML:1.0
Warp: !!opencv-matrix
rows: 3
cols: 3
dt: f
data: [ 1., 0., 0.,
0., 1., 0.,
0., 0., 1. ]
The above structure defines a 3x3 identity matrix with float values.
Example of calling this function (40 iteration are considered and the warp is initialized by the matrix written
in the file init.txt):
>>[warped_image, warp] = ecc_opencv('image.pgm', 'template.pgm', 'homography', 'init.txt', 40);
You can ignore the last argument (the default value of iterations is 50). To ignore the initialization as well, give as input the zero value, i.e.
>>[warped_image, warp] = ecc_opencv('image.pgm', 'template.pgm', 'homography', 0);
If no initialization file is given, the warp is initialized by the identity transformation (identity matrix).
For help type
>>help ecc_opencv
or see the code of the file.
[2] G. D. Evangelidis E. Z. Psarakis, "Projevtive Image Alignment by using ECC Maximization", in Proc. Int. Conf. on Computer Vision Theory and Applications (VISSAP), January 2008, Madeira, Portugal. (pdf)