You are on page 1of 4

Magdalena Mazur

89739015
April 8th, 2008

CS425 Assignment 5 – Object and location recognition


This booklet contains only the first part of the assignment.

% num = match(image1, image2)


%
% This function reads two images and their associated keypoints, and then
% displays lines connecting the keypoints from each image
% (these are correct matches) dependeing on the threshold specified.
% The arguments image1 and image2 are the file names without the file
% extensions.
% It returns the number of matches displayed.
%
% Example: match('scene','book');

function num = match(image1, image2, threshold)

% Load the images and keypoint descriptors and locations


% readkeys returns the arguments [image, descriptors, locVectors]:
%

[im1, des1, loc1] = readkeys(image1);


[im2, des2, loc2] = readkeys(image2);

% Create a new image showing the two images side by side.


im3 = appendimages(im1,im2);

% Show a figure with the joined images and overlaid lines that are
% drawns between the first 5 keypoints in each image (these are just
% random matches)

imshow(im3);
hold on;
num=0;
%set the loop boundaries
v = size(des1);
end1=v(1);
cols1 = size(im1,2);
rows1=size(im1,1);
v1 = size(des2);
e = v1(1);
%for all descriptors in im1 loop here
for i=1:end1

%over all descriptors in im2 loop here, get angle between these descriptors and descriptors in
im1
for j=1:e
dotpr = dot(des1(i,:), des2(j,:));
angles(j) = acos(dotpr);
end

%get the two smallest angles


a = angles';
[Y, I] = sort(a);

smallest = I(1)
second = I(2)
an = angles(smallest)
an2=angles(second)

%if ratio of the two smallest angles below the threshold mark the
%descriptor
if(angles(smallest)/angles(second) <threshold)

line([loc1(i,2) loc2(smallest,2)+cols1], [loc1(i,1) loc2(smallest,1)], 'Color', 'c');


num=num+1;
end
end
The outcomes of various thresholds are presented below:

t=0.85
t=0.75

t=0.5
t=0.6
The best matching was achieved with a threshold choice of 0.6.
Threshold above .75 found many false matches. Therefore for further optimization higher
values of the threshold should be avoided. Especially, since some of the methods (such as
RANSAC) are not feasible for hight percentage of outliers (above 50%). (if using RANSAC, the
matches would be used as 'the model' and false matches would be later on eliminated in
ransac iterations)

You might also like