% 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');
%************************************************************************%
没有合适的资源?快使用搜索试试~ 我知道了~
【图像压缩】基于matlab二维图像压缩感知【含Matlab源码 3671期】.zip
共14个文件
m:6个
pgm:5个
asv:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 41 浏览量
2023-12-17
21:12:23
上传
评论 1
收藏 3.01MB ZIP 举报
温馨提示
CSDN海神之光上传的代码均可运行,亲测可用,直接替换数据即可,适合小白; 1、代码压缩包内容 主函数:main.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2019b;若运行有误,根据提示修改;若不会,私信博主; 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开main.m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可私信博主或扫描博客文章底部QQ名片; 4.1 博客或资源的完整代码提供 4.2 期刊或参考文献复现 4.3 Matlab程序定制 4.4 科研合作 图像压缩: BP神经网络图像压缩、DCT变换图像压缩、FFT图像压缩、霍夫曼图像压缩、JPEG图像压缩、小波变换图像压缩、分形编码图像压缩 行程编码图像压缩、蚁群算法优化小波变换图像压缩
资源推荐
资源详情
资源评论
收起资源包目录
【图像压缩】基于matlab二维图像压缩感知【含Matlab源码 3671期】.zip (14个子文件)
【图像压缩】基于matlab二维图像压缩感知【含Matlab源码 3671期】
dct_basis.m 164B
运行结果1.jpg 30KB
GenerateProjection.m 599B
Demo_CS_OMP.asv 2KB
projections.1.mat 1.92MB
omp.m 857B
cs_omp.m 1KB
PSNR.m 1KB
peppers.pgm 256KB
barbara.pgm 256KB
mandrill.pgm 256KB
Demo_CS_OMP.m 2KB
lenna.pgm 256KB
goldhill.pgm 256KB
共 14 条
- 1
资源评论
海神之光
- 粉丝: 3w+
- 资源: 2092
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功