手動で行うことができます:
img1 = 255-mean(imread('a1.png'),3);
img2 = 255-mean(imread('a2.png'),3);
subplot(221);imagesc(img1);axis image
[x1 y1] = ginput(1);
subplot(222);imagesc(img2);axis image
[x2 y2] = ginput(1);
x = x1-x2;
y = y1-y2;
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)]);
subplot(2,2,[3 4]);
imagesc(max(img1,img2N));axis image
自動的に行うには、これを行うことができます::
%size(img2) <= size(img1)
img1 = 255-mean(imread('a1.png'),3);
img2 = 255-mean(imread('a2.png'),3);
subplot(221);imagesc(img1);axis image
subplot(222);imagesc(img2);axis image
colormap(gray(256))
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)]);
subplot(2,2,[3 4]);
imagesc(max(img1,img2N));axis image