summaryrefslogtreecommitdiffstats
path: root/SD-VBS/benchmarks/sift/src/matlab/gaussianss.m
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/benchmarks/sift/src/matlab/gaussianss.m')
-rw-r--r--SD-VBS/benchmarks/sift/src/matlab/gaussianss.m216
1 files changed, 216 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/sift/src/matlab/gaussianss.m b/SD-VBS/benchmarks/sift/src/matlab/gaussianss.m
new file mode 100644
index 0000000..c92383c
--- /dev/null
+++ b/SD-VBS/benchmarks/sift/src/matlab/gaussianss.m
@@ -0,0 +1,216 @@
1function SS = gaussianss(I,sigman,O,S,omin,smin,smax,sigma0)
2% GAUSSIANSS
3% SS = GAUSSIANSS(I,SIGMAN,O,S,OMIN,SMIN,SMAX,SIGMA0) returns the
4% Gaussian scale space of image I. Image I is assumed to be
5% pre-smoothed at level SIGMAN. O,S,OMIN,SMIN,SMAX,SIGMA0 are the
6% parameters of the scale space as explained in PDF:SIFT.USER.SS.
7%
8% See also DIFFSS(), PDF:SIFT.USER.SS.
9
10% History
11% 4-15-2006 Fixed some comments
12
13% AUTORIGHTS
14% Copyright (c) 2006 The Regents of the University of California.
15% All Rights Reserved.
16%
17% Created by Andrea Vedaldi
18% UCLA Vision Lab - Department of Computer Science
19%
20% Permission to use, copy, modify, and distribute this software and its
21% documentation for educational, research and non-profit purposes,
22% without fee, and without a written agreement is hereby granted,
23% provided that the above copyright notice, this paragraph and the
24% following three paragraphs appear in all copies.
25%
26% This software program and documentation are copyrighted by The Regents
27% of the University of California. The software program and
28% documentation are supplied "as is", without any accompanying services
29% from The Regents. The Regents does not warrant that the operation of
30% the program will be uninterrupted or error-free. The end-user
31% understands that the program was developed for research purposes and
32% is advised not to rely exclusively on the program for any reason.
33%
34% This software embodies a method for which the following patent has
35% been issued: "Method and apparatus for identifying scale invariant
36% features in an image and use of same for locating an object in an
37% image," David G. Lowe, US Patent 6,711,293 (March 23,
38% 2004). Provisional application filed March 8, 1999. Asignee: The
39% University of British Columbia.
40%
41% IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
42% FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
43% INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND
44% ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN
45% ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF
46% CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
47% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
48% A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
49% BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE
50% MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
51
52% --------------------------------------------------------------------
53% Check the arguments
54% --------------------------------------------------------------------
55% --------------------------------------------------------------------
56% Do the job
57% --------------------------------------------------------------------
58
59% Scale multiplicative step
60k = 2^(1/S) ;
61
62dsigma0 = sigma0 * sqrt(1 - 1/k^2) ; % Scale step factor
63sigman = 0.5 ; % Nominal smoothing of the image
64
65% Scale space structure
66SS.O = O ;
67SS.S = S ;
68SS.sigma0 = sigma0 ;
69SS.omin = omin ;
70SS.smin = smin ;
71SS.smax = smax ;
72
73% If mino < 0, multiply the size of the image.
74% (The rest of the code is consistent with this.)
75
76
77if omin < 0
78 for o=1:-omin
79 I = doubleSize(I) ;
80 end
81elseif omin > 0
82 for o=1:omin
83 I = halveSize(I) ;
84 end
85end
86
87[M,N] = size(I) ;
88
89% Index offset
90so = -smin+1 ;
91
92% --------------------------------------------------------------------
93% First octave
94% --------------------------------------------------------------------
95%
96% The first level of the first octave has scale index (o,s) =
97% (omin,smin) and scale coordinate
98%
99% sigma(omin,smin) = sigma0 2^omin k^smin
100%
101% The input image I is at nominal scale sigman. Thus in order to get
102% the first level of the pyramid we need to apply a smoothing of
103%
104% sqrt( (sigma0 2^omin k^smin)^2 - sigman^2 ).
105%
106% As we have pre-scaled the image omin octaves (up or down,
107% depending on the sign of omin), we need to correct this value
108% by dividing by 2^omin, getting
109%e
110% sqrt( (sigma0 k^smin)^2 - (sigman/2^omin)^2 )
111%
112
113SS.octave{1} = zeros(M,N,smax-smin+1) ;
114SS.octave{1}(:,:,1) = imsmooth(I, ...
115 sqrt((sigma0*k^smin)^2 - (sigman/2^omin)^2)) ;
116
117temp = sqrt((sigma0*k^smin)^2 - (sigman/2^omin)^2) ;
118
119for s=smin+1:smax
120 % Here we go from (omin,s-1) to (omin,s). The extra smoothing
121 % standard deviation is
122 %
123 % (sigma0 2^omin 2^(s/S) )^2 - (simga0 2^omin 2^(s/S-1/S) )^2
124 %
125 % Aftred dividing by 2^omin (to take into account the fact
126 % that the image has been pre-scaled omin octaves), the
127 % standard deviation of the smoothing kernel is
128 %
129 % dsigma = sigma0 k^s sqrt(1-1/k^2)
130 %
131 dsigma = k^s * dsigma0 ;
132 SS.octave{1}(:,:,s +so) = ...
133 imsmooth(squeeze(...
134 SS.octave{1}(:,:,s-1 +so)...
135 ), dsigma ) ;
136end
137
138% --------------------------------------------------------------------
139% Other octaves
140% --------------------------------------------------------------------
141
142for o=2:O
143 % We need to initialize the first level of octave (o,smin) from
144 % the closest possible level of the previous octave. A level (o,s)
145 % in this octave corrsponds to the level (o-1,s+S) in the previous
146 % octave. In particular, the level (o,smin) correspnds to
147 % (o-1,smin+S). However (o-1,smin+S) might not be among the levels
148 % (o-1,smin), ..., (o-1,smax) that we have previously computed.
149 % The closest pick is
150 %
151 % / smin+S if smin+S <= smax
152 % (o-1,sbest) , sbest = |
153 % \ smax if smin+S > smax
154 %
155 % The amount of extra smoothing we need to apply is then given by
156 %
157 % ( sigma0 2^o 2^(smin/S) )^2 - ( sigma0 2^o 2^(sbest/S - 1) )^2
158 %
159 % As usual, we divide by 2^o to cancel out the effect of the
160 % downsampling and we get
161 %
162 % ( sigma 0 k^smin )^2 - ( sigma0 2^o k^(sbest - S) )^2
163 %
164 sbest = min(smin + S, smax) ;
165 TMP = halveSize(squeeze(SS.octave{o-1}(:,:,sbest+so))) ;
166
167 target_sigma = sigma0 * k^smin ;
168 prev_sigma = sigma0 * k^(sbest - S) ;
169
170 if(target_sigma > prev_sigma)
171 temp = sqrt(target_sigma^2 - prev_sigma^2);
172 TMP = imsmooth(TMP, temp ) ;
173 end
174 [M,N] = size(TMP) ;
175
176 SS.octave{o} = zeros(M,N,smax-smin+1) ;
177 SS.octave{o}(:,:,1) = TMP ;
178
179 for s=smin+1:smax
180 % The other levels are determined as above for the first octave.
181 dsigma = k^s * dsigma0 ;
182 SS.octave{o}(:,:,s +so) = ...
183 imsmooth(squeeze(...
184 SS.octave{o}(:,:,s-1 +so)...
185 ), dsigma) ;
186 end