forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectFeature.m
108 lines (96 loc) · 2.91 KB
/
SelectFeature.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
%function [xtt] = SelectFeature(Ipi,thresh,boundary,spacing,winx,winy,Nmax,method)
% Selects feature points on the given image
%
% method= 0 -> old method of thresholding = max(q(:))/10
% method = 1 -> new method of thresholding = 10*mean(q(:))
%
%
%support routine for 'trackdemo.m' (help trackdemo)
%
%
%Contributors to this code include: Stefano Soatto, Jean-Yves Bouguet, Xiaolin Feng,
%Hailin Jin, Paolo Favaro.
%Last updated 5/5/2003.
%
%DISTRIBUTED FREE FOR NON-COMMERCIAL USE
%Copyright (c) MASKS, 2003
function [xtt] = SelectFeature(Ipi)
% Required resolution (for the track, in pixel)
resolution = 0.03;
% Selection window sizes
winx = 1; winy = 1;
% saturation in Q for selection (win=1)
saturation = 7000;
% Tracking window sizes
wintx = 4; winty = 4;
% min spacing between 2 feats (in pixel).
spacing = 5;
% rejected pixels around the screen (selection)
boundary = 5;
% rejected pixels around the screen (tracking)
boundary_t = 1;
% max. selected features in selection
Nmax = 1000;
% Threshold of selection
thresh = 0.05;
% lower level in the pyramid
levelmin = 0;
% higher level in the pyramid
levelmax = 2;
% Thresh of ejection of a point
% through the track
ThreshQ = 0.1;
% Minimum space reserved for the
% feature storage
N_max_feat = 500;
% Set to 1 to take into consideration
% the saturation (used in selection
% and tracking)
method = 0;
[nx, ny] = size(Ipi);
% compute the quality vector to select highly textured regions
q = GridQuality(Ipi,winx,winy);
%compute boundary mask
windboundary = zeros(nx,ny);
windboundary(boundary:nx-boundary+1,boundary:ny-boundary+1) = ...
ones(nx-2*boundary+2,ny-2*boundary+2);
%mask out the boundary
q = q.*windboundary;
% threshold the quality vector
if method,
% maxq = max(max(q(find(q<saturation))));
maxq = min(max(q(:)),saturation*min(winx,winy));
else
maxq = max(max(q));
end;
thq = thresh*maxq;
% select local maxima
Q = (q > thq) & (LocalMax(q));
i = find(Q(:));
% recall that sort sorts in ascending
% order, while we want the descending order
[Y,I] = sort(-q(i));
if (size(Y,1)>Nmax),
Y = Y(1:Nmax);
I = I(1:Nmax);
end;
% determine the columns and rows of each selected point
C = ceil(i(I)/nx);
R = rem(i(I)-1,nx)+1;
CC = C * ones(1,size(C,1));
RR = R * ones(1,size(R,1));
% we need to remove points that are too close to each other
% and therefore could lead to confuse one feature for another
D2 = (CC - CC').^2 + (RR-RR').^2; %% matrix of square distances between features
D2_mod = tril(D2-spacing^2,-1); %% take the lower-triangle
good_features = ~sum(D2_mod'<0); %% if the sum is 0 it is a good feature
indexgood = find(good_features);
featR = R(indexgood);
featC = C(indexgood);
xtt = [featR,featC]';
% here we return the selected points
% is desired, the quality vector could
% also be returned
indxtt = (xtt(2,:)-1)*nx + xtt(1,:);
qxtt = q(indxtt);
return;