Face Recognize – MATLAB (With Source Code)
As a beginner to MATLAB, I searched a source code for
studying throughout the internet. But I could not find a complete source code
for that. So, this is the source code for you who searching a MATLAB code for
face recognize.
1. Read Face
%%Reading Face & Class of the face
clc;
close
all;
[fname,
path] = uigetfile('.png','Open a Face as input for Training');
fname
= strcat(path,fname);
im
= imread(fname);
imshow(im);
title('Input Face');
c
= input('Enter the
class');
%%Extracting Features & Saving
F = FeatureStatistical(im);
try
load db;
F=[F c];
db=[db; F];
save db.mat db
catch
db = [F c];
save db.mat db
end
2. Extracting Function
%%Creating FeatureStatistical.m
function [F]=FeatureStatistical(im)
im=double(im);
m=mean(im(:));
s=std(im(:));
F=[m s];
end
3. Test Face
%%Reading Face
clc;
close all;
[fname, path] = uigetfile('.png','Provide
a face for testing');
fname = strcat(path,fname);
im = imread(fname);
imshow(im);
title('Test
Face');
%%Finding the class
Ftest = FeatureStatistical(im);
%%Comparing & Output
load db.mat
Ftrain = db(:,1:2);
Ctrain = db(:,3);
for(i=1:size(Ftrain,1))
dist(i,:)=sum(abs(Ftrain(i,:)-Ftest));
end
m = find(dist==min(dist),1);
det_class=Ctrain(m);
msgbox(strcat('Detected
Class=' , num2str(det_class)));
Comments
Post a Comment