我是Matlab新手。 我正嘗試將PCA功能(下面列出的URL)應用到我的掌紋識別程序中以生成eigenpalms。我的掌紋灰度圖像尺寸是450 * 400。 在使用它之前,我試圖研究這些代碼並添加一些代碼以將特徵向量保存爲.mat文件。我爲自我理解添加了一些%的評論。PCA代碼輸入,用於PalmPrint識別
經過幾天的學習,我仍然無法得到答案。 我決定尋求幫助。我有幾個問題要問這個PCA.m.
PCA.m
什麼是 「選項」 輸入應該是什麼?的「PCA(數據,細節,選項)」 (這是一個整數的縮小尺寸?我試圖找出「選項」值傳遞的位置,但仍然無法獲得ans。msgbox的「h & h2「,是檢查代碼運行到哪裏,我試圖使用整數10,但PCA.m處理的尺寸是400 * 400)。
我保存爲」.ig「的」eigvector「 「文件準備與其他特徵向量執行歐氏距離分類器? (我在考慮eigvector等於eigenpalm,就像在臉部識別中,特徵所面臨的那樣,我試圖將特徵向量矩陣轉換回圖像,但PCA過程之後的圖像是黑色的,並且有很多點)
mySVD.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
如果您喜歡發佈特徵向量的圖像。我認爲也許你需要以某種方式來縮放圖像以用灰度表示,因爲有界的0-255範圍可能存在問題。 –