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

📄 facerecog.m

📁 patten regnization source从1-14章能运行
💻 M
字号:
clear all
close all
clc

% 切嚼 捞固瘤狼 肮荐
M=25;

% 康惑狼 眠沥 乞闭(mean)苞 钎霖祈瞒(std)阑 烙狼肺 急琶. 
um=100;
ustd=80;

% 切嚼 捞固瘤 肺爹苞 焊咯林扁 
S=[];    % 切嚼 捞固瘤 历厘 青纺 
figure(1);
for i=1:M
  str=strcat(int2str(i),'.bmp');    % 捞固瘤狼 捞抚阑 父靛绰 巩磊凯 贸府 
  eval('img=imread(str);');
  subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
  imshow(img)
  if i==3
    title('切嚼 倔奔康惑 笼钦','fontsize',12)
  end
  drawnow;
  [irow icol]=size(img); % 捞固瘤狼 凯(rows : N1)苞 青 (columns : N2)阑 掘绰促. 
  temp=reshape(img',irow*icol,1);    % 1瞒盔 氦磐肺 父电促. (N1*N2)x1 
  S=[S temp];    % S 青纺俊 葛滴 楷搬茄促. 搬苞利栏肺 N1*N2xM 青纺捞 等促. 
end

% 蝴苞 硅版俊 狼窍咯 惯积窍绰 俊矾甫 临捞扁 困咯咯
% 汲沥等 乞闭苞 盒魂阑 扁霖栏肺 葛电 捞固瘤甫 沥痹拳茄促. 
for i=1:size(S,2)
  temp=double(S(:,i));
  m=mean(temp);
  st=std(temp);
  S(:,i)=(temp-m)*ustd/st+um;
end

% 沥痹拳等 捞固瘤甫 焊咯霖促. 
figure(2);
for i=1:M
  str=strcat(int2str(i),'.jpg');
  img=reshape(S(:,i),icol,irow);
  img=img';
  eval('imwrite(img,str)'); 
  subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
  imshow(img)
  drawnow;
  if i==3
    title('沥痹拳等 切嚼 倔奔康惑 笼钦','fontsize',12)
  end
end

% 乞闭倔奔 拌魂 
m=mean(S,2);  % 阿 青狼 乞闭 拌魂. 
tmimg=uint8(m); % unsigned 8-bit integer肺 函券窍搁 蔼甸篮 0俊辑 255 荤捞狼 蔼阑 爱绰促. 
img=reshape(tmimg,icol,irow); % N1*N2x1 氦磐阑 N1xN2 青纺肺 犁炼沥茄促. 
img=img'; 
figure(3);
imshow(img);
title('乞闭倔奔','fontsize',12)

% 绊蜡蔼 盒籍阑 困秦辑 捞固瘤 函版 
dbx=[];    % A 青纺 历厘 硅凯
for i=1:M
  temp=double(S(:,i));
  dbx=[dbx temp];
end

%傍盒魂 青纺(Covariance matrix) C=A'A, L=AA'
A=dbx';
L=A*A';
% vv绰 L狼 绊蜡氦磐(eigenvector)  
% dd绰 L=dbx'*dbx 客 C=dbx*dbx'俊 措茄 绊蜡蔼(eigenvalue). 
[vv dd]=eig(L);
% 沥纺窍咯 绊蜡蔼捞 力肺牢 巴阑 力芭 
v=[];
d=[];
for i=1:size(vv,2)
  if(dd(i,i)>1e-4)
    v=[v vv(:,i)];
    d=[d dd(i,i)];
  end
end

%棵覆瞒鉴栏肺 沥纺 
[B index]=sort(d);
ind=zeros(size(index));
dtemp=zeros(size(index));
vtemp=zeros(size(v));
len=length(index);
for i=1:len
   dtemp(i)=B(len+1-i);
   ind(i)=len+1-index(i);
   vtemp(:,ind(i))=v(:,i);
end
d=dtemp;
v=vtemp;

%绊蜡氦磐狼 沥痹拳 
for i=1:size(v,2) %阿 凯俊 措窍咯 
   kk=v(:,i);
   temp=sqrt(sum(kk.^2));
   v(:,i)=v(:,i)./temp;
end

%C青纺狼 绊蜡氦磐甸 
u=[];
for i=1:size(v,2)
   temp=sqrt(d(i));
   u=[u (dbx*v(:,i))./temp];
end

%绊蜡氦磐狼 沥痹拳 
for i=1:size(u,2)
   kk=u(:,i);
   temp=sqrt(sum(kk.^2));
   u(:,i)=u(:,i)./temp;
end

% 绊蜡倔奔 焊咯林扁
figure(4);
for i=1:size(u,2)
  img=reshape(u(:,i),icol,irow);
  img=img';
  img=histeq(img,255);
  subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
  imshow(img)
  drawnow;
  if i==3
    title('绊蜡倔奔','fontsize',12)
  end
end

% 切嚼 倔奔康惑 笼钦俊辑 阿 倔奔狼 啊吝摹甫 拌魂 
omega = [];
for h=1:size(dbx,2)
  WW=[]; 
  for i=1:size(u,2)
    t = u(:,i)'; 
    WeightOfImage = dot(t,dbx(:,h)');
    WW = [WW; WeightOfImage];
  end
  omega = [omega WW];
end

% 货 捞固瘤甫 掘绢客辑
% 涝仿 颇老 屈侥篮 bmp 趣篮 jpg 屈侥 

InputImage = input('牢侥且 倔奔狼 颇老疙苞 犬厘磊甫 涝仿窍技夸 \n','s');
InputImage = imread(strcat('F:\',InputImage));
figure(5)
subplot(1,2,1)
imshow(InputImage); colormap('gray');title('涝仿 康惑','fontsize',18)
InImage=reshape(double(InputImage)',irow*icol,1); 
temp=InImage;
me=mean(temp);
st=std(temp);
temp=(temp-me)*ustd/st+um;
NormImage = temp;
Difference = temp-m;

p = [];
aa=size(u,2);
for i = 1:aa
  pare = dot(NormImage,u(:,i));
  p = [p; pare];
end

ReshapedImage = m + u(:,1:aa)*p; % m篮 乞闭康惑, u绰 绊蜡倔奔
ReshapedImage = reshape(ReshapedImage,icol,irow);
ReshapedImage = ReshapedImage';

%犁备己等 捞固瘤 焊捞扁 
subplot(1,2,2)
imagesc(ReshapedImage); colormap('gray');
title('犁备己 康惑','fontsize',12)

InImWeight = [];
for i=1:size(u,2)
  t = u(:,i)';
  WeightOfInputImage = dot(t,Difference');
  InImWeight = [InImWeight; WeightOfInputImage];
end

ll = 1:M;
figure(68)
subplot(1,2,1)
stem(ll,InImWeight)
title('涝仿倔奔狼 啊吝摹','fontsize',12)

% Euclidean 芭府甫 备茄促. 
e=[];
for i=1:size(omega,2)
  q = omega(:,i);
  DiffWeight = InImWeight-q;
  mag = norm(DiffWeight);
  e = [e mag];
end

kk = 1:size(e,2);
subplot(1,2,2)
stem(kk,e)
title('涝仿康惑俊 措茄 蜡努府叼救 芭府','fontsize',12)

MaximumValue=max(e)  % 弥措 蜡努府叼救 芭府
MinimumValue=min(e)   % 弥家 蜡努府叼救 芭府

⌨️ 快捷键说明

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