-
Notifications
You must be signed in to change notification settings - Fork 1
/
ASL_recognition_sample.m
101 lines (79 loc) · 2.66 KB
/
ASL_recognition_sample.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
% ASL_recognition_sample
% Load database.mat if database does not exist
if ~exist('database','var')
% get 2-D array database
load('database_v1.mat');
end
% Get databaseOpen and databaseClosed
databaseOpen = database{1};
databaseClosed = database{2};
% Get the number of columns in both database
colDatabaseOpen = size(databaseOpen);
colDatabaseOpen = colDatabaseOpen(2);
colDatabaseClosed = size(databaseClosed);
colDatabaseClosed = colDatabaseClosed(2);
% PCA on both database
[coeff1,score1] = pca(double(databaseOpen));
[coeff2,score2] = pca(double(databaseClosed));
Xcentered1 = score1*coeff1';
PCA_DatabaseOpen = score1'*Xcentered1;
Xcentered2 = score2*coeff2';
PCA_DatabaseClosed = score2'*Xcentered2;
%%% Test unknown sample image
unknownSample = fullfile([pwd '\sample_v1'], 'y11.fig');
fprintf(1, '\nIdentifiying unknown sample %s\n', unknownSample);
HandRightState = 1;
imTemp1 = openfig(unknownSample,'invisible');
imTemp2 = findobj(imTemp1,'type','image');
I = imTemp2.CData;
%%% SEGMENT OUT THE HAND
%%Normalize
% Replace depth value 0 to 4000. This eliminates IR shadow
I((I<=0)) = 4000;
% Minus all values in array I by the minimum value of itself
I = I - min(min(I));
%%Segmentation
% Readjust values above 90 to 4000.
I((I>90)) = 4000;
% Check HandRightState to determine which cropping algorithm to use
if HandRightState == 3
Z = cropImage_Closed(I);
else
Z = cropImage_Open(I);
end
figure;imshow(Z, [0 100]);
[irow,icol]=size(Z);
% Reshape a 640-by-480 matrix into a matrix that has only 1 column
Z=reshape(Z,irow*icol,1);
Z=double(Z);
Z=Z-mean(Z);
% Check HandRightState to determine which database to use
if HandRightState == 3
PCA_DatabaseClosedUnknown = score2'*Z;
for i = 1:colDatabaseClosed
difference(i) = sum(abs(PCA_DatabaseClosedUnknown-PCA_DatabaseClosed(:,i)));
end
finalDiff=[];
for i = 1:10:colDatabaseClosed
temp2 = sum(difference(:,i:i+9));
finalDiff = [finalDiff temp2];
end
minDiffPos = find(finalDiff==min(finalDiff));
alphabetList = ['A' 'E' 'M' 'N' 'S' 'T'];
minDiff = finalDiff(:,minDiffPos);
alphabetSign = alphabetList(:,minDiffPos)
else
PCA_DatabaseOpenUnknown = score1'*Z;
for i = 1:colDatabaseOpen
difference(i) = sum(abs(PCA_DatabaseOpenUnknown-PCA_DatabaseOpen(:,i)));
end
finalDiff=[];
for i = 1:10:colDatabaseOpen
temp2 = sum(difference(:,i:i+9));
finalDiff = [finalDiff temp2];
end
minDiffPos = find(finalDiff==min(finalDiff));
alphabetList = ['B':'D' 'E':'I' 'K':'L' 'O':'R' 'U':'Y'];
minDiff = finalDiff(:,minDiffPos);
alphabetSign = alphabetList(:,minDiffPos)
end