Search
The input data can be downloaded from submission system BRUTE: the image daliborka_01.jpg and the set of seven 2D points u2.
daliborka_01.jpg
u2
u
01_daliborka_points.png
A = estimate_A( u2, u )
A
Ai
ux
01_daliborka_errs.pdf
01_points.mat
Please note when there is a matrix required as an output data, we mean matrix implemented as np.array, not as np.matrix or any other types. If you are using different type than np.array, convert your result.
np.array
np.matrix
Implement the solution in a single file hw01.py. The file must contain the estimate_A function, such that it can be imported (by automatic evaluation) as
hw01.py
estimate_A
import hw01 A = hw01.estimate_A( u2, u )
In addition, when run as main python script, it should do the task described above. Use the if __name__ == "__main__" test for separating code that should not run during import.
if __name__ == "__main__"
Upload an archive containing the following files:
Note: All files must be in the same directory. Do not use any subdirectories.
The following packages should be used:
import numpy as np # for matrix computation and linear algebra import matplotlib.pyplot as plt # for drawing and image I/O import scipy.io as sio # for matlab file format output import itertools # for generating all combinations
Image reading/writing as numpy array:
img = plt.imread( 'daliborka_01.jpg' ) # note that img is read-only, so a copy must be made to allow pixel modifications img = img.copy() img[0,0] = [ 255, 255, 255 ] # put white to upper left corner plt.imsave( 'out.png', img )
Showing the image:
plt.imshow( img ) plt.show()
Manual input of 7 points:
u = plt.ginput( 7 )
Draw errors, export graph as pdf:
# ux ... points u2 transformed by A e = 100 * ( ux - u ) # error displacements magnified by 100 fig = plt.figure() # figure handle to be used later fig.clf() plt.imshow( img ) # draw all points (in proper color) and errors ... plt.plot( u[3,0], u[3,1], 'o', color=[1,0,1], fillstyle='none' ) # the 4-th point in magenta color plt.plot( (u[3,0 ],u[3,0]+e[3,0]), (u[3,1],u[3,1]+e[3,1]), 'r-') # the 4-th displacement ... plt.show() fig.savefig( '01_daliborka_errs.pdf' )
Generator of all triplets:
n = u.shape[1] iter = itertools.combinations( range( 0, n ), 3 ) # three of n # iterate all combinations for inx in iter: u_i = u[ :, inx] u_2i = u_2[ :, inx ] # do the processing for a single triplet ...
Save results in MATLAB format:
sio.savemat('01_points.mat', {'u': u, 'A': A})
Implement your solution in a main script hw01.m, in the file estimate_A.m containing the function, and optionally in additional files for needed functions.
hw01.m
estimate_A.m
Image read, display, write:
img = imread( 'daliborka_01.jpg' ); % load the image figure; % create a new figure image( img ); % display the image, keep axes visible axis image % display it with square pixels img(1,1,:) = [255, 255, 255]; % put white to the upper left corner imwrite( img, 'out.png' ); % write the image to a file
[x,y] = ginput(7);
% ux .. points u2 transformed by A 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 fig2pdf( gcf, '01_daliborka_errs.pdf' ) % function provided in 'tools'
Save results in MAT file:
save( '01_points.mat', 'u', 'A' )