gpt4 book ai didi

matlab - 如何对图像应用主成分分析

转载 作者:行者123 更新时间:2023-12-02 06:57:28 25 4
gpt4 key购买 nike

我正在尝试在图像上应用 pca。指定新的 W 轴为第一主成分,第二主成分为 P 轴。在 W-P 轴上,图像被重新绘制。谁能告诉我该怎么做?

我尝试了以下代码,但无法继续。请帮忙。

I2=;%grayscale image
arr=[];
for i=1:size(I2,1)
for j=1:size(I2,2)
arr=[arr;i,j,I2(i,j)];
end
end
c=pca(arr);
c=c(:,1:2);%i select the first two components here. How do i proceed now

最佳答案

在PCA特征值矩阵中,最大的特征值代表最突出的特征,例如 Nose 。考虑到这一点,定位这些值是一个简单的问题: reshape 图像以生成协方差矩阵并计算特征值并提取正确的特征向量列。完成后,您再次 reshape 矩阵并显示它..

下面附有基本示例代码:

% Reshape the image into a row vector where each row
% is placed next to the one above it.
MD_image1_Row = reshape(MD_image1.',1,[]);

% multiplying the the row matrix with its transpose to form a very large
% matrix
cov_matrix = (1/3).*(MD_image1_Row * MD_image1_Row .');

% finding the eigenvalues and eigenvectors of the matrix formed above
[Vector, Value] = eig(cov_matrix);

% by looking at the eigenvalue matrix the three (depending on the image)
% largest eigenvalues are located and then the corresponding column in the
% Eigenvector matrix is taken and manipulated to produce the Eigenface

% Extracting Eigenvector column
Eig_Vector1 = Vector(:,2803); %value is example

% reshaping Eigenvector into a matrix with the same dimensions as the
% original image
Eig_1_Matrix = reshape(Eig_Vector1.', 51,55); %value is example

% checking size of the EigenMatrix - this is to check the new image has the
% same size as the original images
EigenMatrix = size(Eig_1_Matrix)

% displaying EigenMatrix image using specific limits so that the images are
% displayed correctly
figure, CC = imshow(Eig_1_Matrix,...
[min(Eig_1_Matrix(:)),...
max(Eig_1_Matrix(:))]);

提示:需要考虑主体的光强度,还需要考虑图像方向才能正确显示。

一旦你确定了你想要的特征并提取了正确的特征向量列,你就可以给它们贴上标签并做任何你想做的事情。

关于matlab - 如何对图像应用主成分分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29898408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com