function [img,Phi,mat_dct_1d,img_rec_1d]=Demo_CS_OMP(X)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the DCT basis is selected as the sparse representation dictionary
% instead of seting the whole image as a vector, I process the image in the
% fashion of column-by-column, so as to reduce the complexity.
% Author: Chengfu Huo, roy@mail.ustc.edu.cn, http://home.ustc.edu.cn/~roy
% Reference: J. Tropp and A. Gilbert, “Signal Recovery from Random
% Measurements via Orthogonal Matching Pursuit,” 2007.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%------------ read in the image --------------
% img=imread('lena.bmp'); width-1 % testing image
% img=double(img);
% [height,width]=size(img);
% X=imread('lena.bmp');
img=double(X);
[height,width]=size(img);
%------------ form the measurement matrix and base matrix ---------------
Phi=randn(floor(height/3),width); % only keep one third of the original data
Phi= orth(Phi')';
%Phi = Phi./repmat(sqrt(sum(Phi.^2,1)),[floor(3*height/4),1]); % normalize each column
mat_dct_1d=zeros(352,352); % building the DCT basis (corresponding to each column)
for k=0:1:351
dct_1d=cos([0:1:351]'*k*pi/352);
if k>0
dct_1d=dct_1d-mean(dct_1d);
end;
mat_dct_1d(:,k+1)=dct_1d/norm(dct_1d);
end
%--------- projection ---------
img_cs_1d=Phi*img'; % treat each column as a independent signal,图像的测量
%-------- recover using omp ------------
sparse_rec_1d=zeros(width,height);
Theta_1d=Phi*mat_dct_1d;
for i=1:height
column_rec=cs_omp(img_cs_1d(:,i),Theta_1d,width);%对每一列进行重建
% sparse_rec_1d= sparse_rec_1d(:,i)';
sparse_rec_1d(:,i)=column_rec'; % sparse representation
% c=i
end
img_rec_1d=mat_dct_1d*sparse_rec_1d; % inverse transform
%------------ show the results --------------------
%************************************************************************%