我是 Matlab 的新手。我正在尝试将 PCA 函数(下面列出的 URL)应用到我的掌纹识别程序中以生成特征手掌。我的掌纹灰度图像尺寸为 450*400。在使用它之前,我试图研究这些代码并添加一些代码以将特征向量保存为 .mat 文件。为了我的自我理解,我添加了一些 %comments。
经过几天的学习,我仍然无法得到答案。我决定寻求帮助。关于这个 PCA.m,我有几个问题要问。
PCA.m
“选项”的输入应该是什么?“PCA(data,details,options)”的(它是一个减少维度的整数吗?我试图弄清楚“options”值在哪里传递,但仍然无法获得答案。“h & h2”的 msgbox “,是检查代码运行到哪里。我试图使用10的整数,但PCA.m处理的尺寸是400 * 400。)
我保存为“.mat”文件的“eigvector”准备好与其他特征向量执行欧几里德距离分类器了吗?(我认为 eigvector 等于 eigenpalm,就像在人脸识别中,特征脸一样。我试图将特征向量矩阵转换回图像,但 PCA 处理后的图像是黑色的,上面有很多点)
我的SVD.m
- 在这个函数中,有两个值可以改变,分别是 MAX_MATRIX_SIZE 设置为 1600 和 EIGVECTOR_RATIO 设置为 0.1%。我可以知道这些值会影响结果吗?(我试图玩弄这些值,但我看不出有什么不同。我的掌纹图像尺寸设置为 450*400,所以 Max_matrix_size 应该设置为 180,000?)
** 我希望你们能够理解我在问什么,请帮助,谢谢你们(=
原版: http: //www.cad.zju.edu.cn/home/dengcai/Data/code/PCA.m
mySVD: http: //www.cad.zju.edu.cn/home/dengcai/Data/code/mySVD.m
% Edited Version by me
function [eigvector, eigvalue] = PCA(data,details,options)
%PCA Principal Component Analysis
%
% Usage:
% [eigvector, eigvalue] = PCA(data, options)
% [eigvector, eigvalue] = PCA(data)
%
% Input:
% data - Data matrix. Each row vector of fea is a data point.
% fea = finite element analysis ?????
% options.ReducedDim - The dimensionality of the reduced subspace. If 0,
% all the dimensions will be kept.
% Default is 0.
%
% Output:
% eigvector - Each column is an embedding function, for a new
% data point (row vector) x, y = x*eigvector
% will be the embedding result of x.
% eigvalue - The sorted eigvalue of PCA eigen-problem.
%
% Examples:
% fea = rand(7,10);
% options=[]; %store an empty matrix in options
% options.ReducedDim=4;
% [eigvector,eigvalue] = PCA(fea,4);
% Y = fea*eigvector;
%
% version 3.0 --Dec/2011
% version 2.2 --Feb/2009
% version 2.1 --June/2007
% version 2.0 --May/2007
% version 1.1 --Feb/2006
% version 1.0 --April/2004
%
% Written by Deng Cai (dengcai AT gmail.com)
%
if (~exist('options','var'))
%A = exist('name','kind')
% var = Checks only for variables.
%http://www.mathworks.com/help/matlab/matlab_prog/symbol-reference.html#bsv2dx9-1
%The tilde "~" character is used in comparing arrays for unequal values,
%finding the logical NOT of an array,
%and as a placeholder for an input or output argument you want to omit from a function call.
options = [];
end
h2 = msgbox('not yet');
ReducedDim = 0;
if isfield(options,'ReducedDim')
%tf = isfield(S, 'fieldname')
h2 = msgbox('checked');
ReducedDim = options.ReducedDim;
end
[nSmp,nFea] = size(data);
if (ReducedDim > nFea) || (ReducedDim <=0)
ReducedDim = nFea;
end
if issparse(data)
data = full(data);
end
sampleMean = mean(data,1);
data = (data - repmat(sampleMean,nSmp,1));
[eigvector, eigvalue] = mySVD(data',ReducedDim);
eigvalue = full(diag(eigvalue)).^2;
if isfield(options,'PCARatio')
sumEig = sum(eigvalue);
sumEig = sumEig*options.PCARatio;
sumNow = 0;
for idx = 1:length(eigvalue)
sumNow = sumNow + eigvalue(idx);
if sumNow >= sumEig
break;
end
end
eigvector = eigvector(:,1:idx);
end
%dt get from C# program, user ID and name
evFolder = 'ev\';
userIDName = details; %get ID and Name
userIDNameWE = strcat(userIDName,'\');%get ID and Name with extension
filePath = fullfile('C:\Users\***\Desktop\Data Collection\');
userIDNameFolder = strcat(filePath,userIDNameWE); %ID and Name folder
userIDNameEVFolder = strcat(userIDNameFolder,evFolder);%EV folder in ID and Name Folder
userIDNameEVFile = strcat(userIDNameEVFolder,userIDName); % EV file with ID and Name
if ~exist(userIDNameEVFolder, 'dir')
mkdir(userIDNameEVFolder);
end
newFile = strcat(userIDNameEVFile,'_1');
searchMat = strcat(newFile,'.mat');
if exist(searchMat, 'file')
filePattern = strcat(userIDNameEVFile,'_');
D = dir([userIDNameEVFolder, '*.mat']);
Num = length(D(not([D.isdir])))
Num=Num+1;
fileName = [filePattern,num2str(Num)];
save(fileName,'eigvector');
else
newFile = strcat(userIDNameEVFile,'_1');
save(newFile,'eigvector');
end