-
Notifications
You must be signed in to change notification settings - Fork 3
/
fr_main.m
78 lines (65 loc) · 2.17 KB
/
fr_main.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
%%Loading Database
facedatabase = imageSet('data','recursive');
%%
figure;
montage(facedatabase(1).ImageLocation);
title('Image of Single faces');
% persontoquery =1;
%
% galleryImage = read(facedatabase(persontoquery),1);
% figure;
%
%
%
% for i=1:size(facedatabase,2)
% imageset = read(facedatabase(i),1);
% end
%
% montage(imageset);
%% Dividing the dataset into training set and test set in 8:2
[training,test] = partition(facedatabase,[0.8 0.2]);
%% Extracting Hog Feature for a person
person = 1;
[hogFeature, visualization]= ...
extractHOGFeatures(read(training(person),1));
figure;
subplot(2,1,1);imshow(read(training(person),1));title('Input Face');
subplot(2,1,2);plot(visualization);title('Hog feature');
%% Extracting hog features for all images
trainingFeatures = zeros(size(training,2)*training(1).Count,4680);
featureCount = 1;
for i=1:size(training,2)
for j= 1:training(i).Count
trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),1));
trainingLabel{featureCount} = training(i).Description ;
featureCount = featureCount +1;
end
personIndex{i}= training(i).Description;
end
%% Machine learning algorithm ecoc //training classifier
faceClassifier = fitcecoc(trainingFeatures,trainingLabel);
%%
person =1;
queryImage = read(test(person),1);
queryFeatures = extractHOGFeatures(queryImage);
personLabel = predict(faceClassifier,queryFeatures);
booleanIndex = strcmp(personLabel,personIndex);
integerIndex = find(booleanIndex);
subplot(1,2,1);imshow(queryImage);title('Query Image');
subplot(1,2,2);imshow(read(training(integerIndex),1));title('Matched');
%%
figure;
figureNum =1;
for person = 1:5
for j =1:2
queryImage = read(test(person),j);
queryFeatures = extractHOGFeatures(queryImage);
personLabel = predict(faceClassifier,queryFeatures);
booleanIndex = strcmp(personLabel,personIndex);
integerIndex = find(booleanIndex);
subplot(5,4,figureNum);imshow(imresize(queryImage,3));title('QueryImage');
subplot(5,4,figureNum+1);imshow(read(training(integerIndex),1)); title('Match');
figureNum = figureNum+2;
end
end
%%