function [] = reconstruct()
load C:\att_faces\model.mat;
% 计算新图片在特征子空间中的系数
a1 = imread('C:\Users\xuxiaoxue\Desktop\att_faces\s3\1.pgm');
a2 = imread('C:\Users\xuxiaoxue\Desktop\att_faces\s2\10.pgm');
a3=imread('C:\Users\xuxiaoxue\Desktop\att_faces\1.pgm');
a11=imnoise(a1,'gaussian',0,0.001);
a22=imnoise(a2,'gaussian',0,0.001);
a33=imnoise(a3,'gaussian',0,0.001);
b1=a11(1:112*92); % b 是行矢量 1×N,其中N=10304,提取顺序是先列后行,即从上到下,从左到右
b2=a22(1:112*92); % b 是行矢量 1×N,其中N=10304,提取顺序是先列后行,即从上到下,从左到右
b3=a33(1:112*92); % b 是行矢量 1×N,其中N=10304,提取顺序是先列后行,即从上到下,从左到右
b1=im2double(b1);
b2=im2double(b2);
b3=im2double(b3);
b1=b1-samplemean;
b2=b2-samplemean;
b3=b3-samplemean;
c1 = b1 * base; % c 是图片a 在子空间中的系数, 是1*p 行矢量
c2 = b2 * base; % c 是图片a 在子空间中的系数, 是1*p 行矢量
c3 = b3 * base; % c 是图片a 在子空间中的系数, 是1*p 行矢量
% 根据特征系数及特征脸重建图
% 前15 个
t = 15;
temp1 = base(:,1:t) * c1(1:t)';
temp1 = temp1 + samplemean';
imwrite(mat2gray(reshape(temp1, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\s3\t11.pgm');
temp2 = base(:,1:t) * c2(1:t)';
temp2 = temp2 + samplemean';
imwrite(mat2gray(reshape(temp2, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\s2\t12.pgm');
temp3 = base(:,1:t) * c3(1:t)';
temp3 = temp3 + samplemean';
imwrite(mat2gray(reshape(temp3, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\t13.pgm');
% 前50 个
t=50;
temp1 = base(:,1:t) * c1(1:t)';
temp1 = temp1 + samplemean';
imwrite(mat2gray(reshape(temp1, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\s3\t21.pgm');
temp2 = base(:,1:t) * c2(1:t)';
temp2 = temp2 + samplemean';
imwrite(mat2gray(reshape(temp2, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\s2\t22.pgm');
temp3 = base(:,1:t) * c3(1:t)';
temp3 = temp3 + samplemean';
imwrite(mat2gray(reshape(temp3, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\t23.pgm');
% 前100 个
t = 100;
temp1 = base(:,1:t) * c1(1:t)';
temp1 = temp1 + samplemean';
imwrite(mat2gray(reshape(temp1, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\s3\t31.pgm');
temp2 = base(:,1:t) * c2(1:t)';
temp2 = temp2 + samplemean';
imwrite(mat2gray(reshape(temp2, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\s2\t32.pgm');
temp3 = base(:,1:t) * c3(1:t)';
temp3 = temp3 + samplemean';
imwrite(mat2gray(reshape(temp3, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\t33.pgm');
% 前150 个
t = 150;
temp1 = base(:,1:t) * c1(1:t)';
temp1 = temp1 + samplemean';
imwrite(mat2gray(reshape(temp1, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\s3\t41.pgm');
temp2 = base(:,1:t) * c2(1:t)';
temp2 = temp2 + samplemean';
imwrite(mat2gray(reshape(temp2, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\s2\t42.pgm');
temp3 = base(:,1:t) * c3(1:t)';
temp3 = temp3 + samplemean';
imwrite(mat2gray(reshape(temp3, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\t43.pgm');;
% 前199 个
t = 199;
temp1 = base(:,1:t) * c1(1:t)';
temp1 = temp1 + samplemean';
imwrite(mat2gray(reshape(temp1, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\s3\t51.pgm');
temp2 = base(:,1:t) * c2(1:t)';
temp2 = temp2 + samplemean';
imwrite(mat2gray(reshape(temp2, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\s2\t52.pgm');
temp3 = base(:,1:t) * c3(1:t)';
temp3 = temp3 + samplemean';
imwrite(mat2gray(reshape(temp3, 112,92)),'C:\Users\xuxiaoxue\Desktop\att_faces\t53.pgm');
figure,
subplot(121),imshow(a11);title('加入高斯噪声');
subplot(122),imshow('C:\Users\xuxiaoxue\Desktop\att_faces\s3\t51.pgm');title('重建图像');
figure,
subplot(121),imshow(a22);title('加入高斯噪声');
subplot(122),imshow('C:\Users\xuxiaoxue\Desktop\att_faces\s2\t52.pgm');title('重建图像');
figure,
subplot(121),imshow(a33);title('加入高斯噪声');
subplot(122),imshow('C:\Users\xuxiaoxue\Desktop\att_faces\t53.pgm');title('重建图像');
figure,
subplot(122),imshow('C:\Users\xuxiaoxue\Desktop\att_faces\t53.pgm');title('重建图像');
subplot(2,3,1),imshow(imread('C:\att_faces\s3\1.pgm'));title('original');
subplot(2,3,2),imshow(imread('C:\\att_faces\s2\10.pgm'));title('original');
subplot(2,3,3),imshow(imread('C:\att_faces\1.pgm'));title('original');
subplot(2,3,4),imshow(imread('C:\att_faces\t51.pgm'));title('重建');
subplot(2,3,5),imshow(imread('C:\att_faces\t52.pgm'));title('重建');
subplot(2,3,6),imshow(imread('C:\att_faces\t53.pgm'));title('重建')
end
墨池有雨
- 粉丝: 113
- 资源: 6
最新资源
- (源码)基于C++的表达式求值系统.zip
- (源码)基于C#和Arduino的UWB追踪系统.zip
- (源码)基于Python的岷江白鹤亮翅挂篮智能监控系统.zip
- 苹果IOS绿标免签封装app隐藏顶部网址ios14不显示顶部网址跳转设置
- (源码)基于C++的Taobao分布式文件系统管理工具.zip
- (源码)基于Python的智能家居控制系统.zip
- (源码)基于Spring Boot框架的异常通知系统.zip
- (源码)基于C++和OpenCL的渲染与动画系统.zip
- 新手必学!Python学习路线三部曲!西工大老师讲解.zip
- Android OpenGL 立方体贴图应用举例-天空盒演示demo源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈