-
Notifications
You must be signed in to change notification settings - Fork 17
/
DoG_extrema.m
78 lines (69 loc) · 5.08 KB
/
DoG_extrema.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
%
% Developer : Prakriti Chintalapoodi - c.prakriti@gmail.com
%
function extrema = DoG_extrema(top, current, down)
% Function to find the extrema keypoints given 3 matrices
% A pixel is a keypoint if it is the extremum of its 26 neighbors (8 in current, and 9 each in top and bottom)
[sx, sy] = size(current);
% Look for local maxima
% Check the 8 neighbors around the pixel in the same level
local_maxima = (current(2:sx-1,2:sy-1) > current(1:sx-2,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) > current(1:sx-2,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) > current(1:sx-2,3:sy)) & ...
(current(2:sx-1,2:sy-1) > current(2:sx-1,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) > current(2:sx-1,3:sy)) & ...
(current(2:sx-1,2:sy-1) > current(3:sx,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) > current(3:sx,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) > current(3:sx,3:sy)) ;
% Check the 9 neighbors in the level above it
local_maxima = local_maxima & (current(2:sx-1,2:sy-1) > top(1:sx-2,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) > top(1:sx-2,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) > top(1:sx-2,3:sy)) & ...
(current(2:sx-1,2:sy-1) > top(2:sx-1,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) > top(2:sx-1,2:sy-1)) & ... % same pixel in top
(current(2:sx-1,2:sy-1) > top(2:sx-1,3:sy)) & ...
(current(2:sx-1,2:sy-1) > top(3:sx,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) > top(3:sx,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) > top(3:sx,3:sy));
% Check the 9 neighbors in the level below it
local_maxima = local_maxima & (current(2:sx-1,2:sy-1) > down(1:sx-2,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) > down(1:sx-2,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) > down(1:sx-2,3:sy)) & ...
(current(2:sx-1,2:sy-1) > down(2:sx-1,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) > down(2:sx-1,2:sy-1)) & ... % same pixel in down
(current(2:sx-1,2:sy-1) > down(2:sx-1,3:sy)) & ...
(current(2:sx-1,2:sy-1) > down(3:sx,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) > down(3:sx,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) > down(3:sx,3:sy));
% Look for local minima
% Check the 8 neighbors around the pixel in the same level
local_minima = (current(2:sx-1,2:sy-1) < current(1:sx-2,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) < current(1:sx-2,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) < current(1:sx-2,3:sy)) & ...
(current(2:sx-1,2:sy-1) < current(2:sx-1,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) < current(2:sx-1,3:sy)) & ...
(current(2:sx-1,2:sy-1) < current(3:sx,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) < current(3:sx,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) < current(3:sx,3:sy)) ;
% Check the 9 neighbors in the level above it
local_minima = local_minima & (current(2:sx-1,2:sy-1) < top(1:sx-2,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) < top(1:sx-2,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) < top(1:sx-2,3:sy)) & ...
(current(2:sx-1,2:sy-1) < top(2:sx-1,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) < top(2:sx-1,2:sy-1)) & ... % same pixel in top
(current(2:sx-1,2:sy-1) < top(2:sx-1,3:sy)) & ...
(current(2:sx-1,2:sy-1) < top(3:sx,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) < top(3:sx,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) < top(3:sx,3:sy));
% Check the 9 neighbors in the level below it
local_minima = local_minima & (current(2:sx-1,2:sy-1) < down(1:sx-2,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) < down(1:sx-2,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) < down(1:sx-2,3:sy)) & ...
(current(2:sx-1,2:sy-1) < down(2:sx-1,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) < down(2:sx-1,2:sy-1)) & ... % same pixel in down
(current(2:sx-1,2:sy-1) < down(2:sx-1,3:sy)) & ...
(current(2:sx-1,2:sy-1) < down(3:sx,1:sy-2)) & ...
(current(2:sx-1,2:sy-1) < down(3:sx,2:sy-1)) & ...
(current(2:sx-1,2:sy-1) < down(3:sx,3:sy));
extrema = local_maxima | local_minima;
end