压缩感知重构算法之OMP算法python实现

压缩感知重构算法之CoSaMP算法python实现

压缩感知重构算法之SP算法python实现

压缩感知重构算法之IHT算法python实现

压缩感知重构算法之OLS算法python实现

压缩感知重构算法之IRLS算法python实现

IRLS(iteratively reweighted least squares)算法

(本文给出的代码未进行优化,只是为了说明算法流程 ,所以运行速度不是很快)

IRLS(iteratively reweighted least squares)算法是压缩感知重建算法当中的一个基本算法。主要是为了解决

minu||u||pp, subject to Φu=b

本文采用的代码是加入权重之后的

minu∑i=1Nwiu2i, subject to Φu=b

上式中的权重wi是根据前面一次ui−1计算得到的,具体的计算公式为:

wi=|u(n−1)i|p−2

这样上面的最优化问题可以求解得到:

u(n)=QnΦT(ΦQnΦT)−1b

其中Qn是一个对角矩阵,具体值从1/wi=|u(n−1)i|2−p得到。详细具体的解释请看参考文献1。


代码

要利用python实现,电脑必须安装以下程序

  • python (本文用的python版本为3.5.1)
  • numpy python包(本文用的版本为1.10.4)
  • scipy python包(本文用的版本为0.17.0)
  • pillow python包(本文用的版本为3.1.1)

python代码

#coding: utf-8
'''
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# DCT基作为稀疏基,重建算法为OMP算法 ,图像按列进行处理
# email:ncuzhangben@qq.com,
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'''
#导入集成库
import math # 导入所需的第三方库文件
import numpy as np #对应numpy包
from PIL import Image #对应pillow包 #读取图像,并变成numpy类型的 array
im = np.array(Image.open('lena.bmp'))
#print (im.shape, im.dtype)uint8 #生成高斯随机测量矩阵
sampleRate = 0.7 #采样率
Phi = np.random.randn(256, 256)
u, s, vh = np.linalg.svd(Phi)
Phi = u[:256*sampleRate,] #将测量矩阵正交化 #生成稀疏基DCT矩阵
mat_dct_1d=np.zeros((256,256))
v=range(256)
for k in range(0,256):
dct_1d=np.cos(np.dot(v,k*math.pi/256))
if k>0:
dct_1d=dct_1d-np.mean(dct_1d)
mat_dct_1d[:,k]=dct_1d/np.linalg.norm(dct_1d) #随机测量
img_cs_1d=np.dot(Phi,im) #IRLS算法函数
def cs_irls(y,T_Mat):
L=math.floor((y.shape[0])/4)
hat_x_tp=np.dot(T_Mat.T ,y)
epsilong=1
p=1 # solution for l-norm p
times=1
while (epsilong>10e-9) and (times<L): #迭代次数
weight=(hat_x_tp**2+epsilong)**(p/2-1)
Q_Mat=np.diag(1/weight)
#hat_x=Q_Mat*T_Mat'*inv(T_Mat*Q_Mat*T_Mat')*y
temp=np.dot(np.dot(T_Mat,Q_Mat),T_Mat.T)
temp=np.dot(np.dot(Q_Mat,T_Mat.T),np.linalg.inv(temp))
hat_x=np.dot(temp,y)
if(np.linalg.norm(hat_x-hat_x_tp,2) < np.sqrt(epsilong)/100):
epsilong = epsilong/10
hat_x_tp=hat_x
times=times+1
return hat_x #重建
sparse_rec_1d=np.zeros((256,256)) # 初始化稀疏系数矩阵
Theta_1d=np.dot(Phi,mat_dct_1d) #测量矩阵乘上基矩阵
for i in range(256):
print('正在重建第',i,'列。。。')
column_rec=cs_irls(img_cs_1d[:,i],Theta_1d) #利用IRLS算法计算稀疏系数
sparse_rec_1d[:,i]=column_rec;
img_rec=np.dot(mat_dct_1d,sparse_rec_1d) #稀疏系数乘上基矩阵 #显示重建后的图片
image2=Image.fromarray(img_rec)
image2.show()

matlab代码

%matlab版本用的R2010b
function Demo_CS_IRLS()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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: R. Chartrand and W. Yin, “Iteratively Reweighted Algorithms
% for Compressed Sensing,” 2008.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %------------ read in the image --------------
img=imread('lena.bmp'); % testing image
img=double(img);
[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 = Phi./repmat(sqrt(sum(Phi.^2,1)),[floor(height/3),1]); % normalize each column 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 %--------- projection ---------
img_cs_1d=Phi*img; % treat each column as a independent signal %-------- recover using omp ------------
sparse_rec_1d=zeros(height,width);
Theta_1d=Phi*mat_dct_1d;
for i=1:width
column_rec=cs_irls(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 %------------ show the results --------------------
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')) %****************************************
function hat_x=cs_irls(y,T_Mat,m)
% y=T_Mat*x, T_Mat is n-by-m
% y - measurements
% T_Mat - combination of random matrix and sparse representation basis
% m - size of the original signal
% the sparsity is length(y)/4 hat_x_tp=T_Mat'*y;
epsilong=1;
p=1; % solution for l-norm p
times=1;
while (epsilong>10e-9) && (times<length(y)/4)
weight=(hat_x_tp.^2+epsilong).^(p/2-1);
Q_Mat=diag(1./weight,0);
hat_x=Q_Mat*T_Mat'*inv(T_Mat*Q_Mat*T_Mat')*y;
if(norm(hat_x-hat_x_tp,2) < sqrt(epsilong)/100)
epsilong=epsilong/10;
end
hat_x_tp=hat_x;
times=times+1;
end

参考文献

1、R. Chartrand and W. Yin, “Iteratively Reweighted Algorithms for Compressed Sensing,” 2008.

欢迎python爱好者加入:学习交流群 667279387

压缩感知重构算法之IRLS算法python实现的更多相关文章

  1. 压缩感知重构算法之OLS算法python实现

    压缩感知重构算法之OMP算法python实现 压缩感知重构算法之CoSaMP算法python实现 压缩感知重构算法之SP算法python实现 压缩感知重构算法之IHT算法python实现 压缩感知重构 ...

  2. 压缩感知重构算法之CoSaMP算法python实现

    压缩感知重构算法之OMP算法python实现 压缩感知重构算法之CoSaMP算法python实现 压缩感知重构算法之SP算法python实现 压缩感知重构算法之IHT算法python实现 压缩感知重构 ...

  3. 压缩感知重构算法之IHT算法python实现

    压缩感知重构算法之OMP算法python实现 压缩感知重构算法之CoSaMP算法python实现 压缩感知重构算法之SP算法python实现 压缩感知重构算法之IHT算法python实现 压缩感知重构 ...

  4. 压缩感知重构算法之SP算法python实现

    压缩感知重构算法之OMP算法python实现 压缩感知重构算法之CoSaMP算法python实现 压缩感知重构算法之SP算法python实现 压缩感知重构算法之IHT算法python实现 压缩感知重构 ...

  5. 压缩感知重构算法之OMP算法python实现

    压缩感知重构算法之OMP算法python实现 压缩感知重构算法之CoSaMP算法python实现 压缩感知重构算法之SP算法python实现 压缩感知重构算法之IHT算法python实现 压缩感知重构 ...

  6. 浅谈压缩感知(三十一):压缩感知重构算法之定点连续法FPC

    主要内容: FPC的算法流程 FPC的MATLAB实现 一维信号的实验与结果 基于凸优化的重构算法 基于凸优化的压缩感知重构算法. 约束的凸优化问题: 去约束的凸优化问题: 在压缩感知中,J函数和H函 ...

  7. 浅谈压缩感知(三十):压缩感知重构算法之L1最小二乘

    主要内容: l1_ls的算法流程 l1_ls的MATLAB实现 一维信号的实验与结果 前言 前面所介绍的算法都是在匹配追踪算法MP基础上延伸的贪心算法,从本节开始,介绍基于凸优化的压缩感知重构算法. ...

  8. 浅谈压缩感知(二十八):压缩感知重构算法之广义正交匹配追踪(gOMP)

    主要内容: gOMP的算法流程 gOMP的MATLAB实现 一维信号的实验与结果 稀疏度K与重构成功概率关系的实验与结果 一.gOMP的算法流程 广义正交匹配追踪(Generalized OMP, g ...

  9. 浅谈压缩感知(二十六):压缩感知重构算法之分段弱正交匹配追踪(SWOMP)

    主要内容: SWOMP的算法流程 SWOMP的MATLAB实现 一维信号的实验与结果 门限参数a.测量数M与重构成功概率关系的实验与结果 SWOMP与StOMP性能比较 一.SWOMP的算法流程 分段 ...

随机推荐

  1. pscp命令详解

    注意:只能在winds下执行 环境准备 1.先下载pscp软件,这里是我的云盘地址: 链接:https://pan.baidu.com/s/1mkzRMv-aosC94KbMcMea9w 提取码:k0 ...

  2. 接口测试专题(Java & jmeter & Linux基础)

    以下是我和两个朋友原创文章合集,主题是接口测试,有Java接口测试案例和jmeter的案例,还有接口测试相关服务器操作基础.欢迎点赞.关注和转发. 接口测试 httpclient处理多用户同时在线 h ...

  3. [LC]783题 二叉搜索树结点最小距离(中序遍历)

    ①题目 给定一个二叉搜索树的根结点 root, 返回树中任意两节点的差的最小值. 示例: 输入: root = [4,2,6,1,3,null,null]输出: 1解释:注意,root是树结点对象(T ...

  4. go中的数据结构通道-channel

    1. channel的使用 很多文章介绍channel的时候都和并发揉在一起,这里我想把它当做一种数据结构来单独介绍它的实现原理. channel,通道.golang中用于数据传递的一种数据结构.是g ...

  5. Worktile正式发布全新研发产品!

    经过近一年时间的打磨,Worktile研发产品正式发布啦!和以往Worktile版本升级不同的是,这是一个全新的产品形态,目前已上线 Agile(敏捷开发).Pipe(持续交付).Testhub(测试 ...

  6. java编程思想第四版第九章习题

    第三题 package net.mindview.interfaces; abstract class Base{ public Base(){ print(); } abstract void pr ...

  7. package.json文件内容介绍

    概述 每个项目的根目录下面,一般都有一个package.json文件,定义了这个项目所需要的各种模块,以及项目的配置信息(比如名称.版本.许可证等元数据).npm install命令根据这个配置文件, ...

  8. Kali Rolling 系统配置总结 (Updateing)

    主系统Kali Linux确实好用,继<Kali~2018安装后的配置>之后,自己又全面详细的总结了关于Kali Linux系统安装后的配置,<Kali Rolling 系统配置总结 ...

  9. React入门知识点清单

    做前端的一定都知道现在是三大框架--Vue.React.Angular三足鼎立的时代.Vue是公认的最容易入门的,因为它文件结构上有传统的HTML的影子,让刚接触它的前端人员刚到很"亲切&q ...

  10. AV时间戳dts,pts。从ffmpeg解码过程看过来。

    解码过程中,dts由媒体流读入的包推动(解码包中的dts标记),dts在前进.pts是在dts前进到某处(截点)而进行动作的标记. 物理时间自然流逝,dts可以被控制同步与物理时间同一脚步节奏,也可以 ...