2012-11-17 107 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/。 –

相關問題