matlab练习程序(PCA<SVD>)

clear all;
close all;
clc;
img1=imread('Corner.png');
img2=imread('Corner1.png');
img3=imread('Corner2.png');

img1=imresize(img1,[35 90]); %Matlab的svd不支持太大的数据,我把数据变小了.
img2=imresize(img2,[35 90]);
img3=imresize(img3,[35 90]);

[height width]=size(img2);
a=reshape(double(img1),1,35*90);
b=reshape(double(img2),1,35*90);
c=reshape(double(img3),1,35*90);

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);
[u s w]=svd(x);    %w相当于排序后的d,用svd就不用求x'*x了    

ed=x*w;%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.http://iiec.cqu.edu.cn/wiki/index.php/SVD%E4%B8%8EPCA%E7%9A%84%E7%93%9C%E8%91%9B

转载于:https://www.cnblogs.com/tiandsp/archive/2012/05/02/2478991.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值