diff options
author | leochanj105 <leochanj@live.unc.edu> | 2020-10-19 23:09:30 -0400 |
---|---|---|
committer | leochanj105 <leochanj@live.unc.edu> | 2020-10-20 02:40:39 -0400 |
commit | f618466c25d43f3bae9e40920273bf77de1e1149 (patch) | |
tree | 460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/benchmarks/sift/src/matlab/plotsiftdescriptor.m | |
parent | 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff) |
initial sd-vbs
initial sd-vbs
add sd-vbs
sd-vbs
Diffstat (limited to 'SD-VBS/benchmarks/sift/src/matlab/plotsiftdescriptor.m')
-rw-r--r-- | SD-VBS/benchmarks/sift/src/matlab/plotsiftdescriptor.m | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/sift/src/matlab/plotsiftdescriptor.m b/SD-VBS/benchmarks/sift/src/matlab/plotsiftdescriptor.m new file mode 100644 index 0000000..2f4af50 --- /dev/null +++ b/SD-VBS/benchmarks/sift/src/matlab/plotsiftdescriptor.m | |||
@@ -0,0 +1,169 @@ | |||
1 | function h=plotsiftdescriptor(d,f) | ||
2 | % PLOTSIFTDESCRIPTOR Plot SIFT descriptor | ||
3 | % PLOTSIFTDESCRIPTOR(D) plots the SIFT descriptors D, stored as | ||
4 | % columns of the matrix D. D has the same format used by SIFT(). | ||
5 | % | ||
6 | % PLOTSIFTDESCRIPTOR(D,F) plots the SIFT descriptors warped to the | ||
7 | % SIFT frames F, specified as columns of the matrix F. F has | ||
8 | % the same format used by SIFT(). | ||
9 | % | ||
10 | % H=PLOTSIFTDESCRIPTOR(...) returns the handle H to the line drawing | ||
11 | % representing the descriptors. | ||
12 | % | ||
13 | % REMARK. Currently the function supports only descriptors with 4x4 | ||
14 | % spatial bins and 8 orientation bins (Lowe's default.) | ||
15 | % | ||
16 | % See also PLOTSIFTFRAME(), PLOTMATCHES(), PLOTSS(). | ||
17 | |||
18 | % AUTORIGHTS | ||
19 | % Copyright (c) 2006 The Regents of the University of California. | ||
20 | % All Rights Reserved. | ||
21 | % | ||
22 | % Created by Andrea Vedaldi | ||
23 | % UCLA Vision Lab - Department of Computer Science | ||
24 | % | ||
25 | % Permission to use, copy, modify, and distribute this software and its | ||
26 | % documentation for educational, research and non-profit purposes, | ||
27 | % without fee, and without a written agreement is hereby granted, | ||
28 | % provided that the above copyright notice, this paragraph and the | ||
29 | % following three paragraphs appear in all copies. | ||
30 | % | ||
31 | % This software program and documentation are copyrighted by The Regents | ||
32 | % of the University of California. The software program and | ||
33 | % documentation are supplied "as is", without any accompanying services | ||
34 | % from The Regents. The Regents does not warrant that the operation of | ||
35 | % the program will be uninterrupted or error-free. The end-user | ||
36 | % understands that the program was developed for research purposes and | ||
37 | % is advised not to rely exclusively on the program for any reason. | ||
38 | % | ||
39 | % This software embodies a method for which the following patent has | ||
40 | % been issued: "Method and apparatus for identifying scale invariant | ||
41 | % features in an image and use of same for locating an object in an | ||
42 | % image," David G. Lowe, US Patent 6,711,293 (March 23, | ||
43 | % 2004). Provisional application filed March 8, 1999. Asignee: The | ||
44 | % University of British Columbia. | ||
45 | % | ||
46 | % IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY | ||
47 | % FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, | ||
48 | % INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND | ||
49 | % ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN | ||
50 | % ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF | ||
51 | % CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT | ||
52 | % LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
53 | % A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" | ||
54 | % BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE | ||
55 | % MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | ||
56 | |||
57 | lowe_compatible = 1 ; | ||
58 | |||
59 | % -------------------------------------------------------------------- | ||
60 | % Check the arguments | ||
61 | % -------------------------------------------------------------------- | ||
62 | |||
63 | if(size(d,1) ~= 128) | ||
64 | error('D should be a 128xK matrix (only standard descriptors accepted)') ; | ||
65 | end | ||
66 | |||
67 | if nargin > 1 | ||
68 | if(size(f,1) ~= 4) | ||
69 | error('F should be a 4xK matrix'); | ||
70 | end | ||
71 | |||
72 | if(size(f,2) ~= size(f,2)) | ||
73 | error('D and F must have the same number of columns') ; | ||
74 | end | ||
75 | end | ||
76 | |||
77 | % Descriptors are often non-double numeric arrays | ||
78 | d = double(d) ; | ||
79 | K = size(d,2) ; | ||
80 | if nargin < 2 | ||
81 | f = repmat([0;0;1;0],1,K) ; | ||
82 | end | ||
83 | |||
84 | maginf = 3.0 ; | ||
85 | NBP=4 ; | ||
86 | NBO=8 ; | ||
87 | |||
88 | % -------------------------------------------------------------------- | ||
89 | % Do the job | ||
90 | % -------------------------------------------------------------------- | ||
91 | |||
92 | xall=[] ; | ||
93 | yall=[] ; | ||
94 | |||
95 | for k=1:K | ||
96 | SBP = maginf * f(3,k) ; | ||
97 | th=f(4,k) ; | ||
98 | c=cos(th) ; | ||
99 | s=sin(th) ; | ||
100 | |||
101 | [x,y] = render_descr(d(:,k)) ; | ||
102 | xall = [xall SBP*(c*x-s*y)+f(1,k)] ; | ||
103 | yall = [yall SBP*(s*x+c*y)+f(2,k)] ; | ||
104 | end | ||
105 | |||
106 | h=line(xall,yall) ; | ||
107 | |||
108 | % -------------------------------------------------------------------- | ||
109 | % Helper functions | ||
110 | % -------------------------------------------------------------------- | ||
111 | |||
112 | % Renders a single descriptor | ||
113 | function [x,y] = render_descr( d ) | ||
114 | |||
115 | lowe_compatible=1; | ||
116 | NBP=4 ; | ||
117 | NBO=8 ; | ||
118 | |||
119 | [x,y] = meshgrid(-NBP/2:NBP/2,-NBP/2:NBP/2) ; | ||
120 | |||
121 | % Rescale d so that the biggest peak fits inside the bin diagram | ||
122 | d = 0.4 * d / max(d(:)) ; | ||
123 | |||
124 | % We have NBP*NBP bins to plot. Here are the centers: | ||
125 | xc = x(1:end-1,1:end-1) + 0.5 ; | ||
126 | yc = y(1:end-1,1:end-1) + 0.5 ; | ||
127 | |||
128 | % We swap the order of the bin diagrams because they are stored row | ||
129 | % major into the descriptor (Lowe's convention that we follow.) | ||
130 | xc = xc' ; | ||
131 | yc = yc' ; | ||
132 | |||
133 | % Each bin contains a star with eight tips | ||
134 | xc = repmat(xc(:)',NBO,1) ; | ||
135 | yc = repmat(yc(:)',NBO,1) ; | ||
136 | |||
137 | % Do the stars | ||
138 | th=linspace(0,2*pi,NBO+1) ; | ||
139 | th=th(1:end-1) ; | ||
140 | if lowe_compatible | ||
141 | xd = repmat(cos(-th), 1, NBP*NBP ) ; | ||
142 | yd = repmat(sin(-th), 1, NBP*NBP ) ; | ||
143 | else | ||
144 | xd = repmat(cos(th), 1, NBP*NBP ) ; | ||
145 | yd = repmat(sin(th), 1, NBP*NBP ) ; | ||
146 | end | ||
147 | xd = xd .* d(:)' ; | ||
148 | yd = yd .* d(:)' ; | ||
149 | |||
150 | % Re-arrange in sequential order the lines to draw | ||
151 | nans = NaN * ones(1,NBP^2*NBO) ; | ||
152 | x1 = xc(:)' ; | ||
153 | y1 = yc(:)' ; | ||
154 | x2 = x1 + xd ; | ||
155 | y2 = y1 + yd ; | ||
156 | xstars = [x1;x2;nans] ; | ||
157 | ystars = [y1;y2;nans] ; | ||
158 | |||
159 | % Horizontal lines of the grid | ||
160 | nans = NaN * ones(1,NBP+1); | ||
161 | xh = [x(:,1)' ; x(:,end)' ; nans] ; | ||
162 | yh = [y(:,1)' ; y(:,end)' ; nans] ; | ||
163 | |||
164 | % Verical lines of the grid | ||
165 | xv = [x(1,:) ; x(end,:) ; nans] ; | ||
166 | yv = [y(1,:) ; y(end,:) ; nans] ; | ||
167 | |||
168 | x=[xstars(:)' xh(:)' xv(:)'] ; | ||
169 | y=[ystars(:)' yh(:)' yv(:)'] ; | ||