% function [t, psnr] = Demo_CS_OMP(imageName, sub)
imageName = 'lenna.pgm';
sub = 0.4;
%------------ read in the image --------------
img=imread(imageName); % testing image
%img = rgb2gray(img);
img=double(img);
[height,width]=size(img);
% building the 1D-DCT basis (corresponding to each column)
mat_dct_1d=zeros(height,height);
for k=0:1:(height-1)
dct_1d=cos([0:1:(height-1)]'*k*pi/height);
if k>0
dct_1d=dct_1d-mean(dct_1d);
end;
mat_dct_1d(:,k+1)=dct_1d/norm(dct_1d);
end
trial_nums = 5;
for j = 1:trial_nums
%------------ form the measurement matrix and base matrix ---------------
subrate = sub;
Phi=randn(floor(height*subrate),height); % only keep ((subrate*height)*height numbers of the original data
Phi = Phi./repmat(sqrt(sum(Phi.^2,2)),[1,height]); % normalize each column
%--------- projection ---------
img_cs_1d=Phi*img; % treat each column as a independent signal
tic
%-------- recover using omp ------------
sparse_rec_1d=zeros(height,width);
Theta_1d=Phi*mat_dct_1d;
for i=1:width
column_rec=cs_omp(img_cs_1d(:,i),Theta_1d,height);
sparse_rec_1d(:,i)=column_rec'; % sparse representation
end
img_rec_1d=mat_dct_1d*sparse_rec_1d; % inverse transform
psnr(j) = 20*log10(255/sqrt(mean((img(:)-img_rec_1d(:)).^2)));
t(j) = toc;
end
psnr = mean(psnr);
t = mean(t);
disp(['Elapsed Time = ' num2str(t) ' s']);
disp(['OMP PSNR = ' num2str(psnr) ' dB']);
%------------ show the results --------------------
subplot(2,2,1),imshow(uint8(img)),title('原始图像')
subplot(2,2,1),imagesc(img),title('原始图像')
subplot(2,2,2),imshow(uint8(img_rec_1d)),title(strcat('压缩后的图像 ','(',num2str(psnr),'dB',')'))
% disp('over');
%************************************************************************%


海神之光
- 粉丝: 5w+
- 资源: 7136
最新资源
- 基于SSM商城系统.zip
- 毕业生离校管理系统.zip
- 博客系统毕业设计.zip
- 超市管理系统高级版v2.zip
- 房屋租赁管理信息系统v2.zip
- 进销存或库存管理系统.zip
- 智能桌面宠物完整资料.zip
- IEEE标准节点仿真模型系列:涵盖多种配置,潮流计算已调试完毕,适用于短路仿真与电能质量研究,IEEE标准节点仿真模型系列:潮流计算及扩展应用,IEEE标准节点仿真模型 1、IEEE2机5节点 2、
- 计算机毕业设计源码:基于Java的小说中敏感词识别系统设计与实现.zip关注博主
- 《无线通信》 AndreaGoldsmith、杨鸿文等译
- 三种版本的redis软件包
- report547769026951657921.pdf
- 基于 DeepSeek-Coder 代码漏洞检测与修复的 Python 源码
- 语音转文字模型测试demo(linux)
- 面向能源系统的深度强化学习算法性能比较及最优调度策略代码实践,能源系统深度强化学习算法性能比较及最优调度策略代码实践,面向能源系统深度强化学习算法的性能比较 最优调度(代码) ,面向能源系统;深度强化
- spider for learning (died)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


