Translation Invariant Image Registration using Phase Correlation – Panorama Imaging on MATLAB
Panorama Imaging is one of most specialized techniques in photography. The ratio of this photo is 2:1 or larger in size. Nowadays even modern mobile phones also have the feature of capturing panorama images, specially accelerometer based techniques have made it easier to capture wonderful pieces of images in panoramic way. Unfortunately in my mobile phone camera, even though it has panoramic imaging, it does not have such flexible feature on creating panorama images, therefore what I do is take two pictures and stitch them using MATLAB.
In this article I will share my experience on stitching two images using phase correlation techniques. In this technique I assume that images are not either rotated or scaled with respect to others. With this assumption I can use Translation Invariant Image registration techniques to create the panorama image.
Basic methodology for the process is as follows.
- Applying a Window function to reduce edge effects of both images(I used Hanning Window)
- 2D-FFT of images
- Cross power spectrum of images
- Normalized Cross Correlation by applying the 2D-IFT to the Cross Power Spectrum.
- Detect the peak point.
- Stitch second image from peak location.
- Crop Resulting image to remove the effect from horizontal shift.
In MATLAB the function ‘hanning()’ can used to obtain 1D hanning window, by using the cross product of two hanning windows we can create a 2D hanning window for appliying in input images in prior to 2D-FFT.
hanning1D_row = hanning(image_width); hanning1D_col = hanning(image_height); hanning2D = hanning1D_row*hanning1D_col;
Then the hanning window is multiplied in element-wise with two images for obtaining edge effect reduced images.
image_left_flt = hanning2D.*image_left; image_right_flt = hanning2D.*image_right;
The 2D Fast Fourier Transform is applied to these edge effect reduced images. And they are used to obtain Cross Power Spectrum of images.
FFT_L = fft2(image_left_flt ); FFT_R = fft2(image_right_flt ); IMF = FFT_L*.conj(FFT_R); CPS = IMF./abs(IMF);
Code for this process is as below.
clc; clear all; close all; im01 = imread('image_01.jpg'); im02 = imread('image_02.jpg'); im1 = rgb2gray(im01); im2 = rgb2gray(im02); F1 = fftshift(fft2(im1)); F2 = fftshift(fft2(im2)); [r1 c1 d1] = size(im1); [r2 c2 d2] = size(im2); F = F1.*conj(F2); F = F./abs(F); mag = (ifft2(F)); [X Y] = find((mag == (max(max(mag))))); if im1(1,1)==im2(end-X,end-Y) img = zeros(r2-X+r1,c2-Y+c1,3); img=cast(img,'uint8'); img(1:r2,1:c2,:)=im02; img(r2-X:r2-X+r1-1,c2-Y:c2-Y+c1-1,:)=im01; else img = zeros(X+r2,Y+c2,3); img=cast(img,'uint8'); img(1:r1,1:c1,:)=im01; img(X:X+r2-1,Y:Y+c2-1,:)=im02; end img=cast(img,'uint8'); imshow(img); imout = imcrop(img);
These are the sample images I used.
After processing before perform the cropping operation,
And after cropping.,
Thank you very much for reading.