-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetLocalExtrema.m
62 lines (59 loc) · 2.38 KB
/
getLocalExtrema.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
function locsDoG = getLocalExtrema(DoGPyramid, DoGLevels, ...
PrincipalCurvature, th_contrast, th_r)
%%Detecting Extrema
% INPUTS
% DoG Pyramid - size (size(im), numel(levels) - 1) matrix of the DoG pyramid
% DoG Levels - The levels of the pyramid where the blur at each level is
% outputs
% PrincipalCurvature - size (size(im), numel(levels) - 1) matrix contains the
% curvature ratio R
% th_contrast - remove any point that is a local extremum but does not have a
% DoG response magnitude above this threshold
% th_r - remove any edge-like points that have too large a principal
% curvature ratio
%
% OUTPUTS
% locsDoG - N x 3 matrix where the DoG pyramid achieves a local extrema in both
% scale and space, and also satisfies the two thresholds.
[R,C,L] = size(DoGPyramid);
locsDoG = zeros(0,3);
for i=1:R
for j=1:C
for k=1:L
isExtrema = 1;
if PrincipalCurvature(i,j,k)<th_r && PrincipalCurvature(i,j,k)>0 && abs(DoGPyramid(i,j,k))>th_contrast
localmax = max(max(DoGPyramid(max(i-1,1):min(i+1,R),max(j-1,1):min(j+1,C),k)));
localmin = min(min(DoGPyramid(max(i-1,1):min(i+1,R),max(j-1,1):min(j+1,C),k)));
if DoGPyramid(i,j,k)~=localmax && DoGPyramid(i,j,k)~=localmin
continue
end
if k>1
if DoGPyramid(i,j,k)==localmin
if DoGPyramid(i,j,k)>DoGPyramid(i,j,k-1)
isExtrema = 0;
end
else
if DoGPyramid(i,j,k)<DoGPyramid(i,j,k-1)
isExtrema = 0;
end
end
end
if k<L
if DoGPyramid(i,j,k)==localmin
if DoGPyramid(i,j,k)>DoGPyramid(i,j,k+1)
isExtrema = 0;
end
else
if DoGPyramid(i,j,k)<DoGPyramid(i,j,k+1)
isExtrema = 0;
end
end
end
if isExtrema
locsDoG = [locsDoG;j i DoGLevels(k)];
end
end
end
end
end
end