aşağıdaki dosyayı oluşturun
displayFaceGallery(faceGallery,galleryNames)
içine şunları yapıştırın ;
%% Display Face Gallery
%Copyright 2014-2015 The MathWorks, Inc.
function displayFaceGallery(faceGallery,galleryNames)
% displaying all the gallery images
figure
for i = 1:length(faceGallery)
I = cell(1, faceGallery(i).Count);
% concatenate all the images of a person side-by-side
for j = 1:faceGallery(i).Count
image = read(faceGallery(i), j);
% scale images to have same height, maintaining the aspect ratio
scaleFactor = 150/size(image, 1);
image = imresize(image, scaleFactor);
I{j} = image;
end
subplot(length(faceGallery), 1, i);
imshow(cell2mat(I));
title(galleryNames{i}, 'FontWeight', 'normal');
end
annotation('textbox', [0 0.9 1 0.1], 'String', 'Face Gallery', ...
'EdgeColor', 'none', 'FontWeight', 'bold', ...
'FontSize', 12, 'HorizontalAlignment', 'center')
--------------------------
şimdi şu dosyayı oluşturun
SimpleFaceRecognition.m
%% Simple Face Recognition Example
% Copyright 2014-2015 The MathWorks, Inc.
%% Load Image Information from ATT Face Database Directory
faceDatabase = imageSet('FaceDatabaseATT','recursive');
%% Display Montage of First Face
figure;
montage(faceDatabase(1).ImageLocation);
title('Images of Single Face');
%% Display Query Image and Database Side-Side
personToQuery = 1;
galleryImage = read(faceDatabase(personToQuery),1);
figure;
for i=1:size(faceDatabase,2)
imageList(i) = faceDatabase(i).ImageLocation(5);
end
subplot(1,2,1);imshow(galleryImage);
subplot(1,2,2);montage(imageList);
diff = zeros(1,9);
%% Split Database into Training & Test Sets
[training,test] = partition(faceDatabase,[0.8 0.2]);
%% Extract and display Histogram of Oriented Gradient Features for single face
person = 5;
[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');
%% Extract HOG Features for training set
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),j));
trainingLabel{featureCount} = training(i).Description;
featureCount = featureCount + 1;
end
personIndex{i} = training(i).Description;
end
%% Create 40 class classifier using fitcecoc
faceClassifier = fitcecoc(trainingFeatures,trainingLabel);
%% Test Images from Test Set
person = 1;
queryImage = read(test(person),1);
queryFeatures = extractHOGFeatures(queryImage);
personLabel = predict(faceClassifier,queryFeatures);
% Map back to training set to find identity
booleanIndex = strcmp(personLabel, personIndex);
integerIndex = find(booleanIndex);
subplot(1,2,1);imshow(queryImage);title('Query Face');
subplot(1,2,2);imshow(read(training(integerIndex),1));title('Matched Class');
%% Test First 5 People from Test Set
figure;
figureNum = 1;
for person=1:5
for j = 1:test(person).Count
queryImage = read(test(person),j);
queryFeatures = extractHOGFeatures(queryImage);
personLabel = predict(faceClassifier,queryFeatures);
% Map back to training set to find identity
booleanIndex = strcmp(personLabel, personIndex);
integerIndex = find(booleanIndex);
subplot(2,2,figureNum);imshow(imresize(queryImage,3));title('Query Face');
subplot(2,2,figureNum+1);imshow(imresize(read(training(integerIndex),1),3));title('Matched Class');
figureNum = figureNum+2;
end
figure;
figureNum = 1;
end
------------------------
ve son dosya aşağıdaki ad ile oluşturun
SimpleFaceRecognitionMathWorks.m
%% Face Recognition with MathWorks Faces
% Copyright 2014-2015 The MathWorks, Inc.
clear all;
close all;
clc;
%% Read Mathworks Face Gallery
faceGallery = imageSet('MathWorksGallery', 'recursive');
galleryNames = {faceGallery.Description};
displayFaceGallery(faceGallery,galleryNames);
%% Create HoG training features from face gallery
trainingFeatures = zeros(19,10404);
featureCount = 1;
for i=1:size(faceGallery,2)
for j = 1:faceGallery(i).Count
sizeNormalizedImage = imresize(rgb2gray(read(faceGallery(i),j)),[150 150]);
trainingFeatures(featureCount,:) = extractHOGFeatures(sizeNormalizedImage);
trainingLabel{featureCount} = faceGallery(i).Description;
featureCount = featureCount + 1;
end
personIndex{i} = faceGallery(i).Description;
end
%% Create Classifier
faceClassifier = fitcecoc(trainingFeatures,trainingLabel);
%% Read test data
testSet = imageSet('MathWorksTestImages');
figure;
figureNum = 1;
for i= 1: testSet.Count
queryImage = read(testSet,i);
queryFeatures = extractHOGFeatures(rgb2gray(queryImage));
personLabel = predict(faceClassifier,queryFeatures);
booleanIndex = strcmp(personLabel, personIndex);
integerIndex = find(booleanIndex);
subplot(5,2,figureNum);imshow(queryImage);title('Query Face');
subplot(5,2,figureNum+1);imshow(read(faceGallery(integerIndex),1));title('Matched Class');
figureNum = figureNum+2;
end