CS1674: Homework 6 - Programming

Due: 3/15/2018, 11:59pm

This assignment is worth 40 points.

In this exercise, you will compute an image homography, from matching points between two images. Using this homography, you can tell where points from the first image appear in the second image. You can also compute a warp between the two images, stitching the two images into the same canvas.

You are required to write and submit the following:
  1. [10 pts] Function H = estimate_homography(PA, PB) to compute a homography between the points from the first image (in matrix PA) and second image (in matrix PB). Inputs: PA and PB are 4x2 matrices; each row contains the (x, y) coordinates of matching points (a row in the first matrix should be the match for a row in the second matrix). Output: H is a 3x3 matrix. You need to set up a system of equations A as shown in slide 30 here. Once you set up your system A, solve for H using: [~, ~, V] = svd(A); h = V(:, end); H = reshape(h, 3, 3)';.

  2. [5 pts] Function [p2] = apply_homography(p1, H) to apply the homography and convert back from homogeneous coordinates, as shown in slide 32.

  3. [25 pts] Script titled mosaic.m where you load images, select matching points, compute a homography, apply it to a new point from the first image, and stitch a mosaic from the two images:
    1. [2 pts] Use the following two images: keble1, keble2. Load them into Matlab and show them in separate figures, followed by the command impixelinfo after each figure. This will allow you to see pixel coordinates at the bottom of the figures, when you hover over the images.
    2. [3 pts] Examine the images, and determine at least four pairs of points (in each pair, one point should be from the first image, and one from the second image) that are distinctive. Write them down in matrix form in the script, with rows being the points and columns being the x and y locations. This will give you the PA, PB to use below.
    3. [2 pts] Use the function H = estimate_homography(PA, PB) you wrote that computes a homography between the points from the first image (in matrix PA) and second image (in matrix PB) that you found in the previous step.
    4. [3 pts] Now pick one new point from the first image, write it down in your script, and use the computed homography to compute where it "lands" in the second image. Use your apply_homography function to do this. Create a 1x2 subplot which shows (1) the first image, with the p1 point selected shown in green, and (2) the second image, with the p2 point computed using the homography, shown in yellow.
    5. Now stitch a mosaic from the two images.
      • [2 pts] Create a new canvas which replicates the size of image2 3 times in the horizontal and 3 times in the vertical direction, and puts image2 in the middle of this canvas.
      • [8 pts] For each pixel at location p1 in image1, apply the estimated homography to determine location p2 where to send the pixel from p1 into the canvas you created. The new location you compute might be negative, which means in indexes the black part of the canvas; you will need to add two values to the first and second component of p2, to convert from image2's coordinate system to the large canvas' coordinate system. The location you computed might be a non-integer so round both the x and y components up and down (using ceil and floor), resulting in up to four locations for each pixel in image1.
      • [2 pts] Add each pixel from image1 to (four locations in) the large canvas.
      • [3 pt] After iterating over all pixels in image1, show the stitched result.

Submission: