-
Notifications
You must be signed in to change notification settings - Fork 5
/
correct_surf.m
124 lines (115 loc) · 3.93 KB
/
correct_surf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
%% PROJECT 1 Analysis and Search of Visual Data - SURF
%% Federico Favia, Mayank Gulati, September 2019
clc
clear all
close all
%% reading image and converting to grayscale
I = imread('data1/obj1_5.jpg');
ref = rgb2gray(I); %grayscale
figure()
imshow(ref);
%% Applying SURF
surf_ref = detectSURFFeatures(ref);
surf_ref = surf_ref.selectStrongest(250); %only 250 (few hundreds) strongest keypoints
hold on
plot(surf_ref);
n_det_ref = surf_ref.Count; %number of detected keypoints on reference image
% %% scaling repeatibility
% m = 1.2; %scale factor
% counter = 0; %numerator of repeatibility (number of matches)
%
% for i = 1:9 %nine scale factors
%
% scale(i) = m.^(i-1);
%
% surf_ref_scaled = scale(i) .* (surf_ref.Location)'; %scale the SURF keypoints of the ref to predict
%
% target = imresize(ref,m.^(i-1)); %scale the reference image
%
% %figure()
% %imshow(target);
%
% surf_tar = detectSURFFeatures(target);
% surf_tar = surf_tar.selectStrongest(250); %only 250 (few hundreds) strongest keypoints
%
% %hold on
% %plot(surf_tar);
%
% n_det_tar = 250; %number of detected keypoints on target
% %hold on
% %plot(surf_ref_scaled(1,:),surf_ref_scaled(2,:),'O');
%
% for j = 1 : n_det_ref
% for k = 1 : n_det_tar
% if (abs(surf_ref_scaled(1,j) - surf_tar.Location(k,1)) <= 2) && (abs(surf_ref_scaled(2,j) - surf_tar.Location(k,2)) <= 2)
% counter = counter + 1;
% break;
% end
% end
% end
%
% repeatibility_scale_surf(i) = counter ./ n_det_ref; %repeatibility formula
% counter = 0; %reset counter of matches
% end
%
% %% plot repeatibility over scaling
% figure1 = figure()
% plot(scale,repeatibility_scale,'-*g');
% title('SURF Repeatibility wrt scales')
% xlabel('Scale')
% ylabel('Repeatibility(scale)')
% saveas(figure1,'surf_repeat_scale.png')
% %% rotation repeatibility
% angle = 15; %rotation angle step (degree)
% counter = 0; %numerator of repeatibility (number of matches)
%
% for i = 1:25 %number of rotations
% theta(i) = (i-1).*angle;
%
% rotation_matrix = [cosd(theta(i)) -sind(theta(i)); sind(theta(i)) cosd(theta(i))]; %rotation matrix
%
% %shift
% surf_ref_shift(1,:) = (surf_ref.Location(:,1))' - size(ref,2)/2;
% surf_ref_shift(2,:) = -( (surf_ref.Location(:,2))' - size(ref,1)/2 );
%
% surf_ref_rotated = rotation_matrix * surf_ref_shift(1:2,:); %rotate the SURF keypoints of the ref to predict
%
% target = imrotate(ref,theta(i),'bicubic'); %rotate the ref image
%
% %shifting back
% surf_ref_rotated(1,:) = surf_ref_rotated(1,:) + size(target,2)/2;
% surf_ref_rotated(2,:) = - (surf_ref_rotated(2,:) - size(target,1)/2 );
%
% %figure()
% %imshow(target);
%
% surf_tar = detectSURFFeatures(target);
% surf_tar = surf_tar.selectStrongest(250); %only 250 (few hundreds) strongest keypoints
%
% %hold on
% %plot(surf_tar);
%
% n_det_tar = 250; %number of detected keypoints on target
% %hold on
% %plot(surf_ref_rotated(1,:),surf_ref_rotated(2,:),'O');
%
% for j = 1 : n_det_ref
% for k = 1 : n_det_tar
% if (abs(surf_ref_rotated(1,j) - surf_tar.Location(k,1)) <= 2) && (abs(surf_ref_rotated(2,j) - surf_tar.Location(k,2)) <= 2)
% counter = counter + 1;
% break;
% end
% end
% end
%
% repeatibility_rotation_surf(i) = counter ./ n_det_tar; %repeatibility formula
% counter = 0; %reset counter of matches
% end
% %
% % %% plot repeatibility over rotation angles
% % figure2 = figure()
% % plot(theta,repeatibility_rotation,'-Oy');
% % title('SURF Repeatibility wrt rotation')
% % xlabel('Theta (deg)')
% % ylabel('Repeatibility(theta)')
% % saveas(figure2,'surf_repeat_rotation.png')