MATLAB中的ICA人脸识别

时间:2014-03-05 15:46:46

标签: matlab face-recognition

我正在完成我的最后一年项目,我真的需要一些帮助。 我的部分是面部识别,我使用ICA算法来识别面部。 我能够标记特征(眼睛和嘴巴)并对齐它们。 但是我无法遵循ICA架构-I算法。

我的代码哪里有错误:

% script Arch1.m
% 
% Put the aligned training images in the rows of C, one image per row.  


[V,R,E] = pcabigFn(C');

% We choose to use the first 4 eigenvectors as 6 images were considered. 

x = V(:,1:4)';      % x is 200x3600
runica              % calculates whitening(wz), weight matrix(w). 

F = R(:,1:4) * inv(w*wz);   % F is 500x200 and each row contains the 
                    % ICA1 rep of an image

% Representations of test images under architecture I: 
%%% Put original aligned test images in rows of Ctest.

Dtest = zeroMn(Ctest')'; % For proper testing, subtract the mean of the 
                            % training images not the test images: 
                            %Dtest = Ctest-ones(6,1)*mean(C);
x = V(:,1:4)';

Rtest = Dtest*V;
Ftest = Rtest(:,1:4) * inv(w*wz);

% Test nearest neighbor classification using cosine, not euclidean distance, 
% as similarity measure.
%
% First create label vectors. These are column vectors of integers. Lets 
% say our 500 training examples consisted of 500 different people. Then

trainClass = [1:6]'; 

%
% We also need the correct class labels of the test examples if we want to 
% compute percent correct. Lets say the test examples were two images each 
% of the first 10 individuals. Then 

testClass = [1 2 3 4 5 6]';


%We now compute percent correct:
train_ex = F';
test_ex = Ftest';
[pc,rankmat] = nnclassFn(train_ex,test_ex,trainClass,testClass);

%pc is percent correct of first nearest neighbor.
%rankmat gives the top 30 matches for each test image. 

-------------------------------------------------------------------------

nnclassFn.m
            function [testPerf,rankmat] = nnclassFn(train,test,trainClass,answer)

    numTest = size(test,2);
    numTrain = size(train,2);

%Get distances to training examples

dists=-1 * cosFn(test,train);%Outputs a Ntest x Ntrain matrix of cosines

%sort the rows of dists to find the nearest training example:
[Sdist,nearest] = sort(dists'); %cols of Sdist are distances in ascend order
        %1st row of nearest is index of 1st closest training example




------------------------------------------------------------------
cosFn.m

    `function [S] = cosFn(mat1,mat2)

  denom = sum(mat1.^2,1)*sum(mat2'.^2,2);
  denom (find(denom==0)) = 0.00000000000000000000001;
  numer = mat1'*mat2;

  S = numer./denom;

我在此代码中遇到的问题是,如果我在trainClasstestClass向量中具有相同的大小,那么代码可以正常工作并识别。但是,如果测试图像(存储在testClass中)少于数据库图像(存储在trainClass中),则表示denom= sum(mat1.^2,1)*sum(mat2'.^2,2);中的尺寸错误

我将只有少量面孔用于测试数据库。您可以建议如何减少testClass并删除上述错误。

0 个答案:

没有答案
相关问题