Advertisement

压缩感知重构之SP的matlab实现

阅读量:
复制代码
    function CS_SP()
    
    img=imread('lena.bmp');  
    img=double(img);
    [height,width]=size(img);
    
    Phi=randn(floor(height/3),width); 
    Phi = Phi./repmat(sqrt(sum(Phi.^2,1)),[floor(height/3),1]); 
    
    
    mat_dct_1d=zeros(256,256);  % building the DCT basis (corresponding to each column)
    for k=0:1:255 
    dct_1d=cos([0:1:255]'*k*pi/256);
    if k>0
        dct_1d=dct_1d-mean(dct_1d); 
    end;
    mat_dct_1d(:,k+1)=dct_1d/norm(dct_1d);
    end
    
    
    img_cs_1d=Phi*img;         
    
    
    sparse_rec_1d=zeros(height,width);            
    Theta_1d=Phi*mat_dct_1d;
    for i=1:width
    column_rec=cs_sp(img_cs_1d(:,i),Theta_1d,height);
    sparse_rec_1d(:,i)=column_rec';          
    end
    img_rec_1d=mat_dct_1d*sparse_rec_1d;         
    
    figure(1)
    subplot(2,2,1),imagesc(img),title('original image')
    subplot(2,2,2),imagesc(Phi),title('measurement mat')
    subplot(2,2,3),imagesc(mat_dct_1d),title('1d dct mat')
    psnr = 20*log10(255/sqrt(mean((img(:)-img_rec_1d(:)).^2)))
    subplot(2,2,4),imagesc(img_rec_1d),title(strcat('1d rec img ',num2str(psnr),'dB'))
    
    disp('over')
    
    function hat_x=cs_sp(y,T_Mat,m)
    
    
    n=length(y);                          
    s=floor(n/4);                                  
    r_n=y;                             
    sig_pos_lt=[];                      
    
    for times=1:s                        
    
    product=abs(T_Mat'*r_n);
    [val,pos]=sort(product,'descend');
    sig_pos_cr=pos(1:s);           
    sig_pos=union(sig_pos_cr,sig_pos_lt);
    
    Aug_t=T_Mat(:,sig_pos);          
    
    aug_x_cr=zeros(m,1);               
    aug_x_cr(sig_pos)=(Aug_t'*Aug_t)^(-1)*Aug_t'*y;  
    
    [val,pos]=sort(abs(aug_x_cr),'descend');
    
    hat_x=zeros(1,m);
    hat_x(pos(1:s))=aug_x_cr(pos(1:s));
    
    sig_pos_lt=pos(1:s);              
    
    r_n=y-T_Mat*hat_x';
    end
             
    
    
    AI写代码java
    
    运行
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-05-31/LbH9P7ngjGhYBr2Mcot3OFdvVUA0.png)

全部评论 (0)

还没有任何评论哟~