-
Notifications
You must be signed in to change notification settings - Fork 0
/
decodeKW1.m
34 lines (26 loc) · 933 Bytes
/
decodeKW1.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
function [bitting, pinPositions] = decodeKW1(mat, bladeBounds)
% find normalized pin positions
pinPositions = zeros(1,5);
for p = 1:length(pinPositions)
pinPositions(p) = round(bladeBounds(1,2) - ((0.247 + 0.15*(p-1)) * (bladeBounds(1,2) - bladeBounds(1,1)) / 1.15));
end
% find mode y value for each pin (-5:+5)
cutDepths = zeros(1,5);
for p = 1:length(pinPositions)
x = pinPositions(p);
roi = mat(bladeBounds(2,2):bladeBounds(2,1)-5, x-5:x+5);
[r,c] = find(roi);
cutDepths(p) = mode(r);
end
% bitting specs
normalizedBittingSpecs = 1 - ([.329, .306, .283, .260, .237, .214, .191] / .335);
% normalized cut depths
normalizedCutDepths = cutDepths / (bladeBounds(2,1) - bladeBounds(2,2));
% calculate bitting code with smallest error
bitting = zeros(1,5);
for p = 1:length(pinPositions)
error = abs(normalizedBittingSpecs - normalizedCutDepths(p));
[m, i] = min(error);
bitting(p) = i;
end
end