juchong
juchong

Reputation: 31

Align a Series of Images Together in Matlab

I'm trying to align a series of images together in matlab.

I have a series of images which are very similar to one another. They are slightly offset in either the x or y direction. The images all have 4 crosshairs on each corner of the image to assist with alignment. I'd like to align them such that the entire series lies on top of all four crosshairs. I'd also like to crop out any differences between the files after they have been aligned.

I've been trying to get the alignment working, but I can't seem to figure it out in matlab.

Here are two sample images. [1] [2]

Thanks for all your help!

Upvotes: 1

Views: 2337

Answers (2)

ace_vent
ace_vent

Reputation: 278

Try

%size(img2) <= size(img1) 

img1 = 255-mean(imread('a1.png'),3); 
img2 = 255-mean(imread('a2.png'),3); 

c = normxcorr2(img2,img1); 
[y x] = find(c==max(c(:))); 
y = y-size(img2,1); 
x = x-size(img2,2); 

T = maketform('affine',[1 0 x;0 1 y; 0 0 1]'); 
img2N = imtransform(img2,T,'xdata',[1 size(img1,2)],'ydata',[1 size(img1,1)]); 
imagesc(max(img1,img2N));
axis image 

Upvotes: 0

jpjacobs
jpjacobs

Reputation: 9549

I guess image registration is what you might be looking for.

Upvotes: 1

Related Questions