Warning
This page is located in archive. Go to the latest version of this course pages.

Homework 01 - Image Coordinate System, Affine Transformation

Input Data

Find your data in the assignment '00data: Your data' in the submission system; the image daliborka_01.jpg and the set of seven 2D points U2.

daliborka_01.jpg

Task

Make Matlab script hw01.m to do the following.

  1. Load daliborka_01.jpg image into your Matlab workspace and display it. Use subfig.m utility in Tools repository.
    img = imread( 'daliborka_01.jpg' ); % load the image
    subfig(2,2,1); % create a new figure
    image( img ); % display the image, keep axes visible
    axis image % display it with square pixels
  2. Manually acquire the set of seven points in the image corresponding to the tops of the five chimneys and the two towers. The points must be ordered from left to right. Use
    [x,y] = ginput(7)
  3. Store the point coordinates in a 2×7 matrix u. Every point is represented by a column vector of coordinates, i.e. u(:,1) are coordinates of the first point.
  4. In the bitmap image, colorize the pixels that are nearest to the acquired points (use the round function to convert fractional coordinates into integer coordinates). Use the following colors in the following order: red = [255 0 0], green = [0 255 0], blue = [0 0 255], magenta = [255 0 255], cyan = [0 255 255], yellow = [255 255 0], white = [255 255 255] to colorize the respective seven points. The colors are defined by their R, G, B values: color = [R G B]. The order of colors must correspond to the order of points in the matrix u. Store the modified bitmap image as a file 01_daliborka_points.png.
    imwrite(img, '01_daliborka_points.png');
  5. Implement estimation of the affine transformation A (2×3 matrix) from n given points u2 to points u as a function
    A = estimate_A( u2, u ); % u2 and u are 2xn matrices
    1. Perform all possible selections of 3 point correspondences from all n correspondences. Use e.g.
      nchoosek(1:n, 3 )
    2. For each triple compute the affine transformation Ai (exactly).
    3. Compute transfer errors of the particular transformation for every correspondence, i.e., the euclidean distances between points U and points U2 transferred by A. Find the maximum error over the correspondences.
    4. From the all computed transformations Ai select the one A that has the maximum transfer error minimal.
    5. Assume general number of points, though we have only 7 points and 35 possibilities
      n = size(u,2); % number of columns
  6. Display the modified image, the set of points u using the same colors as above, and 100× magnified transfer errors for the best A as red lines.
    % assume we have points in ''u'' and points ''u2'' transferred by ''A'' in ''ux''
    e = 100 * ( ux - u ); % magnified error displacements
    ...
    hold on % to plot over the image
    ...
    plot( u(1,4), u(2,4), 'o', 'linewidth', 2, 'color', 'magenta' ) % the 4-th point 
    plot( [ u(1,4) u(1,4)+e(1,4) ], [ u(2,4) u(2,4)+e(2,4) ], 'r-', 'linewidth', 2 ); % the 4-th error
    ...
    hold off
    (If the errors are too large, it is optional to plot them magnified only 10×, as blue lines).
  7. Export (print) the plot as a pdf file 01_daliborka_errs.pdf. Use fig2pdf.m utility in Tools repository.
    fig2pdf( gcf, '01_daliborka_errs.pdf' )
  8. Store the points and the matrix in a file 01_points.mat.
    save( '01_points.mat', 'u', 'A' )
Example of a points and transfer errors

Upload

Upload an archive containing the following files:

  1. 01_points.mat
  2. 01_daliborka_points.png
  3. 01_daliborka_errs.pdf
  4. estimate_A.m
  5. hw01.m - your Matlab implementation. It makes all required figures, output files and prints.
  6. any other your files required by hw01.m.

Note: All files must be in the same directory. Do not use any subdirectories.

courses/gvg/labs/gvg-2017-hw-01.txt · Last modified: 2018/02/14 15:56 by policmic