Image stitching Using MATLAB, Joining Multiple Images in MATLAB, Without Correlation: MATLAB Image Processing

The Wikipedia definition says, Image stitching is a process of combining multiple images with some or no overlapping fields of view to produce a segmented panorama or high-resolution image. Commonly performed through the use of computer software, most approaches to image stitching require nearly exact overlaps between images and identical exposures to produce seamless results.

This process can also be easily done in MATLAB, as image is also a matrix of integers & what MATLAB do processing on, is a Matrix. So, image stitching is a simple problem of Matrix Manipulation. If you are aware of these manipulations you can easily get to know how to do it.

NOTE: This method will perform image stitching without correlation of the parts to be stitched, so if there is a overlap between the content of the images to be stitched that will distort the image, as it will contain the repetition of the pixels.

So lets take an Image First. Its my favorite image of Himalaya, as seen from a small & beautiful hill station Ranikhet.
The original or Desired Image, which we have to get after Image Stitching
The original or Desired Image, which we have to get after Image Stitching
Now just for the experimentation purpose I have cropped this image in two parts, & will try to stitch those 2 parts (left & right) in order to get the complete panoramic view of Himalaya.

The 2 parts looks like:
(1) Left Part as 1p.jpg in the below MATLAB Codes
Left part of the image to be stitched
Left part of the image to be stitched
(2) Right Part as 1q.jpg in the below MATLAB Codes

Right part of the image to be stitched
Right part of the image to be stitched
Now its time to apply our MATLAB code in order to combine these two images or stitch them to get whatever we wanted it to be.

MATLAB Code, If you wanted to stitch the above two images one over another:

clc
close all
clear all
a= imread('1p.jpg');
%read the left part of the image
b=imread('1q.jpg');  %read the right part of the image
sa= size(a); %get the size of the left image
sb = size(b);%get the size of the left image
b= imresize(b,[sa(1) sa(2)]); %now resize 'b' as per the size of 'a' in order to get perfect sized image
c= [a;b]; % club the image a & b into another new image after making their size same
%note the semicolon in the above line inside bracket
imshow(c) % show the image

The resultant image after applying above MATLAB code is:
The resultant Image After One Over Another image Stiching
The resultant Image After One Over Another image Stitching
NOTE: We have resized image 'b' as per image 'a', you are free to do opposite. This will particularly create visible distortion in the case where there is a large difference in the image size of the combining images.

NOTE: If you want to take image 1p.jpg instead of 1q.jpg to be stitched first, you just need to interchange the variables in the 2nd last line,  that is c= [a;b] to c= [b;a]


MATLAB Code, If you wanted to stitch the above two images sideways:

clc
close all
clear all
a= imread('1p.jpg');
%read the left part of the image
b=imread('1q.jpg');  %read the right part of the image
sa= size(a); %get the size of the left image
sb = size(b);%get the size of the left image
b= imresize(b,[sa(1) sa(2)]); %now resize 'b' as per the size of 'a' in order to get perfect sized image
c= [a b]; % club the image a & b into another new image after making their size same
%note the missing semicolon in the above line inside bracket
imshow(c) % show the image

The resultant image after applying above MATLAB code is:
The stitched version of the above two images Sideways
The stitched version of the above two images Sideways

NOTE: If you want to take image 1p.jpg instead of 1q.jpg to be stitched first, you just need to interchange the variables in the 2nd last line,  that is c= [a b] to c= [b a]


Hope you enjoyed the article on Image Stitching Using Matlab. If you want to share your own result, or want to share your own improved code, just comment over the page or just mail me. I will be happy to include that here.

5 comments: