Skip to content

Commit e1efff9

Browse files
committed
code formatting
1 parent 2af82d9 commit e1efff9

File tree

4 files changed

+6
-99
lines changed

4 files changed

+6
-99
lines changed

CropImages.m

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
name = '1.jpg';
55
s3 = '.pgm';
66
save = strcat(s1,s3);
7-
8-
A = imread(name);
7+
A = imread(name);
98

109
%%computer vision facedetector
1110

MainMenu.m

-33
Original file line numberDiff line numberDiff line change
@@ -29,71 +29,54 @@
2929
end
3030

3131
%%Establishing Training set and test set by dividing the dataset in 8:2
32-
3332
if (choice == 2)
34-
3533
if (~exist('facedatabase','var'))
3634
warndlg('Please generate database first!\n');
3735
else
3836
[training,test] = partition(facedatabase,[0.8 0.2]);
3937
end
40-
4138
end
4239

4340
%%Feature Extraction
44-
4541
if (choice == 3)
4642
if (~exist('facedatabase','var'))
4743
warndlg('Please generate database first!');
4844
%fprintf('Please generate database first!\n');
4945
elseif(~exist('test','var') || ~exist('training','var'))
5046
warndlg('Training the system first!\n');
5147
else
52-
5348
trainingFeatures = zeros(size(training,2)*training(1).Count,4680);
5449
featureCount = 1;
55-
5650
for i=1:size(training,2)
5751
for j= 1:training(i).Count
5852
trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),1));
5953
trainingLabel{featureCount} = training(i).Description ;
6054
featureCount = featureCount +1;
6155
end
6256
personIndex{i}= training(i).Description;
63-
6457
end
6558
end
66-
67-
6859
end
6960

7061
%%Generating Classfier using ecoc machine learning algorithm
7162
if (choice == 4)
72-
7363
if (~exist('facedatabase','var'))
7464
warndlg('Please generate database first!');
75-
7665
elseif(~exist('test','var') || ~exist('training','var'))
7766
warndlg('Training the system first!\n');
78-
7967
elseif(~exist('trainingFeatures','var'))
8068
warndlg('Extract Features before proceding to classifer!');
81-
8269
else
8370
faceClassifier = fitcecoc(trainingFeatures,trainingLabel);
8471
end
85-
8672
end
8773

8874
%% Prediction "Recognition"
89-
9075
if (choice == 5)
9176
if (~exist('facedatabase','var'))
9277
warndlg('Please generate database first!');
93-
9478
elseif(~exist('test','var') || ~exist('training','var'))
9579
warndlg('Training the system first!\n');
96-
9780
elseif(~exist('trainingFeatures','var'))
9881
warndlg('Extract Features before proceding to classifer!');
9982
elseif(~exist('faceClassifier','var'));
@@ -103,36 +86,25 @@
10386
figureNum =1;
10487
for person = 1:5
10588
for j =1:2
106-
10789
queryImage = read(test(person),j);
10890
queryFeatures = extractHOGFeatures(queryImage);
10991
personLabel = predict(faceClassifier,queryFeatures);
110-
11192
booleanIndex = strcmp(personLabel,personIndex);
11293
integerIndex = find(booleanIndex);
11394
subplot(5,4,figureNum);imshow(imresize(queryImage,3));title('QueryImage');
11495
subplot(5,4,figureNum+1);imshow(read(training(integerIndex),1)); title('Match');
11596
figureNum = figureNum+2;
116-
11797
end
118-
119-
12098
end
121-
122-
12399
end
124-
125100
end
126101

127102
%% Reading image from a path and recognising the person from the dataset
128-
129103
if (choice == 6)
130104
if (~exist('facedatabase','var'))
131105
warndlg('Please generate database first!');
132-
133106
elseif(~exist('test','var') || ~exist('training','var'))
134107
warndlg('Training the system first!\n');
135-
136108
elseif(~exist('trainingFeatures','var'))
137109
warndlg('Extract Features before proceding to classifer!');
138110
elseif(~exist('faceClassifier','var'));
@@ -145,19 +117,14 @@
145117
queryImage = imread(filename);
146118
queryFeatures = extractHOGFeatures(queryImage);
147119
personLabel = predict(faceClassifier,queryFeatures);
148-
149-
150120
booleanIndex = strcmp(personLabel,personIndex);
151121
integerIndex = find(booleanIndex);
152122
subplot(1,2,1);imshow(queryImage);title('Query Image');
153123
subplot(1,2,2);imshow(read(training(integerIndex),1));title('Matched');
154-
155124
end
156125
end
157126
end
158127

159-
160-
161128
if (choice == 7)
162129
clear choice choice2
163130
return;

cropdataset.m

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
11

22
%%To Crop the Faces Automatically from a Dataset folder
3-
43
clear all;
54
close all;
65

7-
8-
9-
for i = 1:10
10-
6+
for i = 1:10
117
s1 = int2str(i);
128
s2 = '.jpg';
13-
149
s3 = '.pgm';
1510
s4 = 'dataset/';
16-
1711
s = strcat(s4,s1,s2);
1812
save = strcat(s1,s3);
19-
20-
2113
A = imread(s);
2214

2315
FaceDetector = vision.CascadeObjectDetector();
2416
BBOX = step(FaceDetector, A);
2517

2618
Face=imcrop(A,BBOX);
27-
2819

2920
grayImage = rgb2gray(Face);
3021
J = imresize(grayImage,[112 92]);
3122
imwrite(J,save);
3223

33-
imshow(J);
34-
35-
36-
end
37-
38-
24+
imshow(J);
25+
end

fr_main.m

+2-48
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11

22
%%Loading Database
3-
4-
5-
63
facedatabase = imageSet('data','recursive');
74

8-
9-
10-
115
%%
12-
13-
146
figure;
157
montage(facedatabase(1).ImageLocation);
168
title('Image of Single faces');
179

18-
1910
% persontoquery =1;
2011
%
2112
% galleryImage = read(facedatabase(persontoquery),1);
@@ -30,95 +21,58 @@
3021
% montage(imageset);
3122

3223

33-
3424
%% Dividing the dataset into training set and test set in 8:2
35-
36-
3725
[training,test] = partition(facedatabase,[0.8 0.2]);
3826

39-
40-
4127
%% Extracting Hog Feature for a person
42-
43-
44-
4528
person = 1;
4629
[hogFeature, visualization]= ...
4730
extractHOGFeatures(read(training(person),1));
4831
figure;
4932
subplot(2,1,1);imshow(read(training(person),1));title('Input Face');
5033
subplot(2,1,2);plot(visualization);title('Hog feature');
5134

52-
53-
54-
55-
5635
%% Extracting hog features for all images
57-
58-
5936
trainingFeatures = zeros(size(training,2)*training(1).Count,4680);
6037
featureCount = 1;
61-
6238
for i=1:size(training,2)
6339
for j= 1:training(i).Count
6440
trainingFeatures(featureCount,:) = extractHOGFeatures(read(training(i),1));
6541
trainingLabel{featureCount} = training(i).Description ;
6642
featureCount = featureCount +1;
6743
end
6844
personIndex{i}= training(i).Description;
69-
7045
end
7146

72-
73-
7447
%% Machine learning algorithm ecoc //training classifier
75-
76-
7748
faceClassifier = fitcecoc(trainingFeatures,trainingLabel);
7849

79-
80-
8150
%%
82-
83-
8451
person =1;
8552
queryImage = read(test(person),1);
8653
queryFeatures = extractHOGFeatures(queryImage);
8754
personLabel = predict(faceClassifier,queryFeatures);
8855

89-
9056
booleanIndex = strcmp(personLabel,personIndex);
9157
integerIndex = find(booleanIndex);
9258
subplot(1,2,1);imshow(queryImage);title('Query Image');
9359
subplot(1,2,2);imshow(read(training(integerIndex),1));title('Matched');
9460

95-
96-
97-
98-
99-
10061
%%
10162

10263

10364
figure;
10465
figureNum =1;
10566
for person = 1:5
106-
for j =1:2
107-
67+
for j =1:2
10868
queryImage = read(test(person),j);
10969
queryFeatures = extractHOGFeatures(queryImage);
11070
personLabel = predict(faceClassifier,queryFeatures);
111-
11271
booleanIndex = strcmp(personLabel,personIndex);
11372
integerIndex = find(booleanIndex);
11473
subplot(5,4,figureNum);imshow(imresize(queryImage,3));title('QueryImage');
11574
subplot(5,4,figureNum+1);imshow(read(training(integerIndex),1)); title('Match');
11675
figureNum = figureNum+2;
117-
11876
end
119-
120-
12177
end
122-
123-
124-
%%
78+
%%

0 commit comments

Comments
 (0)