【问题标题】:How can I use the princomp function of Matlab in the following case?在以下情况下如何使用 Matlab 的 princomp 函数?
【发布时间】:2012-11-17 12:37:18
【问题描述】:

我有 10 张图片(18x18)。我将这些图像保存在一个名为 images[324][10] 的数组中,其中数字 324 代表图像的像素数量,数字 10 代表我拥有的图像总数。

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

我听说你可以使用实现 PCA 的 princomp 函数来做到这一点。

问题是我还没有找到任何关于如何使用这个功能的例子,尤其是对于我的情况。

如果我跑步

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

它运行良好,但我怎样才能得到数组newimages[number_of_desired_features][10]

【问题讨论】:

    标签: matlab image-processing pca


    【解决方案1】:

    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
    

    【讨论】:

    • 您提到的教程论文不可用。你有其他网址吗?
    • 我编辑了我的帖子并提供了一个工作链接,取自作者页面:shlens.wordpress.com/tutorials
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    • 2016-01-07
    • 2015-08-21
    • 2017-07-09
    • 1970-01-01
    相关资源
    最近更新 更多