标签:bottom Image imshow jpg outImage 源码 Matlab 正交变换 top
一、简介
二、源代码
clear,clc,close all;
Image=rgb2gray(imread('cameraman.jpg'));
subplot(121),imshow(Image),title('原图像');
[ca,ch,cv,cd]=dwt2(Image,'db4'); %用db4小波对图像进行一级小波分解
result=idwt2(ca*0,ch,cv,cd,'db4')/256;
Image=imread('desert.jpg');%读取图像
grayI=rgb2gray(Image);%将彩色图像灰度化
DFTI1=fft2(grayI);
ADFTI1=abs(DFTI1);
top=max(ADFTI1(:));
bottom=min(ADFTI1(:));
subplot(131),imshow(Image),title('原图');%显示原图像
subplot(132),imshow(ADFTI1),title('原频谱图');%显示傅里叶变换频谱图
subplot(133),imshow(ADFTI2),title('移位频谱图');%显示傅里叶变换频谱图
% imwrite(ADFTI1,'dftpinpu2_1.jpg');
% imwrite(ADFTI2,'dftpinpu2_2.jpg');
clear,clc,close all;
fmt={'*.jpg','JPEG image(*.jpg)';'*.*','All Files(*.*)'};
[FileName,FilePath]=uigetfile(fmt,'导入数据','face*.jpg','MultiSelect','on');
if ~isequal([FileName,FilePath],[0,0])
FileFullName=strcat(FilePath,FileName);
else
return;
end
N=length(FileFullName);
for k=1:N
Image=im2double(rgb2gray(imread(FileFullName{k})));
X(:,k) = Image(:); % 把图像放在矩阵x的第k列
end
[h,w,c]=size(Image);
% %----------- 计算每幅训练图像的与平均脸的差值 -------%
averagex = mean(X')'; %计算均值图像
X=X-averagex; % 求中心化图像向量
%-----奇异值分解方法计算协方差矩阵的特征值和特征向量----%
R = X'*X; %协方差矩阵为x*x’,这里用奇异值分解
[Q,D] = eig(R); %V为以特征向量为列的矩阵,D为特征值组成的对角阵
[D_sort,index] = sort(diag(D),'descend');
D=D(index,index);
Q = Q(:,index);
P = X*Q*(abs(D))^-0.5;
total = 0.0;
count = sum(D_sort);
for r =1:N
total = total + D_sort(r);
if total/count > 0.95 %当差异信息比例达到85%时退出循环
break;
end
end
%-------------测试样本在新空间上投影后的坐标-----------%
KLCoefR = P'*X;
figure; plot(KLCoefR(1,:),KLCoefR(2,:),'ko'),title('K-L变换行压缩');
xlabel('第一主成分得分');ylabel('第二主成分得分');
Y= P(:,1:2)*KLCoefR(1:2,:)+averagex; %重建
for j=1:N
outImage=reshape(Y(:,j),h,w);
% top=max(outImage(:));
% bottom=min(outImage(:));
% outImage=(outImage-bottom)/(top-bottom);
% str=strcat('feaface12_',num2str(j),'.jpg');
% imwrite(outImage,str);
figure,imshow(outImage,[]);
end
Z= P(:,1:r)*KLCoefR(1:r,:)+averagex; %重建
for j=1:N
outImage=reshape(Z(:,j),h,w);
% top=max(outImage(:));
% bottom=min(outImage(:));
% outImage=(outImage-bottom)/(top-bottom);
% str=strcat('feaface1r_',num2str(j),'.jpg');
% imwrite(outImage,str);
figure,imshow(outImage,[]);
for j =1:N
outImage=reshape(KLCoefC(:,j),h,w);
% top=max(outImage(:));
% bottom=min(outImage(:));
% outImage=(outImage-bottom)/(top-bottom);
% str=strcat('feaface',num2str(j),'.jpg');
% imwrite(outImage,str);
figure,imshow(outImage,[]);
end
%
%
三、运行结果
四、备注
版本:2014a
完整代码或代写加1564658423
标签:bottom,Image,imshow,jpg,outImage,源码,Matlab,正交变换,top 来源: https://www.cnblogs.com/homeofmatlab/p/14901092.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。