Time for action – basic approach to panorama stitching

In this example, we will use three photographs taken from the same point in space, just by rotating the camera in the horizontal axis. Let's see the steps needed:

  1. First, as always, we will load and display our images:
    >> L = imread('Left.jpg'),
    >> M = imread('Middle.jpg'),
    >> R = imread('Right.jpg'),
    >> subplot(1,3,1);imshow(L);title('Left image')
    >> subplot(1,3,2);imshow(M);title('Middle image')
    >> subplot(1,3,3);imshow(R);title('Right image')
    Time for action – basic approach to panorama stitching
  2. Now, let's pick two pairs of points that we will use for the connections (remember: we will not use any geometric transformations here). For the selection, we will use the Zoom In and the Data Cursor tools. First we do it for the left and middle image:
    Time for action – basic approach to panorama stitching

    Then, it is time to pick a pair of points for the middle and right image:

    Time for action – basic approach to panorama stitching

    Having pinpointed the two points that will be matched to connect the two images, we now have to move on to stitching.

  3. Let's start with the left and middle images. The point we selected in the left image is on row 693, column 2018. In the middle image, the same point resides on row 674, column 767. This means that the left image should be raised by 693 - 674 = 19 pixels (so that the points are on the same row). We can accomplish this using circshift. This function shifts the elements of a matrix in the dimension stated by the user in a circular fashion; that is, the pixels that fall out of the picture due to the shifting process, re-appear at the other end:
    >> Lr = circshift(L,-19);

    Now, we must connect the two images at the vertical line passing through the common point:

    >> First = cat(2,Lr(:,1:2018,:),M(:,767:end,:));
  4. Now, the resulting image can be combined with the right one, but first, we must perform an alignment like the one in step 3. The point selected in the middle image is at row 587 and column 1767, while in the right image, it resides on row 618, column 466. This means that the right image must be shifted upwards by 618 - 587 = 31 pixels:
    >> Rr = circshift(R,-31);

    Now, we must connect the two images at the vertical line passing through the common point:

    >> All = cat(2,First(:,1:3019,:),Rr(:,466:end,:));
  5. Let's see what we have accomplished:
    >> imshow(All)
    Time for action – basic approach to panorama stitching
  6. A closer look at the result reveals that several things went wrong; some alignments, especially in the connection of the middle image to the right one, appear too distorted. Some experimentation reveals that minor adjustments to the shifting process and the vertical coordinate for the middle-right connection can improve things, but even better results will come, by also performing median filtering:
    >> Rr = circshift(R,-21);
    >> All = cat(2,First(:,1:3019,:),Rr(:,450:end,:));
    >> for i = 1:size(All,3)
    panorama(:,:,i)=medfilt2(All(:,:,i),[5 5]);
    end
    >> figure,imshow(panorama)
    Time for action – basic approach to panorama stitching

What just happened?

In this example, we demonstrated the simplest possible approach to panorama stitching. For acceptable results with minimal effort, this approach is not bad, but the demanding user should look for more complicated methods; combining feature detection with geometrical image transformations. The approach presented here, started with the manual selection of the common points between the images and the usage of their coordinates for aligning and stitching the images. Some refinement of the exact coordinates is commonly needed, as well as some postprocessing filtering step, such as median filtering. The final result still has artefacts, but it is certainly acceptable for such an easy and straightforward process. The blue sky areas that have appeared at the bottom of the image after the shifting commands, can either be blacked out, or cropped to achieve a better result.

Pop quiz – image mixing details

Q1. Which of the following is true?

  1. Using bands four through seven of a lan image, adds information that is not visible to the human eye.
  2. Blending two images using imfuse, results in an image that is very bright.
  3. We can perform masking of a color image, by dot multiplying it with a two-dimensional mask.
  4. HDR images should be constructed using uncompressed images of a higher depth than 8-bits.
  5. The only thing needed for a good panoramic image is to concatenate the images at the correct column.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset