Assignment 2: Stitching photo mosaics, The goal of the assignment is to automatically stitch images acquired by a panning camera into a mosaic as illustrated in figures 1 and 2 below.
The goal of the assignment is to automatically stitch images acquired by a panning camera into a mosaic as illustrated in figures 1 and 2 below.
Fig.1: Three images acquired by a panning camera. |
Fig.2: Images stitched to a mosaic. |
Algorithm outline:
1. Choose one image as the reference frame.
2. Estimate homography between each of the remaining images and the reference image. To estimate homography between two images use the following procedure:
a. Detect local features in each image.
b. Extract feature descriptor for each feature point.
c. Match feature descriptors between two images.
d. Robustly estimate homography using RANSAC.
3. Wrap each image into the reference frame and composite warped images into a single mosaic.
Complete Matlab Code Stitching photo mosaics: % Read images image1_color = double(imread('a.jpg'))/255; image2_color = double(imread('b.jpg'))/255; image3_color = double(imread('c.jpg'))/255; % Conversaion of Color image to GrayScale image1_gray = rgb2gray(image1_color); image2_gray = rgb2gray(image2_color); image3_gray = rgb2gray(image3_color); % % show images % figure(1); clf; % subplot(1,3,1); imagesc(imargb); axis image; axis off; title('Image a'); % subplot(1,3,2); imagesc(imbrgb); axis image; axis off; title('Image b'); % subplot(1,3,3); imagesc(imcrgb); axis image; axis off; title('Image c'); % Harris Corner points Detector Rthreshold = 500; % Threshold for Harris corners points [Harris_x_image1,Harris_y_image1,strengtha] = harris(image1_gray,Rthreshold); [Harris_x_image2,Harris_y_image2,strengthb] = harris(image2_gray,Rthreshold); [Harris_x_image3,Harris_y_image3,strengthc] = harris(image3_gray,Rthreshold); % Descriptors Extraction [Descriptor_image1,Descriptor_x_image1,Descriptor_y_image1] = ext_desc(image1_gray,Harris_x_image1,Harris_y_image1); [Descriptor_image2,Descriptor_x_image2,Descriptor_y_image2] = ext_desc(image2_gray,Harris_x_image2,Harris_y_image2); [Descriptor_image3,Descriptor_x_image3,Descriptor_y_image3] = ext_desc(image3_gray,Harris_x_image3,Harris_y_image3); % Computation of approximate matches between image1 and image2 by matching local features Distance2 = dist2(Descriptor_image1',Descriptor_image2'); [Weee,Exol1] = sort(Distance2,2); ratior = Weee(:,1)./Weee(:,2); Cope = find(ratior<.8); Exol1 = Exol1(Cope); X_of_image1 = Descriptor_x_image1(Cope); Y_of_image1 = Descriptor_y_image1(Cope); X_of_image2 = Descriptor_x_image2(Exol1); Y_of_image2 = Descriptor_y_image2(Exol1); % Computation of approximate matches between image2 and image3 by matching local features Distance3 = dist2(Descriptor_image3',Descriptor_image2'); [Wee1,Exol1] = sort(Distance3,2); ratior1 = Wee1(:,1)./Wee1(:,2); Cope1 = find(ratior1<.8); Exol1 = Exol1(Cope1); X_of_image11 = Descriptor_x_image3(Cope1); Y_of_image11 = Descriptor_y_image3(Cope1); X_of_image21 = Descriptor_x_image2(Exol1); Y_of_image21 = Descriptor_y_image2(Exol1); % Threshold of inlier image1 and image2 TR = 0.1; [MaD, inliers] = ransacfithomography([X_of_image1; Y_of_image1], [X_of_image2; Y_of_image2], TR); % Threshold of inlier image2 and image3 TR = 0.1; [MaD1, inliers1] = ransacfithomography([X_of_image11; Y_of_image11], [X_of_image21; Y_of_image21], TR); % Combining the image emptybox=[-400 1200 -200 700]; % Image2 is reference frame figure(6); clf; i2 = vgg_warp_H(image2_color, eye(3), 'linear', emptybox); imshow(i2); axis image; % Combining the image 1 to the reference image 2 figure(7); clf; i1 = vgg_warp_H(image1_color, MaD, 'linear', emptybox); imshow(i1); axis image; % Combining the image 3 to the reference image 2 figure(8); clf; i3 = vgg_warp_H(image3_color, MaD1, 'linear', emptybox); imshow(i3); axis image; figure(9); clf; imagesc(double(max(i2,i1))); % (Homography) combining the image1 with image2 in one picture figure(10); clf; imagesc(double(max(i2,i3))); % (Homography) combining the image3 with image2 in one picture % combine the 3 images in one picture figure(11); clf; imagesc(max(i3,double(max(i2,i1)))); axis image; axis off; Download Complete Matlab Code Stitching photo mosaics from my google drive.
If you face any problem while downloading code, send me email.
JawwadJLF@gmail.com |
Reacties
Een reactie posten