/
computeCorners.m
110 lines (96 loc) · 2.72 KB
/
computeCorners.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
109
110
function [cornies, cornyLoc, cornyhands] = computeCorners(anglematrix, boundy, opts)
% COMPUTE CORNERS. Calculates corners from the anglegram matrix. The
% anglegram is shrunk to ensure a better interpretation of the data.
%
% USAGE:
% [cornies, cornyLoc, cornyhands] = computeCorners(anglematrix, boundy, opts)
%
% [cornies, cornyLoc, cornyhands] = computeCorners([], boundy, opts)
%
testag = false;
if isempty(anglematrix)
testag = true;
anglematrix = computeMultiAnglegram(boundy);
end
if nargin < 3
agsize = [64 64];
offst = agsize(1)/2;
statsfname = 'max';
else
[agsize, offst, statsfname] = getoptions(opts);
end
wrapN = @(x, N) (1 + mod(x-1, N));
anglegram = imresize(anglematrix, agsize);
anglegram = anglegram(:,1:offst);
switch lower(statsfname)
case 'max'
statfn = @(x) max(x, [],2);
case 'mean'
statfn = @(x) mean(x, 2);
end
anglesumve = statfn(anglegram);
mam = mean(anglesumve);
stam = std(anglesumve);
[minval, minlocations] = findpeaks(-[anglesumve;anglesumve],...
'MinPeakHeight',-mam+stam);
minval = -minval;
[minval, ic,~] = unique(minval, 'stable');
minlocations = wrapN(minlocations(ic), agsize(1));
cornyLoc = fix((minlocations./64)*size(boundy,1));
cornies = boundy(cornyLoc,:);
cornyhands.anglesumve = anglesumve;
cornyhands.minlocations = minlocations;
cornyhands.minval = minval;
cornyhands.mam = mam;
cornyhands.stam = stam;
if testag == true
cornyhands.anglegram = anglematrix;
end
test = length(cornyhands.minval)>=4 && ...
mean(minval)>=120;
if test == true
fprintf('%s: Suspicious points found. Rearranging corner points..\n',...
mfilename);
cornyhands.allcornies = cornies;
cornyhands.allcornyloc = cornyLoc;
cornies = [];
cornyLoc = [];
end
switch length(cornyLoc)
case 0
cornyhands.guesstype = 'circ';
cornyhands.guesslabel = 1;
case 1
cornyhands.guesstype = 'drop';
cornyhands.guesslabel = 2;
case 2
cornyhands.guesstype = 'bidrop';
cornyhands.guesslabel = 3;
case 3
cornyhands.guesstype = 'tridrop';
cornyhands.guesslabel = 4;
otherwise
cornyhands.guesstype = 'multidrop';
cornyhands.guesslabel = -1;
end
end
function [agsize, offst, statsfname] = getoptions(opts)
%
agsize = [64 64];
offst = agsize(1)/2;
statsfname = 'max';
fnames = fieldnames(opts);
for ix=1:length(fnames)
switch fnames{ix}
case 'agsize'
agsize = opts.(fnames{ix});
case 'offst'
offst = opts.(fnames{ix});
case 'statsfname'
statsfname = opts.(fnames{ix});
otherwise
fprintf('%s: ERROR, option %s not recognised.\n',...
mfilename, upper(fnames{ix}));
end
end
end