2012-11-17 110 views
4

我有10张图片(18x18)。我将这些图像保存在名为images[324][10]的数组中,其中数字324代表图像的像素数量,数字10代表我拥有的图像总量。如何在以下情况下使用Matlab的princomp函数?

我想将这些图像用于神经网络,但是324是一个很大的数字作为输入,因此我想减少这个数字,但保留尽可能多的信息。

我听说你可以用princomp函数来实现PCA。

问题是,我还没有找到任何关于如何使用此功能的例子,特别是对于我的情况。

如果我运行

[COEFF, SCORE, latent] = princomp(images); 

它运行良好,但我怎么能那么获取数组newimages[number_of_desired_features][10]

回答

5

PCA可能是一个正确的选择(但不是唯一的一个)。虽然,您应该意识到,PCA不会自动减少输入数据功能的数量。我建议你阅读本教程:http://arxiv.org/pdf/1404.1100v1.pdf - 这是我用来了解PCA和它对初学者非常好的一个。

回到你的问题。图像是324维空间中的矢量。在这个空间中,第一个基矢量是在左上角有一个白色像素的矢量,下一个像素是白色,另一个是黑色 - 以此类推。它可能不是代表这个图像数据的最佳基矢量。 PCA计算新的基向量(COEFF矩阵 - 新向量表示为旧向量空间中的值)和新图像向量值(SCORE矩阵)。此时,您还没有丢失任何数据(不减少功能数量)。但是,你可以停止使用一些新的基本向量,因为它们可能与噪声连接,而不是数据本身。在教程中详细介绍了这些内容。

images = rand(10,324); 
[COEFF, SCORE] = princomp(images); 
reconstructed_images = SCORE/COEFF + repmat(mean(images,1), 10, 1); 
images - reconstructed_images 
%as you see there are almost only zeros - the non-zero values are effects of small numerical errors 
%its possible because you are only switching between the sets of base vectors used to represent the data 
for i=100:324 
    SCORE(:,i) = zeros(10,1); 
end 
%we remove the features 100 to 324, leaving only first 99 
%obviously, you could take only the non-zero part of the matrix and use it 
%somewhere else, like for your neural network 
reconstructed_images_with_reduced_features = SCORE/COEFF + repmat(mean(images,1), 10, 1); 
images - reconstructed_images_with_reduced_features 
%there are less features, but reconstruction is still pretty good 
+0

你提到的Thee tutorial paper is not available。你有任何其他网址吗? –

+0

我编辑了我的文章并提供了一个工作链接,取自作者的页面:http://shlens.wordpress.com/tutorials/。 –

相关问题