Search
To fulfill this assignment, you need to submit these files (all packed in one .zip file):
.zip
answers.txt
assignment_01.m
matrix_manip.m
compute_letter_mean.m
compute_lr_histogram.m
initial1_mean.png
initial2_mean.png
initials_histograms.png
Use the template of the assignment. When preparing a zip file for the upload system, do not include any directories, the files have to be in the zip file root.
Beware of using for loops! :)
for
You will be provided with a virtual machine that has MATLAB R2016b installed. To complete this lab before the course starts on your own laptop, it is possible to use a MATLAB trial version OR to install Octave, which is a free alternative to MATLAB.
If you have a high-resolution display (like 3000×1800 on 13.3“), the MATLAB toolbar strip could be too small for comfortably working with it. Unfortunately, there is no workaround for Linux yet except to lower your screen resolution, say, to 1920×1080 or similar.
We will be using MATLAB programming language during this course. It is necessary for you to be as familiar with it as possible, since the labs are time limited and the tasks are often challenging. It may happen that you spend more time looking for MATLAB syntax of some function instead of solving the problem itself.
For the case you are not too sure about your MATLAB skills, here are few useful links:
help ops % short help on MATLAB operators and special characters doc sum % documentation for the sum function lookfor transpose % searches for string "transpose" in the documentation
In most of the assignments, there will be a set of simple questions. Answering the questions should help you to solve the assignment. All questions need to be answered correctly to get the points for the assignment.
Fill the correct answers to your answers.txt file.
Example answers.txt (bogus answers only, fill the correct ones):
question1 : gen_zero_matrix question2 : 'x*' # enclose special characters in tick marks, also known as single quotation marks. question3 : '^' # enclose special characters in tick marks, also known as single quotation marks. question4 : [a,d,e] question5 : [b,f]
In the first part of today’s assignment, you will start with some simple matrix manimulation tasks. AVOID THE USE OF ANY LOOPS IN YOUR PROGRAM!
Your goal is to complete a function output = matrix_manip(A, B), where A and B are input matrices and output is a resulting structure containing results of operations described below.
output = matrix_manip(A, B)
A
B
output
To have some data to work with, use matrices A and B from assignment_01.m:
A = [16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1] B = [ 3 4 9 4 3 6 6 2 3 4; 9 2 10 1 4 3 7 1 3 5]
Function should work on general input matrices, not only for above prescribed A and B matrices or matrices with the same dimensions. Dimensions of the input matrices will be always suitable for all of the following tasks.
output.A_transpose
>> output.A_transpose output.A_transpose = 16 5 9 4 2 11 7 14 3 10 6 15 13 8 12 1
output.A_3rd_col
>> output.A_3rd_col output.A_3rd_col = 3 10 6 15
:
output.A_slice
>> output.A_slice output.A_slice = 7 6 12 14 15 1
output.A_gr_inc
>> output.A_gr_inc output.A_gr_inc = 17 2 3 14 1 6 12 11 9 1 10 8 7 13 1 5 15 16 1 1
>
[]
C
output.C
>> output.C output.C = 499 286 390 178 286 383 351 396 390 351 383 296 178 396 296 508
>> output.A_weighted_col_sum output.A_weighted_col_sum = 391
.*
sum()
output.D
>> output.D output.D = -1 0 5 0 -1 2 2 -2 -1 0 3 -4 4 -5 -2 -3 1 -5 -3 -1
repmat
D
>> output.D_select output.D_select = 0 5 0 -2 -4 4 -5 -5
.^2
find
norm
In this part of the assignment, you are supposed to work with a simple input data which contains images of letters. We will use similar data structures later on during the labs. Do the following:
Note: Plotting and displaying of images should be implemented only in assignment_01.m.
data_33rpz_cv01.mat
images
Alphabet
labels
ims = permute(images,[1 2 4 3]); % The images must be ordered by the 4th dimension. montage(ims); colormap gray;
imshow
imagesc
subplot
montage
uint8
letter_mean = compute_letter_mean(letter_char, Alphabet, images, labels)
letter_char
letter_mean
x = sum of pixel values in the left half of image - sum of pixel values in the right half of image
lr_histogram = compute_lr_histogram(letter_char, Alphabet, images, labels, num_bins)
num_bins
lr_histogram
>> compute_lr_histogram('A', Alphabet, images, labels, 10) ans = 1 1 3 6 12 27 24 20 5 1
hist
This is a simple task that demonstrates working with homogeneous planar points and lines.
[1, 1]
[800, 600]
H = [1 0.1 0; 0.1 1 0; 0.004 0.002 1 ];
Example result of this task is shown in figure 1.
Fig. 1: Example intersection
Notes: the Matlab function ginput is suitable for entering the points.
ginput
[u v] = ginput( 4 ); % or x = ginput(4)'; % note that ginput returns row vectors, hence the transpose
Matlab has a powerful debugger. Either put breakpoints everywhere you want, or use the command keyboard in your code to stop processing at the place. Exit the debugging mode:
keyboard
dbquit
You can also start debugging automatically in case of error by turning on
dbstop error
Especially when some user input is needed, it is wise to store intermediate data for later reuse. Following example could be helpful
if( ~exist( 'my_points.mat', 'file' ) ) [x y] = ginput( 7 ); save( 'my_points.mat', 'x', 'y' ); else load( 'my_points.mat' ); end
Vectors are stored as column matrices.
u = [1;2]; X = [1;2;3]; Xmore = [1 2 3; 4 5 6]'; % transpose at the end
Vectors are multiplied by a matrices on the left:
P = [1 0 0 -5; 0 1 0 -6; 0 0 1 1]; % a camera ux_homog = P * [X;1]; % projection
I = eye(3); % 3x3 identity I2 = diag( [1 1 1] ); % same result Z = zeros(3); % 3x3 matrix of zeroes O = ones(3); % 3x3 matrix of ones
X1 = [1;2;3]; X2 = [4;5;6]; d2 = norm(X1-X2); % cannot be used for more vectors d2 = sqrt(sum((X1-X2).^2)); % for matrices with points stored in columns
u1 = [4;5;1]; u2 = [7;8;1]; dot12 = u1' * u2; % apostrophe is the transpose
In addition to standard matrix addition and subtraction, there are some operators working element-by-element.
M1 = [1 2; 3 4; 5 6]; M2 = [7 8; 9 10; 11 12]; % note the sizes A = M1 .* M2; % Hadamard product (multiplication element-by-element; note the dot) B = M1 ./ M2; % Hadamard division (division element-by-element) C = M1 .^ 2; % power element-by-element
numbers = [1 2 sqrt(-3) acos(2) 4 6+3i 7 ]; is_real = imag( numbers ) == 0; % logical array real_only = numbers( is_real );
u1 = [4;5;1]; u2 = [7;8;1]; u12x = cross(u1,u2); % verification of orthogonality by dot product % (remember the recommendations 1 and 2) u12x' * u1 % should be zero u12x' * u2 % should be zero
Let x = r cos(a) and y = r sin(a). Then the angle can be recovered as
a = atan2( y, x );
This function is safe when either of its arguments is zero (but not both), and works for four quadrants.
Let hnd be some axes handle (e.g. gca) or some figure handle (e.g. gcf). The snapshot identical to the (pixel-wise) appearance of the screen is captured as
hnd
gca
gcf
f = getframe( hnd ); img = f.cdata;
Notes: when capturing a sequence, do not forget to call drawnow before capturing. Also be careful not to obscure the captured window by other GUI content, mouse pointer, etc.
drawnow