Homework 05 - Homography


H = u2H( u, u0 )

Create function u2H computing homography from four image matches. Let u be the image coordinates of points in the first image (2×4 matrix) and u0 (2×4 matrix) be the image coordinates of the corresponding points in the second image. Then H is a 3×3 homography matrix, such that

λ_i [u0(:,i);1] = H * [u(:,i);1]

for all i=1:4 and some nonzero λ_i. Matrix H is regular. Return an empty matrix [] if there is no solution.


  1. Implement function u2H. Use the following test data:
    u =  [0 0 1 1;
          0 1 1 0]
    u0 = [1 2 1.5 1;
          1 2 0.5 0]
         % result should be (but verify yourself):
    H =  [1     1     1
         -1     1     1
          1     0     1 ]
  2. Download the reference image and your specific image from the upload system, task 00ID: Your data.
  3. Create manually 10 image matches (point correspondences) between the two images. A simple utility edit_points from the Tools repository can be used (see its help). Store the matches as column vectors in 2×10 matrices u and u0 for your and the reference image, respectively. The i-th correspondence is thus u(:,i) and u0(:,i).
  4. Find the homography (3×3 matrix H) that maps your image to the reference image. Find it as the best homography by optimizing over all 210 quadruplets among the ten matches. Minimize the maximal transfer error (in the domain of points u0) on all image matches. Create function u2h_optim (with arbitrary inputs and outputs) solving this step. The function will be used in the one of the future homeworks.
  5. Store the matches and the homography as 05_homography.mat
    save( '05_homography.mat', 'H', 'u', 'u0', 'point_sel', '-v6' )
  6. Fill the black pixels in your image using the pixels from the reference image and H. Store the corrected bitmap image as 05_corrected.png. Optionally, try some colour normalization of filled-in area (up to one bonus point).
  7. Display both images side by side and draw the image matches to both as crosses with labels (1 to 10) and highlight the four points used for computing the best H. Export as 05_homography.pdf.
Example of 10 point correspondences
Example of the corrected image
Detail (baseline) Detail (w/ colour normalization)

Filling-in the image

The part of reference image is transferred to your image, so we need the transformation of coordinates in the opposite direction.

  1. Generate list of coordinates u of all pixels in your image that are to be filled. These are typically integers.
  2. Transform these coordinates using the homography. Resulting coordinates u0 point to the reference image (typically not integers).
  3. For each pixel i:
    • Look-up the color in the reference image. The easier way is to take the nearest pixel (rounding the coordinates).
      rgb = im0(round(u0(2,i)),round(u0(1,i)),:); % here we take all values (':') along the third dimension
      In general situations, the coordinates should be checked no to be outside the image.
    • Fill the color in your image (using corresponding coordinates u(:,i)).
      im(u(2,i), u(1,i),:) = rgb;


Upload an archive consisting of:

  1. u2H.m
  2. 05_homography.mat
  3. 05_homography.pdf
  4. 05_corrected.png
  5. hw05.m – your Matlab implementation entry point.
  6. any other files required by hw05.m (including data and files from the repository).
courses/gvg/labs/gvg-2017-hw-05.txt · Last modified: 2018/02/14 15:58 by policmic