%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 测试SVD样本图像能量提取效果。
% SVD分解方法满足能量守恒定理,可以实现各成分能量的提取,实现在降维层次上的图像相似度比较。
% 本实验选取3维进行比较,简单测试有一定的效果。能否选取某一层次的主成分进行一类人的气质测试?
% Version 1.0
% Copyright(c) 2014.8. mafei863@qq.com
% All Rights Reserved.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
close all;
clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%利用SVD进行特征提取然后匹配相似度%%%%%%%%%%%%%%%
%利用SVD分别对每一图像灰度图像和HSV特征进行提取第一主成分对应的特征向量,识别效果显著提高
%提取第一特征根对应的特征向量和颜色HSV特征向量,对以人身为主的图片效果较好,如“行人重-1”
%包含较多背景的图像效果较差,如"行人重-3"
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
vectorColNum=1;
databasePath='D:\我的文档\MATLAB\svdExtractEnergyTest\行人重-1\';
testBmpNO=5;
filepath=strcat(databasePath,num2str(testBmpNO));
filepath=strcat(filepath,'.bmp');
img=imread(filepath);
img1=double(rgb2gray(img));%加载一个简单的单色图像
subplot(2,3,1);imshow(filepath);
title(['the orignal: ' num2str(testBmpNO) '.bmp']);
[m n]=size(img1);
[u1 s v]=svd(img1) ;
recImage=zeros(m,n);
%重构相应主成分图像
for i=1:vectorColNum
recImage=recImage+s(i,i)*u1(:,i)*v(:,i)';
end
recImage=uint8(recImage);
subplot(2,3,2);imshow((recImage));
title([num2str(vectorColNum) ' vector rec-bmp']);
%保存相应主成分对应的特征向量
orignalU=[];
for i=1:vectorColNum
orignalU=[orignalU;u1(:,i)];%取前n个列向量,组成一个大的列向量
end
subplot(2,3,4);plot(orignalU);
imgHsv=rgb2hsv(img);
%将原图像的彩色信息 累加入特征向量中
[u2 s v]=svd((imgHsv(:,:,1))) ;
for i=1:vectorColNum
orignalU=[orignalU;u2(:,i)];%取前n个列向量,组成一个大的列向量
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
targetU=[];
for j=1:8
filepath=strcat(databasePath,num2str(j));
filepath=strcat(filepath,'.bmp');
imgi=imread(filepath);
img2=double(rgb2gray(imgi));%加载一个简单的单色图像
[u2 s v]=svd(img2) ;
targetU2=[];
for i=1:vectorColNum
targetU2=[targetU2;u2(:,i)];%取前n个列向量,组成一个大的列向量
end
imgiHsv=rgb2hsv(imgi);
[u2 s v]=svd((imgiHsv(:,:,1))) ;
for i=1:vectorColNum
targetU2=[targetU2;u2(:,i)];%取前n个列向量,组成一个大的列向量
end
targetU=[targetU targetU2];
end
distU=[];
for i=1:size(targetU,2)
distU=[distU (norm(targetU(:,i)-orignalU(:,1),2))];
end
% [v d]=min(distU);
[v d]=sort(distU)
% if v<1.7
filepath=strcat(databasePath,num2str(d(2)));
filepath=strcat(filepath,'.bmp');
subplot(2,3,3);imshow(filepath);
title(['the reco-target: ' num2str(d(2)) '.bmp']);
subplot(2,3,6);plot(targetU(:,d(2)));
% else
% subplot(2,3,3);title('The target is :none');
% end
% for i=3:5
% filepath=strcat(databasePath,num2str(d(i)));
% filepath=strcat(filepath,'.bmp');
% subplot(2,3,i+1); imshow(filepath);
% title(['the ' num2str(i) ' candidate.']);
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%--------图片欧氏距离的 直接比较---------------------------
% databasePath='D:\我的文档\MATLAB\svdExtractEnergyTest\行人重-1\';
% filepath=strcat(databasePath,'1.bmp');
% img1=double(rgb2gray(imread(filepath)));%加载一个简单的单色图像
% subplot(2,3,1);imshow(uint8(img1));
% title('the orignal bmp');
% [m n]=size(img1);
%
% recImage=reshape(img1,m*n,1);
% targetU=[];
% for j=2:8
% filepath=strcat(databasePath,num2str(j));
% filepath=strcat(filepath,'.bmp');
% img2=double(rgb2gray(imread(filepath)));%加载一个简单的单色图像
%
% targetU=[targetU reshape(img2,m*n,1)];
%
% end
% distU=[];
% for i=1:7
% distU=[distU (norm(targetU(:,i)-recImage(:,1),2))];
% end
% [v d]=min(distU);
% d
% % if v<1.7
% filepath=strcat(databasePath,num2str(d+1));
% filepath=strcat(filepath,'.bmp');
% subplot(2,3,3);imshow(filepath);
% title('the recognisition target');
% disp(['The target is :' num2str(d+1) '.bmp'])
% subplot(2,3,6);plot(targetU(:,d));
% else
% subplot(2,3,3);title('The target is :none');
% end
%%%%%%%%%%%%%%-----------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% img5=double(rgb2gray(imread('5.bmp')));%加载一个简单的单色图像
% subplot(2,3,3);imshow(uint8(img5));
% [m n]=size(img5);
% [u5 s v]=svd(img5) ;
% targetU5=[];
% for i=1:vectorColNum
% targetU5=[targetU5;u5(:,i)];%取前n个列向量,组成一个大的列向量
% end
% subplot(2,3,6);plot(targetU5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% [u3 s3 v3]=svd(img31) ;
% ssDist=[];
% for i=1:size(s)
% ssDist=[ssDist (s(i,i)-s3(i,i))];
% end
% subplot(2,3,5); plot(ssDist);
%
% uuDist=[];
% for i=1:size(s)
% uuDist=[uuDist u-u3];
% end
% subplot(2,3,6); plot(uuDist);
svd行人重识别简单测试
4星 · 超过85%的资源 需积分: 13 4 浏览量
2014-08-12
20:38:24
上传
评论 2
收藏 540KB RAR 举报
mafei863
- 粉丝: 0
- 资源: 5
最新资源
- Python 版冒泡排序算法源代码
- tensorflow-gpu-2.7.2-cp38-cp38-manylinux2010-x86-64.whl
- tensorflow-2.7.3-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.7.2-cp39-cp39-manylinux2010-x86-64.whl
- Python版本快速排序源代码
- Python 语言版的快速排序算法实现
- 450815388207377安卓_base.apk
- 超微主板 X9DRE-TF+ bios 支持 nvme启动
- 基于Python通过下载气象数据和插值拟合离散数据曲线实现对寒潮过程的能量分析
- 智能车仿真软件.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈