-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotDescriptor.m
143 lines (102 loc) · 4.18 KB
/
plotDescriptor.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
%plots a particular descriptor, indicating keypoints and orientations
function plotDescriptor = plotDescriptor(descriptor, image, orientationDef, genDescriptor)
clf;
% imagesc(image);
keypointDescriptor = genDescriptor{1};
orientations = orientationDef{1};
%for each keypoints in octave plots the dots
for octave = 1:size(keypointDescriptor, 1)
%for each keypoints layer
for kptLayer = 1:size(keypointDescriptor,2)
[rowKpt colKpt] = find(keypointDescriptor{octave,kptLayer} == 1);
for keypoint = 1:size([rowKpt colKpt],1)
%plots the dot
image = plotDot(image, rowKpt(keypoint), colKpt(keypoint), octave);
end
end
end
imagesc(image);
hold on;
for octave = 1:size(keypointDescriptor, 1)
%for each keypoints layer
for kptLayer = 1:size(keypointDescriptor,2)
[rowKpt colKpt] = find(keypointDescriptor{octave,kptLayer} == 1);
for keypoint = 1:size([rowKpt colKpt],1)
%plot the arrow with orientation and magnitude starting on
%the dot, the length of the line also depends on the
%octave in which the keypoint is located
plotArrow(rowKpt(keypoint), colKpt(keypoint), octave, ...
orientations{octave}{kptLayer}(rowKpt(keypoint),colKpt(keypoint)));
end
end
end
hold off;
function plotArrow = plotArrow(row,col,octave, keypointDetail)
%iterates on all the orientations in a particular keypoint and
%draws them
for orient = 1:size(keypointDetail.bestHist,1)
%get the degree to rotate
degrees = keypointDetail.interpOrien(orient);
radians = (pi/180)*degrees ;
magnitude = keypointDetail.histogram(keypointDetail.bestHist(orient));
%to see better magnitudes, the small ones are thresholded
if(magnitude<6)
magnitude = 6;
end
%proportional to the octave in which it was found
magnitude = magnitude*octave;
relRow = row;
relCol = col;
if(octave==1)
relRow = round(row/2);
relCol = round(col/2);
end
if(octave>2)
relRow = row * (2^(octave-2));
relCol = col * (2^(octave-2));
end
relCol ;
relRow ;
colTo = round(relCol + magnitude*cos(radians));
colTo = colTo - relCol;
rowTo = round(relRow+magnitude*sin(radians));
rowTo = rowTo - relRow;
h = quiver(relCol,relRow,colTo,rowTo, 'Color','w');
adjust_quiver_arrowhead_size(h, 7.0);
end
end
function plotDot = plotDot(image, row, col, octave)
relRow = row;
relCol = col;
if(octave==1)
relRow = round(row/2);
relCol = round(col/2);
end
if(octave>2)
relRow = row * (2^(octave-2));
relCol = col * (2^(octave-2));
end
if(relRow==1)
relRow = 2;
end
if(relCol==1)
relCol = 2;
end
image(relRow,relCol,1) = 255;
image(relRow,relCol,2) = 255;
image(relRow,relCol,3) = 0;
image(relRow-1,relCol-1,1) = 255;
image(relRow-1,relCol-1,2) = 255;
image(relRow-1,relCol-1,3) = 0;
image(relRow+1,relCol+1,1) = 255;
image(relRow+1,relCol+1,2) = 255;
image(relRow+1,relCol+1,3) = 0;
image(relRow-1,relCol+1,1) = 255;
image(relRow-1,relCol+1,2) = 255;
image(relRow-1,relCol+1,3) = 0;
image(relRow+1,relCol-1,1) = 255;
image(relRow+1,relCol-1,2) = 255;
image(relRow+1,relCol-1,3) = 0;
plotDot = image;
end
end