-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiScaleHarris.m
89 lines (70 loc) · 2.35 KB
/
multiScaleHarris.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
function [first_fHM, feature_record] = multiScaleHarris(image)
img_size = size(image);
ROWS = img_size(1);
COLS = img_size(2);
image_gray = rgb2gray(image);
% Use Sobel operator to do derivative
sobel_y = [-1 -2 -1; 0 0 0; 1 2 1];
sobel_x = transpose(sobel_y);
grad_x = [-1 0 1];
grad_y = transpose(grad_x);
sub_image = image_gray;
feature_record = zeros(ROWS,COLS);
first_fHM = zeros(ROWS,COLS);
%% Do multi scale Harris Corner
for lv=1:4
%% Sub image Size & scale
scale = 2^(lv-1);
sub_img_size = size(sub_image);
SUB_ROWS = sub_img_size(1);
SUB_COLS = sub_img_size(2);
%% Gradient of x&y
Ix = filter2(sobel_x, sub_image);
Iy = filter2(sobel_y, sub_image);
%% outer product of gradient for M=[A C; C B]
Ix2 = Ix .* Ix;
Iy2 = Iy .* Iy;
Ixy = Ix .* Iy;
%% apply gaussian filter
sigma = 1.5;
Sx2 = imgaussfilt(Ix2, sigma);
Sy2 = imgaussfilt(Iy2, sigma);
Sxy = imgaussfilt(Ixy, sigma);
%% Compute corner strength: Fhm
for i=1:SUB_ROWS
for j=1:SUB_COLS
M = [Sx2(i,j) Sxy(i,j); Sxy(i,j) Sy2(i,j)];
fHM(i,j) = det(M) ./ trace(M);
end
end
if lv==1
first_fHM = fHM;
end
%% Pick local maxima of 3x3 and above threshold t
window = 1;
t = 10.0; % threshold
for i=1:SUB_ROWS
for j=1:SUB_COLS
% Check each pixel start
if fHM(i,j) > t
picked = 1;
if i-window<1 || i+window > SUB_ROWS || j-window<1 || j+window > SUB_COLS
continue;
end
neighbour3x3 = fHM(i-window:i+window,j-window:j+window);
if max(neighbour3x3(:)) ~= fHM(i,j)
picked = 0;
end
if picked == 1
r = i*scale;
c = j*scale;
feature_record(r,c) = 1;
end
end
% Check each pixel END
end
end
%% image pyramid
sub_image = impyramid(sub_image, 'reduce');
end
end