资源简介
用pca提取图像目标特征,用分类对目标分类
代码片段和文件信息
function [eigvector eigvalue] = PCA_Bao(X ReducedDimThd)
%PCA Principal Component Analysis
%
% Usage:
% [eigvector eigvalue] = PCA(X ReducedDim)
% [eigvector eigvalue] = PCA(X)
%
% Input:
% X - Data matrix. Each row vector of fea is a data point.
%
% 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(710);
% [eigvectoreigvalue] = PCA(fea4);
% Y = fea*eigvector;
%
%
P = X;
% Calculate the mean column vector of the matrix P and substract
% it from P
row_P = size(P1);
col_P = size(P2);
PP=[];
mean_P= mean(P2);
temp=ones(1col_P);
PP = P-mean_P*temp;
% Calculate the eigenvalues and eigenvectors of the matrix PP‘*PP
Q=PP‘*PP;
[vector_Qvalue_Q] = eig(Q);
% Caculate the eigenvalues and eigenvectors of the matrix PP*PP‘
% using SVD(Singular Value Decomposition)
valuecov = value_Q;
vectcov = PP*vector_Q;
vectorcov = vectcov*value_Q^(-0.5);
% Sort the eigenvectors and the eigenvalues of the covariance
% matrix of P with the decrease of the eigenvalues
eigvalue = diag(value_Q);
[junk index] = sort(-eigvalue);
eigvalue = eigvalue(index);
eigvector = vectorcov(: index);
% Return the eigenvectors and the eigenvalue matrix of the covariance
% matrix of imgs
if ReducedDim~=0
if ReducedDim>col_P
ReducedDim=col_P;
fprintf(‘Only %d vectors exist...‘col_P);
end
vectors = eigvector(:1:ReducedDim);
values = eigvalue(1:ReducedDim1:ReducedDim);
else
eigIdx = find(cumsum(eigvalue)./sum(eigvalue) >= Thd);
eigvalue (eigIdx) = [];
eigvector (:eigIdx) = [];
end;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2175 2009-05-09 14:25 PCA.m
----------- --------- ---------- ----- ----
2175 1
- 上一篇:css300
- 下一篇:opencv与qt结合使用的(亲测可用)
评论
共有 条评论