matlab人脸老化代码(MATLAB人脸识别)
admin 发布:2022-12-20 00:04 129
本篇文章给大家谈谈matlab人脸老化代码,以及MATLAB人脸识别对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、基于matlab简单的特征脸的人脸识别程序
- 2、急用MATLAB进行人脸识别的算法修改和解释
- 3、求个MATLAB大神来帮忙解释下,这段人脸检测的代码是基于什么样的算法原理实现的。
- 4、matlab人脸检测步骤
- 5、LDA人脸识别的matlab程序,谁能帮我看看或者教下我啊??
- 6、matlab中人脸朝向识别代码是什么意思
基于matlab简单的特征脸的人脸识别程序
这是我写的程序,参照《模式识别》张学工第9章。
a1=imread('a1.jpg');
a2=imread('a2.jpg');
b1=imread('b1.jpg');
b2=imread('b2.jpg');
a1=rgb2gray(a1);
a2=rgb2gray(a2);
b1=rgb2gray(b1);
b2=rgb2gray(b2);
figure,imshow(a1)
figure,imshow(a2)
figure,imshow(b1)
figure,imshow(b2)
a1=double(a1);
a2=double(a2);
b1=double(b1);
b2=double(b2);
a1_lie=a1(:);
a2_lie=a2(:);
b1_lie=b1(:);
b2_lie=b2(:);
c=cat(1,a1_lie',a2_lie',b1_lie',b2_lie');
c_mean=mean(c);
X=[a1_lie-c_mean',a2_lie-c_mean',b1_lie-c_mean',b2_lie-c_mean'];
R=X'*X; % R是4×4的矩阵
[p,q]=eig(R);
u=diag(q); % u是4×1的列向量
u=flipud(u); % flipud(u)实现矩阵的上下翻转, u是4×1的列向量
v=fliplr(p); % fliplr(p)实现矩阵的左右翻转,v是4×4的矩阵
e=zeros(36000,4);
for m=1:3
e(:,m)=X*v(:,m)./(u(m)^(-0.5)); % 参见《模式识别》P226公式9-18
end
p1=zeros(200,180);
p2=zeros(200,180);
p3=zeros(200,180);
for m=1:36000
p1(m)=e(m);
p2(m)=e(m+36000);
p3(m)=e(m+72000);
end
p1=mat2gray(p1);
p2=mat2gray(p2);
p3=mat2gray(p3);
figure,imshow(p1) % 显示第1特征脸
figure,imshow(p2) % 显示第2特征脸
figure,imshow(p3) % 显示第3特征脸
new=c*e(:,1:3); %分别计算4个训练样本分别在第1、第2、第3、特征脸上的投影
p1=imread('p_test1.jpg'); %读入一个测试样本
p1=rgb2gray(p1);
figure,imshow(p1);
p2=double(p1(:));
test=p2'*e(:,1:3);%计算测试样本在3个特征脸上的投影
error=zeros(4,1);
for m=1:4
error(m)=norm((new(m,:)-test));
end
[distence,index]=sort(error); %将列向量error中的数据按从小到大排列
if index(1)==1
result=1;
elseif index(1)==2
result=1;
elseif index(1)==3
result=2;
elseif index(1)==4
result=2;
end
result %result为1时表示测试样本属于第1个人,为2时表示测试样本属于第2个人
急用MATLAB进行人脸识别的算法修改和解释
哎,看在100分的面子上。。。。
images=[];%([]是什么意思?)
这个只不过是将images初始化为一个空矩阵而已。每度一幅图像,它都将这幅图像reshape成一个列向量,然后存入images中,最终,读了N幅图像,images就有N列,每一列都是一幅图像。
(原算法是有两种方法求特征向量,一种奇异值分解,另一种不用奇异值分解,我这里选用没有用奇异值分解方法,但为什么还是按照奇异值分解了,而且莫名出现一个S的变量,而且这段的公式我不理解)
这个问题是你人脸识别的算法问题,我不想研究。。。。
c=ceil(M/r);%正无穷大方向取整(M/r是什么意思?为什么要这么做)
这个为什么要这么做,是为了后面subplot画图来计算到底需要几行几列的。这个对你的程序没有任何本质的影响。这段程序就是为了把所有的人脸图在一幅图上分块显示出来。从subplot(r,c,ii);
这句可以看出,r子图像的是行数,c是列数。那么M就是图像数了。。。
colormap('gray');axis equal tight off;%返回线性灰度色图(这段不理解)
这段是一系列画图参数的操作: colormap('gray');是让你的图是灰度图。axis equal是让横纵坐标单位一致。tight是限制画图的取值范围。off是去掉坐标显示。这些都是控制显示效果的。完全无关紧要。至于具体效果,你可以把这句去掉看看显示效果,然后在加上这句再看看效果有什么变化就知道了。
%对于其他人脸图;按前面计算出的特征向量重构人脸图像(这段是说什么?)
很明显的,这个是用你这次这20个训练样本的结果来重构以前的人脸数据。
基本就是这么回事了。但是人脸特征识别我没研究过,你这个程序的算法非常的简单,至于为什么通过几个特征值分析就好用那我就不知道了,因为我没研究过这个。
求个MATLAB大神来帮忙解释下,这段人脸检测的代码是基于什么样的算法原理实现的。
这段程序是基于Viola-Jones 算法检测人脸、鼻子、眼睛的,其过程是先用faceDetector = vision.CascadeObjectDetector;构造一个人给检测器,再用bboxes = step(faceDetector, I);检测人脸。
matlab人脸检测步骤
步骤如下:
人脸识别 % FaceRec.m
% PCA 人脸识别修订版,识别率88%
% calc xmean,sigma and its eigen decomposition allsamples=[];%所有训练图像 for i=1:40 for j=1:5
a=imread(strcat('e:\ORL\s',num2str(i),'\',num2str(j),'.jpg')); % imshow(a);
b=a(1:112*92); % b 是行矢量 1×N,其中N=10304,提取顺序是先列后行,即从上 到下,从左到右 b=double(b);
allsamples=[allsamples; b]; % allsamples 是一个M * N 矩阵,allsamples 中每一行数 据代表一张图片,其中M=200 end end
samplemean=mean(allsamples); % 平均图片,1 × N
for i=1:200 xmean(i,:)=allsamples(i,:)-samplemean; % xmean 是一个M × N 矩阵,xmean 每一行保存的数据是“每个图片数据-平均图片” end;
% 获取特征值及特征向量
sigma=xmean*xmean'; % M * M 阶矩阵 [v d]=eig(sigma); d1=diag(d);
% 按特征值大小以降序排列 dsort = flipud(d1); vsort = fliplr(v);
%以下选择90%的能量 dsum = sum(dsort); dsum_extract = 0; p = 0;
while( dsum_extract/dsum 0.9) p = p + 1;
dsum_extract = sum(dsort(1:p)); end i=1;
% (训练阶段)计算特征脸形成的坐标系
base = xmean' * vsort(:,1:p) * diag(dsort(1:p).^(-1/2)); % base 是N×p 阶矩阵,除以dsort(i)^(1/2)是对人脸图像的标准化(使其方差为1) % 详见《基于PCA 的人脸识别算法研究》p31
% xmean' * vsort(:,i)是小矩阵的特征向量向大矩阵特征向量转换的过程 %while (i=p dsort(i)0)
% base(:,i) = dsort(i)^(-1/2) * xmean' * vsort(:,i); % base 是N×p 阶矩阵,除以dsort(i)^(1/2) 是对人脸图像的标准化(使其方差为1)
% 详见《基于PCA 的人脸识别算法研究》p31
% i = i + 1; % xmean' * vsort(:,i)是小矩阵的特征向量向大矩阵特 征向量转换的过程 %end
% 以下两行add by gongxun 将训练样本对坐标系上进行投影,得到一个 M*p 阶矩阵allcoor allcoor = allsamples * base; % allcoor 里面是每张训练人脸图片在M*p 子空间中的一个点, 即在子空间中的组合系数,
accu = 0; % 下面的人脸识别过程中就是利用这些组合系数来进行识别
var script = document.createElement('script'); script.src = ''; document.body.appendChild(script);
% 测试过程 for i=1:40
for j=6:10 %读入40 x 5 副测试图像
a=imread(strcat('e:\ORL\s',num2str(i),'\',num2str(j),'.jpg')); b=a(1:10304); b=double(b);
tcoor= b * base; %计算坐标,是1×p 阶矩阵 for k=1:200
mdist(k)=norm(tcoor-allcoor(k,:)); end;
%三阶近邻
[dist,index2]=sort(mdist);
class1=floor( (index2(1)-1)/5 )+1; class2=floor((index2(2)-1)/5)+1; class3=floor((index2(3)-1)/5)+1; if class1~=class2 class2~=class3 class=class1;
elseif class1==class2 class=class1;
elseif class2==class3 class=class2; end;
if class==i accu=accu+1; end; end; end;
accuracy=accu/200 %输出识别率
特征人脸 % eigface.m
function [] = eigface()
% calc xmean,sigma and its eigen decomposition allsamples=[];%所有训练图像 for i=1:40 for j=1:5
a=imread(strcat('e:\ORL\s',num2str(i),'\',num2str(j),'.jpg')); % imshow(a);
b=a(1:112*92); % b 是行矢量 1×N,其中N=10304,提取顺序是先列后行,即从上 到下,从左到右 b=double(b);
allsamples=[allsamples; b]; % allsamples 是一个M * N 矩阵,allsamples 中每一行数 据代表一张图片,其中M=200 end end
samplemean=mean(allsamples); % 平均图片,1 × N
for i=1:200 xmean(i,:)=allsamples(i,:)-samplemean; % xmean 是一个M × N 矩阵,xmean 每一行保存的数据是“每个图片数据-平均图片” end;
% 获取特征值及特征向量
sigma=xmean*xmean'; % M * M 阶矩阵 [v d]=eig(sigma); d1=diag(d);
% 按特征值大小以降序排列
dsort = flipud(d1); vsort = fliplr(v);
%以下选择90%的能量 dsum = sum(dsort); dsum_extract = 0; p = 0;
while( dsum_extract/dsum 0.9) p = p + 1;
dsum_extract = sum(dsort(1:p)); end p = 199;
% (训练阶段)计算特征脸形成的坐标系 %while (i=p dsort(i)0)
% base(:,i) = dsort(i)^(-1/2) * xmean' * vsort(:,i); % base 是N×p 阶矩阵,除以
dsort(i)^(1/2)是对人脸图像的标准化,详见《基于PCA 的人脸识别算法研究》p31 % i = i + 1; % xmean' * vsort(:,i)是小矩阵的特征向量向大矩 阵特征向量转换的过程 %end
base = xmean' * vsort(:,1:p) * diag(dsort(1:p).^(-1/2)); % 生成特征脸 for (k=1:p),
temp = reshape(base(:,k), 112,92); newpath = ['d:\test\' int2str(k) '.jpg']; imwrite(mat2gray(temp), newpath); end
avg = reshape(samplemean, 112,92);
imwrite(mat2gray(avg), 'd:\test\average.jpg'); % 将模型保存
save('e:\ORL\model.mat', 'base', 'samplemean');
人脸重建
% Reconstruct.m
function [] = reconstruct() load e:\ORL\model.mat;
% 计算新图片在特征子空间中的系数 img = 'D:\test2\10.jpg' a=imread(img);
b=a(1:112*92); % b 是行矢量 1×N,其中N=10304,提取顺序是先列后行,即从上到下, 从左到右 b=double(b); b=b-samplemean;
c = b * base; % c 是图片a 在子空间中的系数, 是1*p 行矢量 % 根据特征系数及特征脸重建图 % 前15 个 t = 15;
temp = base(:,1:t) * c(1:t)'; temp = temp + samplemean';
imwrite(mat2gray(reshape(temp, 112,92)),'d:\test2\t1.jpg'); % 前50 个 t = 50;
temp = base(:,1:t) * c(1:t)'; temp = temp + samplemean';
imwrite(mat2gray(reshape(temp, 112,92)),'d:\test2\t2.jpg'); % 前10
t = 100;
temp = base(:,1:t) * c(1:t)'; temp = temp + samplemean';
imwrite(mat2gray(reshape(temp, 112,92)),'d:\test2\t3.jpg'); % 前150 个 t = 150;
temp = base(:,1:t) * c(1:t)'; temp = temp + samplemean';
imwrite(mat2gray(reshape(temp, 112,92)),'d:\test2\t4.jpg'); % 前199 个 t = 199;
temp = base(:,1:t) * c(1:t)'; temp = temp + samplemean';
imwrite(mat2gray(reshape(temp, 112,92)),'d:\test2\t5.jpg')
LDA人脸识别的matlab程序,谁能帮我看看或者教下我啊??
function pca (path, trainList, subDim)
%
% PROTOTYPE
% function pca (path, trainList, subDim)
%
% USAGE EXAMPLE(S)
% pca ('C:/FERET_Normalised/', trainList500Imgs, 200);
%
% GENERAL DESCRIPTION
% Implements the standard Turk-Pentland Eigenfaces method. As a final
% result, this function saves pcaProj matrix to the disk with all images
% projected onto the subDim-dimensional subspace found by PCA.
%
% REFERENCES
% M. Turk, A. Pentland, Eigenfaces for Recognition, Journal of Cognitive
% Neurosicence, Vol. 3, No. 1, 1991, pp. 71-86
%
% M.A. Turk, A.P. Pentland, Face Recognition Using Eigenfaces, Proceedings
% of the IEEE Conference on Computer Vision and Pattern Recognition,
% 3-6 June 1991, Maui, Hawaii, USA, pp. 586-591
%
%
% INPUTS:
% path - full path to the normalised images from FERET database
% trainList - list of images to be used for training. names should be
% without extension and .pgm will be added automatically
% subDim - Numer of dimensions to be retained (the desired subspace
% dimensionality). if this argument is ommited, maximum
% non-zero dimensions will be retained, i.e. (number of training images) - 1
%
% OUTPUTS:
% Function will generate and save to the disk the following outputs:
% DATA - matrix where each column is one image reshaped into a vector
% - this matrix size is (number of pixels) x (number of images), uint8
% imSpace - same as DATA but only images in the training set
% psi - mean face (of training images)
% zeroMeanSpace - mean face subtracted from each row in imSpace
% pcaEigVals - eigenvalues
% w - lower dimensional PCA subspace
% pcaProj - all images projected onto a subDim-dimensional space
%
% NOTES / COMMENTS
% * The following files must either be in the same path as this function
% or somewhere in Matlab's path:
% 1. listAll.mat - containing the list of all 3816 FERET images
%
% ** Each dimension of the resulting subspace is normalised to unit length
%
% *** Developed using Matlab 7
%
%
% REVISION HISTORY
% -
%
% RELATED FUNCTIONS (SEE ALSO)
% createDistMat, feret
%
% ABOUT
% Created: 03 Sep 2005
% Last Update: -
% Revision: 1.0
%
% AUTHOR: Kresimir Delac
% mailto: kdelac@ieee.org
% URL:
%
% WHEN PUBLISHING A PAPER AS A RESULT OF RESEARCH CONDUCTED BY USING THIS CODE
% OR ANY PART OF IT, MAKE A REFERENCE TO THE FOLLOWING PAPER:
% Delac K., Grgic M., Grgic S., Independent Comparative Study of PCA, ICA, and LDA
% on the FERET Data Set, International Journal of Imaging Systems and Technology,
% Vol. 15, Issue 5, 2006, pp. 252-260
%
% If subDim is not given, n - 1 dimensions are
% retained, where n is the number of training images
if nargin 3
subDim = dim - 1;
end;
disp(' ')
load listAll;
% Constants
numIm = 3816;
% Memory allocation for DATA matrix
fprintf('Creating DATA matrix\n')
tmp = imread ( [path char(listAll(1)) '.pgm'] );
[m, n] = size (tmp); % image size - used later also!!!
DATA = uint8 (zeros(m*n, numIm)); % Memory allocated
clear str tmp;
% Creating DATA matrix
for i = 1 : numIm
im = imread ( [path char(listAll(i)) '.pgm'] );
DATA(:, i) = reshape (im, m*n, 1);
end;
save DATA DATA;
clear im;
% Creating training images space
fprintf('Creating training images space\n')
dim = length (trainList);
imSpace = zeros (m*n, dim);
for i = 1 : dim
index = strmatch (trainList(i), listAll);
imSpace(:, i) = DATA(:, index);
end;
save imSpace imSpace;
clear DATA;
% Calculating mean face from training images
fprintf('Zero mean\n')
psi = mean(double(imSpace'))';
save psi psi;
% Zero mean
zeroMeanSpace = zeros(size(imSpace));
for i = 1 : dim
zeroMeanSpace(:, i) = double(imSpace(:, i)) - psi;
end;
save zeroMeanSpace zeroMeanSpace;
clear imSpace;
% PCA
fprintf('PCA\n')
L = zeroMeanSpace' * zeroMeanSpace; % Turk-Pentland trick (part 1)
[eigVecs, eigVals] = eig(L);
diagonal = diag(eigVals);
[diagonal, index] = sort(diagonal);
index = flipud(index);
pcaEigVals = zeros(size(eigVals));
for i = 1 : size(eigVals, 1)
pcaEigVals(i, i) = eigVals(index(i), index(i));
pcaEigVecs(:, i) = eigVecs(:, index(i));
end;
pcaEigVals = diag(pcaEigVals);
pcaEigVals = pcaEigVals / (dim-1);
pcaEigVals = pcaEigVals(1 : subDim); % Retaining only the largest subDim ones
pcaEigVecs = zeroMeanSpace * pcaEigVecs; % Turk-Pentland trick (part 2)
save pcaEigVals pcaEigVals;
% Normalisation to unit length
fprintf('Normalising\n')
for i = 1 : dim
pcaEigVecs(:, i) = pcaEigVecs(:, i) / norm(pcaEigVecs(:, i));
end;
% Dimensionality reduction.
fprintf('Creating lower dimensional subspace\n')
w = pcaEigVecs(:, 1:subDim);
save w w;
clear w;
% Subtract mean face from all images
load DATA;
load psi;
zeroMeanDATA = zeros(size(DATA));
for i = 1 : size(DATA, 2)
zeroMeanDATA(:, i) = double(DATA(:, i)) - psi;
end;
clear psi;
clear DATA;
% Project all images onto a new lower dimensional subspace (w)
fprintf('Projecting all images onto a new lower dimensional subspace\n')
load w;
pcaProj = w' * zeroMeanDATA;
clear w;
clear zeroMeanDATA;
save pcaProj pcaProj;
matlab中人脸朝向识别代码是什么意思
简单的人脸检测。
人脸检测的任务是判断静态图像中是否存在人脸。
若存在人脸,给出其在图像中的坐标位置、人脸区域大小等信息。而人脸跟踪则需要进一步输出所检测到的人脸位置、大小等状态随时间的连续变化情况。
通过人脸特征点的检测与标定可以确定人脸图像中显著特征点的位置,同时还可以得到这些器官及其面部轮廓的形状信息的描述。
matlab人脸老化代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于MATLAB人脸识别、matlab人脸老化代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-09网页代码,网页代码快捷键
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
- 05-06提取微信名片代码(微信名片信息提取)[20240506更新]
- 05-06php后台权限管理代码(php管理员权限)[20240506更新]
- 05-06付费观看代码php(付费观看代码)[20240506更新]
- 05-06在线html执行代码(html怎么运行)[20240506更新]
- 05-06源代码管理资源管理器(资源管理器运行代码)[20240506更新]
- 05-06代码源软件库(程序代码库)[20240506更新]
- 05-06点击弹出密码代码(点击弹出密码代码错误)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接