用Matlab实现pca
对于这个问题,我不明白为什么每次运行pca行时,我的MATLAB都会崩溃。我在包含异常面的矩阵上使用pca,如下所述: pics.mat包含40个图像的矩阵数据,每个图像的尺寸为96*64像素。(96*64*40的矩阵) 我在这一部分的代码是:用Matlab实现pca,matlab,matrix,pca,face-recognition,Matlab,Matrix,Pca,Face Recognition,对于这个问题,我不明白为什么每次运行pca行时,我的MATLAB都会崩溃。我在包含异常面的矩阵上使用pca,如下所述: pics.mat包含40个图像的矩阵数据,每个图像的尺寸为96*64像素。(96*64*40的矩阵) 我在这一部分的代码是: %% problem 1a: finding average face load('pics.mat'); % loads the file % combines the 3d matrix into a 2d matrix total = [pic
%% problem 1a: finding average face
load('pics.mat'); % loads the file
% combines the 3d matrix into a 2d matrix
total = [pics(:, :, 1)];
for i = 2:40
total = [total + pics(:, :, i)];
end
size(total) %96 by 64
A1 = total/40 % the average values divided by total # of faces for avg face
%% problem 1b: the anomalous face
Anom = [];
for i = 1:40
Anom(:, :, i) = [pics(:, :, i) - A1]; % subtract the average face from all 40 images
end
%% problem 1c I: pca
Anom = reshape(Anom, [6144 40]); % reshapes a 3d into 2d
[eigenfaces,scores,sigma2] = pca(Anom', 'Centered' ,'off'); % this crashes MATLAB
我遇到的问题是,当我在本节中使用pca对b部分的40个异常面进行处理时,我的MATLAB崩溃了
我在这一部分的代码是:
%% problem 1a: finding average face
load('pics.mat'); % loads the file
% combines the 3d matrix into a 2d matrix
total = [pics(:, :, 1)];
for i = 2:40
total = [total + pics(:, :, i)];
end
size(total) %96 by 64
A1 = total/40 % the average values divided by total # of faces for avg face
%% problem 1b: the anomalous face
Anom = [];
for i = 1:40
Anom(:, :, i) = [pics(:, :, i) - A1]; % subtract the average face from all 40 images
end
%% problem 1c I: pca
Anom = reshape(Anom, [6144 40]); % reshapes a 3d into 2d
[eigenfaces,scores,sigma2] = pca(Anom', 'Centered' ,'off'); % this crashes MATLAB
为什么会崩溃?是因为我在前面几节中的代码,还是因为我在一台极度贫血的笔记本电脑上运行这个程序?我遇到了一个类似的问题,维度让计算变得难以承受。 主动形状模型,在附录C中,他将D转换为T以处理矩阵维数 我希望它也适用于你的情况,因为它使我免于很多麻烦 这是我在MatLab中解决它的方法: imvecs=图像向量 meanval=它们的平均值 大小(imvecs,2)=我的数据集中的图像数(N) T现在是一个NxN大小的矩阵,希望在不耗尽内存的情况下更容易计算
祝你好运 是64位操作系统吗?如果没有,您可能希望在崩溃后立即检查matlab.exe的内存消耗,即使是从任务管理器中也可以。很可能您的计算机“很弱”,代码对matlab来说太多了。Matlab通常不会因为代码中的错误而崩溃。是的,我在64位Windows 8上运行这个。这可能是记忆;我在一个小得多的矩阵上尝试了pca,它很有效。