matlab练习程序(PCA)

时间:2023-02-13 17:04:12
clear all;
close all;
clc;
img1
=imread('Corner.png');
img2
=imread('Corner1.png');
img3
=imread('Corner2.png');
[height width]
=size(img2);
a
=reshape(img1,1,height*width);
b
=reshape(img2,1,height*width);
c
=reshape(img3,1,height*width);

ma
=mean(a);
mb
=mean(b);
mc
=mean(c);

a
=a-ma;
b
=b-mb;
c
=c-mc;

x
=[a' b' c'];
x=double(x);
y
=x'*x/(height*width);

[v d]
=eig(y);

ed
=x*v;

img4
=zeros(height,width);
img4
=reshape(ed(:,1),height,width);

img5
=zeros(height,width);
img5
=reshape(ed(:,2),height,width);

img6
=zeros(height,width);
img6
=reshape(ed(:,3),height,width);

imshow(mat2gray(img4));
figure,imshow(mat2gray(img5));
figure,imshow(mat2gray(img6));

图片福利:

图1:

matlab练习程序(PCA)

图2:

matlab练习程序(PCA)

图3:

matlab练习程序(PCA)

主成分:

matlab练习程序(PCA)

特征值中间的成分:

matlab练习程序(PCA)

特征值最小的成分:

matlab练习程序(PCA)