⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lda_face_recognition.m

📁 lDA人脸识别,有很高的效率,而且确定可用,希望大家都来看看
💻 M
字号:
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This code is LDA base face recoginition programme. It reads nots(here 6)
% facse from ORL database and the rest (nump-nots) are used as test.
% LDA_Performance shows the recognition performance. 
% 
% If you get out of memory error you may uncomment the comments.
% 
% This code has been written in Fall 2008 by me, Gholamreza Anbarjafari
% (Shahab). You can use this code for any research and academic purposes
% and you may refer to us in your acknowledgement!
% 
% Feel free to contact us for any furthur information:
%  {hasan.demirel, shahab.jafari}@emu.edu.tr
%   http://faraday.ee.emu.edu.tr/shahab
%   http://faraday.ee.emu.edu.tr/hdemirel
%   (c) Demirel and Anbarjafari -2008
% 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
close all
nump=40;             %no_of_classes
nots=6;                %no_of_training_set
D=pwd;
cd([D, '\ORLDatabase']);
[face,MAP]=imread('face1.bmp');
[a,b]=size(face);
% a=75;b=60;
counter=0;
for i=1:nump
    for j=1:nots
        file=['face' int2str((i-1)*10+j) '.bmp'];
        [face,MAP]=imread(file);
        grayface=ind2gray(face,MAP);
%         grayface=imresize(grayface,[75 60]);
        counter=counter+1;
        X(counter,:)=double(reshape(grayface,a*b,1));
    end
end
counter=0;
for i=1:nump
    for j=nots+1:10
        file=['face' int2str((i-1)*10+j) '.bmp'];
        [face,MAP]=imread(file);
        grayface=ind2gray(face,MAP);
%         grayface=imresize(grayface,[75 60]);
        counter=counter+1;
        Y(counter,:)=double(reshape(grayface,a*b,1));
    end
end
cd(D)
% clear memory
x=X';y=Y';
[r,c]=size(x);
tSM=zeros(r,1);
k=1;
for i=1:nots:((nump*nots)-nots+1)
    SM=x(:,i)+x(:,i+1)+x(:,i+2)+x(:,i+3)+x(:,i+4)+x(:,i+5);
    tSM=tSM+SM;
    m(:,k)=SM/nots;
    k=k+1;
end
tm=tSM/(nump*nots);
Sw=zeros(r,r);
for i=1:nump
    C=nots*(i-1)+1;
    for j=C:(C+nots-1)
        SM=(x(:,j)-m(:,i))*(x(:,j)-m(:,i))';
        Sw=Sw+SM;
    end
end
% clear memory
Sb=zeros(r,r);
for i=1:nump
    SM=nots*(m(:,i)-tm)*(m(:,i)-tm)';
    Sb=Sb+SM;
end
clear memory
[V,L]=eig(pinv(Sw)*Sb);
% clear memory
[rr,cc]=size(L)
maxL=min(min(L));
for i=1:rr
    for j=1:cc
        if L(i,j)>maxL
            maxL=L(i,j);
            ii=i;
            jj=j;
        end
    end
end
v=V(:,jj);
Lamda=max(max(L));

for i=1:nump*nots
    new_X(i,:)=v'*x(:,i);
end
% clear memory

for i=1:nump*(10-nots)
    new_Y(i)=v'*y(i,:);
end

counter=0;
for i=1:nump*(10-nots)
    error=[];
    for j=1:nump*nots
        temp=(new_X(:,i)-new_Y(:,j));
        distance=sqrt(temp*temp');
        error=[error distance];
    end
    % clear memory
    Minimum_Error=max(error);
    for k=1:nump*nots
        if error(k)<Minimum_Error
            Minimum_Error=error(k);
            holder=k;
        end
    end
    if ceil(holder/nots)==ceil(i/(10-nots))
        counter=counter+1;
    end
    % clear memory
end
LDA_Performance=(counter/(noc*(10-nots)))*100

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -