No BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Automatic 2d Rigid Body Image Registration

3.7 | 3 ratings Rate this file 57 Downloads (last 30 days) File Size: 112 KB File ID: #19086 Version: 1.0
image thumbnail

Automatic 2d Rigid Body Image Registration


Matthew Sochor (view profile)


06 Mar 2008 (Updated )

Automatic 2d rigid registration using improved MI kernel

| Watch this File

File Information

Rigid body 2-D image co-registration (translation and rotation) is performed using maximization of mutual information.

Function is implemented in c-code and compiled using the Matlab compiler to minimize computation time. Current compilation will only run on a 32-Bit windows machine running 2007b. Matlab compiler is necessary to re-compile for other versions/platforms.

Mutual information joint entropy matrix is computed using the Hanning windowed sinc function as the kernel of interpolation, which is the HPV estimation method [1].

Maximization of the joint entropy matrix is carried out using Powel's Direction set method [2] with original c-code very slightly modified from J.P. Moreau's code[3].
[1] Lu X, et al., Mutual information-based multimodal image registration using a novel joint histogram estimation, Comput Med Imaging Graph (2008), doi:10.1016/j.compmedimag.2007.12.001

[2] Numerical Recipes, The Art of Scientific Computing By W.H. Press, B.P. Flannery, S.A. Teukolsky and W.T. Vetterling, Cambridge University Press, 1986



Automatic Image Registration Using (Normalized) Mutual Information For Users Of Ip Toolbox and Efficient Subpixel Image Registration By Cross Correlation inspired this file.

Required Products Image Processing Toolbox
MATLAB Compiler
MATLAB release MATLAB 7.5 (R2007b)
Other requirements Currently compiled for 32 Bit windows on 2007b. If you have the matlab compiler, you should be able to re-compile for your system as necessary.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
10 Jan 2015 Valéria Souza

Which modification I can make for use on a 64-Bit Windows Machine?

Comment only
04 Sep 2012 John Reinert Nash

Compiling using Matlab Compiler 2012a and MS Visual Studio 2010 on Windows 7 worked well for me with no modifications to the code. Successful registration of two 1000x783 pixel images achieved. Thanks for the useful program!

13 Sep 2010 Jun

Jun (view profile)

Hi, All,
I had the same segment fault problem. But I found after did
the following it worked:
At the bottom of the file, in function void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { },
REMOVE this line:
pTranslate = (double *)mxGetPr(prhs[2]);

We ONLY have 2 input parameters. prhs is the array of pointers to the input mxArrays. The above line read the
third parameter and caused segment faults.

After remove the line, I compiled with Open Watcom 1.9
in Matlab Version 32-bit edition.
It worked nicely.


Comment only
21 Jun 2010 Alex

Alex (view profile)

I have the same problem as Frank on Dec 02 2009. What compiler was originally used with this?

Comment only
03 Mar 2010 Zhen

Zhen (view profile)

My way to fix this code:
1. when input image size<256, error occurs...
you can change 256 in the for loops to nX or nY
2. when image size is too small, registration accuracy gets worse..
when image size is too small. the 256-bin histogram gets less samples. We can use less intensity bins, say, change from uint8 (0-255) to(0-80).

Comment only
02 Dec 2009 Frank

Frank (view profile)

Running Xp 32bit the mex files in the zip does not work (Segmentation violation detected) !
I tried to compile again the .cpp with "mex mi_hpv_2d.cpp" but it seems that lcc compiler is not able to compile it. Does someone already encountered this problem ? Is there any solution, installing visual c++ compiler ? other solutions ?

Thanks a lot !

Comment only
13 Nov 2009 Casey Ta

I found the following two bugs:

In the mi_hpv function. It seems like P_A and P_B should both be created with a size of 256. I was testing some small images and would keep getting seg faults since the second to last for loop would write past the bounds of the array when the image height or width is less than 256.

In mexFunction, the following line is unnecessary and caused exceptions when I was debugging in Visual Studio 2008 since there are only 2 input parameters:
pTranslate = (double *)mxGetPr(prhs[2]);

Also, for the problems noted by Yang Shuo above, replace the first line with the code that comes after the comment, and replace the second line with:
Float = imrotate(Ref, 30, 'bilinear', 'crop');

Comment only
25 Sep 2009 yang shuo

why it gives the result as follows:
??? Error using ==> imread at 315
File "sl_phantom.tif" does not exist.

Error in ==> d_mi_registration at 65
Ref = imread('sl_phantom.tif'); % same as: Ref = uint8(phantom.*255);

14 May 2009 Lee Cooper

Would like to use this since it is probably fast but it seg faults on my machine. Recompiled with mex, still crashes. Using for 1000x1000 images. Maybe this is the problem?

Also, a script cannot begin with a number character.

Comment only
01 May 2008 yanjun cui

File "sl_phantom.tif" does not exist.

Comment only
12 Mar 2008 Matthew Fenty

Installed this program without problem and works fantastically. All of the other co-registration programs out there are nothing compared to this one.

Thanks a bunch

14 Mar 2008

Fixed error when using non-square input. Is now capable of handling any rectangle.

Contact us