This example is converted from old blog : Panoramic Picture Creation which is using the IPD and SIVP that time. It illustrates simple method of panoramic picture creation using sum of absolute differences. It assumes no zooming, rotational variation in 2 images.
Our task is to combine the 2 images above at their overlapping region.
Reading and Showing Images
Download the images above and save them as ‘1.jpg’ and ‘2.jpg’. Read and show them on the same figure.
S1 = imread('1.jpg'); S2 = imread('2.jpg'); subplot(121); imshow(S1); subplot(122); imshow(S2);
Calculate Sum of Absolute Differences (SAD)
Extract the “Red” layer for the SAD calculation, we could also use other layers for this purpose.
S1r = S1(:,:,1); S2r = S2(:,:,1); sz = 50; roi2 = S2r(1:sz,1:sz); [x,y]=size(S2r); for cnt = y:-1:x/2 roi1 = S1r(1:sz,cnt-sz+1:cnt); data(y-cnt+1)=sum(sum(abs(double(roi2)-double(roi1)))); end plot(data); [minval,ind] = min(data); plot(ind,minval,'r*');
Combine The Images At The Minimum Error Region
From the figure above, we will use the minimum error point as the binding point for 2 images.
Sc = S1(1:$,1:y-sz-ind+1,:); Sfinal = [Sc S2]; imshow(Sfinal);