File Exchange

image thumbnail


version (2.18 KB) by Nathan Childress
Autoposition automatically registers two images


Updated 02 Sep 2003

View License

AUTOPOSITION automatically registers two images.

[image1 image2] = AUTOPOSITION(image1, image2) will register image1 to image2. Image2 must be smaller in both dimensions than image2. Image1 is cropped to image2's size, and image2 may be cropped if it is found to lie outside of image1. Most of the code is taken from an Image Processing Toolbox demo, but some extra lines have been added for
robustness. Both images must be grayscale images.
[image1 image2 offset] = AUTOPOSITION(image1, image2) returns the offset generated by the normxcorr2 function.

% If you have the IP Toolbox 4.0, you may have to change the TIF
% extenstions to PNG
im1 = imread('bacteria.tif');
im2 = im1(50:170, 100:150);
figure, subplot(2,2,1), imagesc(im1, [0 239]), title('Original')
axis image
subplot(2,2,2), imagesc(im2, [0 239]), axis image, title('Cropped')
[im3 im4 offset] = autoposition(im1, im2);
subplot(2,2,3), imagesc(im3, [0 239]), axis image, title('Aligned')
subplot(2,2,4), imagesc(imsubtract(im4,im3), [-5 5]), axis image, colorbar
title('Difference of registered images');

Cite As

Nathan Childress (2020). Autoposition (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Rob Campbell

Kinor, you're right. You want submission #18401

kinor kinor

the method used is normxcorr2, normalized crosscorrelation

the result can only pjrovide pixel accuracy as there is no further step or am I missing something?

Mike Jung

This is an excellent function you made. I have one question, what type of registration technique does this function use? I looked at the code but I wasn't able to figure that one out. It doesn't look like mutual information. What is it?

jonathan haffarei

good documentation.
Quite precize.(0.1 pixel)
Simple interface.

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!