主要利用了Shihao Ji 08年发表的《Bayesian Compressive Sensing》的论文代码,先将图片进行小波变换,得到稀疏系数,采样,然后重建稀疏系数,小波逆变换得到原来的图像。具体的代码如下。
%要运行本程序需要下载另外两个程序包。
%1:http://www.eee.hku.hk/~wsha/Freecode/freecode.htm %(Compressive sensing for image using wavelet %transform and orthogonal matching pursuit algorithm)
%2:http://people.ee.duke.edu/~lcarin/BCS.html
%( bcs_ver0.1.zip )
clear all
addpath(‘Sample‘);%存放了lena.bmp
addpath(‘bcs_ver0.1‘);%BCS_fast_rvm.m
img=imread(‘lena.bmp‘); % read in the image "lena.bmp"
img=double(img);
[height,width]=size(img);
img_rec=zeros(height,width);
N=256; % 信号长度
K =100; % 每个信号测量个数
% 高斯随机测量矩阵
phi= randn(K,N);
phi = phi./repmat(sqrt(sum(phi.^2,2)),[1,N]);
% 噪声方差
sigma = 0.005;
e = sigma*randn(K,256);
% 小波变换矩阵生成
ww=DWT(height); %构造正交小波变换矩阵,图像大小N*N,N=2^P,P是整数。
Theta_d=phi*ww‘;%测量矩阵乘上基矩阵
%高斯随机观测
y =phi*img + e; %测量
for i=1:width
% solve by BCS
yx=y(:,i);
initsigma2 = std(yx)^2/1e2;% std(y):Standard deviation
[weights,used,sigma2,errbars] = BCS_fast_rvm(Theta_d,yx,initsigma2,1e-8);
fprintf(1,‘高斯观测 number of nonzero weights: %d\n‘,length(used));
x_BCS = zeros(N,1); err = zeros(N,1);
x_BCS(used) = weights; err(used) = errbars;
img_rec(:,i)=x_BCS‘;
end
img_rec=ww‘*img_rec;% 小波逆变换
p=psnr(img,img_rec);
figure
subplot(1,2,1),imshow(uint8(img)),title(strcat(‘高斯观测(采样‘,num2str(K),‘个数)‘))
subplot(1,2,2),imshow(uint8(img_rec)),title(strcat(‘高斯观测(‘,num2str(p),‘dB)‘))
原文地址:http://blog.csdn.net/hjxzb/article/details/46652009