-
Notifications
You must be signed in to change notification settings - Fork 0
/
getHarrisKeyPoints.m
80 lines (67 loc) · 1.93 KB
/
getHarrisKeyPoints.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
% Harris detector
% The code calculates
% the Harris Feature Points(FP)
%
% When u execute the code, the test image file opened
% and u have to select by the mouse the region where u
% want to find the Harris points,
% then the code will print out and display the feature
% points in the selected region.
% You can select the number of FPs by changing the variables
% max_N & min_N
% A. Ganoun
frame = imread('D:\workspace\CMP719\HW1\symbench_v1\symbench_v1\cars\01.png');
I =double(frame);
Aj=6;
cmin = Aj;
cmax = size(I, 1);
rmin = Aj;
rmax = size(I, 2);
min_N=10;max_N=50;
%%%%%%%%%%%%%%Intrest Points %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sigma=2; Thrshold=20; r=6; disp=1;
dx = [-1 0 1; -1 0 1; -1 0 1]; % The Mask
dy = dx';
%%%%%%
Ix = conv2(I(cmin:cmax,rmin:rmax), dx, 'same');
Iy = conv2(I(cmin:cmax,rmin:rmax), dy, 'same');
g = fspecial('gaussian',max(1,fix(6*sigma)), sigma); %%%%%% Gaussien Filter
%%%%%
Ix2 = conv2(Ix.^2, g, 'same');
Iy2 = conv2(Iy.^2, g, 'same');
Ixy = conv2(Ix.*Iy, g,'same');
%%%%%%%%%%%%%%
k = 0.04;
R11 = (Ix2.*Iy2 - Ixy.^2) - k*(Ix2 + Iy2).^2;
R11=(1000/max(max(R11)))*R11;
R=R11;
ma=max(max(R));
sze = 2*r+1;
MX = ordfilt2(R,sze^2,ones(sze));
R11 = (R==MX)&(R>Thrshold);
imshow(R11);
count=sum(sum(R11(5:size(R11,1)-5,5:size(R11,2)-5)));
loop=0;
while (((count<min_N)|(count>max_N))&(loop<30))
if count>max_N
Thrshold=Thrshold*1.5;
elseif count < min_N
Thrshold=Thrshold*0.5;
end
R11 = (R==MX)&(R>Thrshold);
count=sum(sum(R11(5:size(R11,1)-5,5:size(R11,2)-5)));
loop=loop+1;
end
R=R*0;
R(5:size(R11,1)-5,5:size(R11,2)-5)=R11(5:size(R11,1)-5,5:size(R11,2)-5);
[r1,c1] = find(R);
PIP=[r1+cmin,c1+rmin]%% IP
%%%%%%%%%%%%%%%%%%%% Display
Size_PI=size(PIP,1);
for r=1: Size_PI
I(PIP(r,1)-2:PIP(r,1)+2,PIP(r,2)-2)=255;
I(PIP(r,1)-2:PIP(r,1)+2,PIP(r,2)+2)=255;
I(PIP(r,1)-2,PIP(r,2)-2:PIP(r,2)+2)=255;
I(PIP(r,1)+2,PIP(r,2)-2:PIP(r,2)+2)=255;
end
figure,imshow(uint8(I));