├── 3DCS ├── algorithms │ ├── gap.m │ ├── gap2d.m │ ├── gap3d.m │ ├── gap_tv.m │ ├── gap_tv3d.m │ ├── gentv3dop.m │ ├── gentvop.m │ ├── gpsr.m │ ├── tv.m │ ├── tv3d.m │ └── tvdenoising.m ├── packages │ ├── TVAL3_beta2.4 │ │ ├── Demos │ │ │ ├── demo_DFT.m │ │ │ ├── demo_barbara.m │ │ │ ├── demo_complex.m │ │ │ └── demo_phantom.m │ │ ├── Fast_Walsh_Hadamard_Transform │ │ │ ├── fWHtrans.cpp │ │ │ ├── fWHtrans.mexa64 │ │ │ ├── fWHtrans.mexmaci │ │ │ ├── fWHtrans.mexmaci64 │ │ │ ├── fWHtrans.mexw32 │ │ │ ├── fWHtrans.mexw64 │ │ │ ├── ifWHtrans.m │ │ │ ├── newFWHTcmp.fig │ │ │ └── readme.txt │ │ ├── Solver │ │ │ ├── TVAL3.m │ │ │ ├── ftvcs_al_TVL2p.m │ │ │ ├── ftvcs_al_TVL2p_old.m │ │ │ ├── ftvcs_al_opts.m │ │ │ ├── ftvcs_alp.m │ │ │ ├── ftvcs_alp_old.m │ │ │ └── readme.txt │ │ ├── User_Guide.pdf │ │ ├── Utilities │ │ │ ├── A_fWH.m │ │ │ ├── At_fWH.m │ │ │ ├── Fp1d.m │ │ │ ├── Fp2d.m │ │ │ ├── FpT1d.m │ │ │ ├── FpT2d.m │ │ │ ├── MRImask.m │ │ │ ├── ScaleA.m │ │ │ ├── Scaleb.m │ │ │ ├── barbara256.tif │ │ │ ├── defDDt.m │ │ │ ├── f_handleA.m │ │ │ ├── getA.m │ │ │ └── isinInterval.m │ │ ├── demo.m │ │ └── warm_up.m │ ├── YUV2Image │ │ ├── clipValue.m │ │ ├── conversion.mat │ │ ├── convertRgbToYuv.m │ │ ├── convertYuvToRgb.m │ │ ├── loadFileYuv.m │ │ └── saveFileYuv.m │ ├── readme.md │ ├── wavelet │ │ ├── GAP_3D_wL21_grayscale.m │ │ ├── MakeONFilter.m │ │ ├── formhg.m │ │ ├── get_waveletMatrix.m │ │ ├── my_get_weight3d.m │ │ ├── my_get_weight3d_3dtree_exp.m │ │ ├── my_get_weight3d_exp.m │ │ ├── my_get_weight3d_tree.m │ │ ├── my_get_weight3d_tree_exp.m │ │ ├── myfastinvtransform3_givenT.m │ │ ├── myfasttransform3_givenT.m │ │ └── run_gap_cassi.m │ └── yuv2mov │ │ └── yuv2mov.m ├── readme.md ├── scenes │ ├── dynamic │ │ └── noise_free │ │ │ └── foreman.yuv │ └── static │ │ ├── angrybird.jpg │ │ ├── angrybird64.png │ │ ├── barbara.png │ │ ├── fire.jpg │ │ ├── gi.png │ │ ├── house.png │ │ ├── phantom.png │ │ └── siemens.png ├── tests │ ├── cs.m │ ├── cs3d.m │ ├── gendata.m │ ├── gendata3d.m │ ├── testcs.m │ ├── testcs3d.m │ ├── testcs3dexp.m │ ├── testcs3dsamprate.m │ ├── testcs3dtab.m │ ├── testcsmhsm.m │ ├── testcstab.m │ ├── testell1samprate.m │ ├── testell1sparsity.m │ ├── testfunc.m │ ├── testgap.m │ └── testgap3d.m └── utils │ ├── fm_3dcs.m │ ├── fm_cassi.m │ ├── fm_cs.m │ ├── fmt_3dcs.m │ ├── fmt_cassi.m │ ├── fmt_cs.m │ ├── getallfiles.m │ ├── haarmtx.m │ ├── imnorm.m │ ├── imreadallfmt.m │ ├── savevideoframes.m │ ├── setdefault.m │ └── sparcons.m ├── GPSR ├── GPSR_6.0 │ ├── .DS_Store │ ├── Camera.tif │ ├── GPSR_BB.m │ ├── GPSR_Basic.m │ ├── IST.m │ ├── README.txt │ ├── demo_continuation.m │ ├── demo_image_deblur.m │ ├── figure_4.m │ ├── figure_5.m │ ├── figure_6.m │ ├── figures_1_2_3.m │ ├── immi1.mat │ └── l1_ls.m └── bak │ └── GPSR_6.0.zip ├── ISTA&FISTA └── simple_implementation │ ├── cs_fista.m │ ├── cs_ista.m │ └── test_main.m ├── NESTA_v1.1 ├── Analysis │ ├── PsiTransposeWFF.m │ ├── PsiWFF.m │ ├── analyze_tests.m │ ├── hadamard.c │ ├── hadamard.m │ ├── hadamard.map │ ├── hadamard.mexa64 │ ├── hadamard.mexglx │ ├── hadamard.mexmac │ ├── hadamard.mexmaci │ ├── hadamard.mexw32 │ ├── makeSnr.m │ ├── make_window.m │ ├── pulseTrain.m │ ├── radar_signal.m │ ├── run_tests.m │ └── use_pulseTrain.m ├── Core_Nesterov.m ├── Core_Nesterov_UP.m ├── DemoAnalysis.m ├── DemoComplex.m ├── DemoContinuation.m ├── DemoContinuation.m~ ├── DemoNonProjector.m ├── DemoReweighting.m ├── DemoReweighting.m~ ├── DemoTV.m ├── DemoTV_UP.m ├── DemoUP.m ├── DemoUP.m~ ├── Misc │ ├── A_Subset.m │ ├── A_f.m │ ├── A_fhp.m │ ├── At_Subset.m │ ├── At_f.m │ ├── At_fhp.m │ ├── CGwrapper.m │ ├── LSQRwrapper.m │ ├── LineMask.m │ ├── MakeRDSquares.m │ ├── calctv.m │ ├── counter.m │ ├── msp_signal.m │ └── my_normest.m ├── NESTA.m ├── NESTA.m~ ├── NESTA_UP.m ├── NESTA_UP.m~ ├── RecPF_v1.1 │ ├── .DS_Store │ ├── demo_RecPF.m │ ├── images │ │ ├── ortho1.jpg │ │ ├── ortho2.jpg │ │ ├── ortho3.jpg │ │ ├── ortho4.jpg │ │ ├── ortho5.jpg │ │ └── ortho6.jpg │ ├── readme.txt │ ├── solver │ │ ├── RecPF.asv │ │ ├── RecPF.m │ │ ├── RecPF_Modified.m │ │ └── RecPF_Modified.m~ │ └── utilities │ │ ├── MRImask.m │ │ ├── Wavedb1Phi.m │ │ ├── dctPhi.m │ │ ├── funcval.m │ │ ├── identityPhi.m │ │ ├── selectPF.m │ │ └── snr.m ├── Setup_Nesta.m ├── changeLog.txt └── fastProjection.m ├── OMP_SP_IHT_CoSaMP_GBP_IRLS ├── CS Recovery Algorithms.pdf ├── OMP_SP_IHT_CoSaMP_GBP_IRLS │ ├── Demo_CS_CoSaMP.m │ ├── Demo_CS_GBP.m │ ├── Demo_CS_IHT.m │ ├── Demo_CS_IRLS.m │ ├── Demo_CS_OMP.m │ ├── Demo_CS_SP.m │ └── lena.bmp └── bak │ └── CS_recovery_algorithms_OMP_SP_IHT_CoSaMP_GBP_IRLS.rar ├── README.md ├── SLOPE_code ├── Adlas.R ├── Adlas.m ├── README ├── cproxSortedL1.c ├── data │ ├── testData_A.txt │ ├── testData_b.txt │ ├── testData_lambda.txt │ └── testData_x0.txt ├── doc │ ├── SLOPE.pdf │ └── SortedL1_SM.pdf ├── gpl-3.0.txt ├── makemex.m ├── proxSortedL1.R ├── proxSortedL1.c ├── proxSortedL1.h ├── proxSortedL1.m ├── proxSortedL1Mex.c ├── test.txt ├── testAdlas.R └── testAdlas.m ├── TVAL3_beta2.4 ├── Demos │ ├── demo_DFT.m │ ├── demo_barbara.m │ ├── demo_complex.m │ └── demo_phantom.m ├── Fast_Walsh_Hadamard_Transform │ ├── fWHtrans.cpp │ ├── fWHtrans.mexa64 │ ├── fWHtrans.mexmaci │ ├── fWHtrans.mexmaci64 │ ├── fWHtrans.mexw32 │ ├── fWHtrans.mexw64 │ ├── ifWHtrans.m │ ├── newFWHTcmp.fig │ └── readme.txt ├── Solver │ ├── TVAL3.m │ ├── ftvcs_al_TVL2p.m │ ├── ftvcs_al_TVL2p_old.m │ ├── ftvcs_al_opts.m │ ├── ftvcs_alp.m │ ├── ftvcs_alp_old.m │ └── readme.txt ├── User_Guide.pdf ├── Utilities │ ├── A_fWH.m │ ├── At_fWH.m │ ├── Fp1d.m │ ├── Fp2d.m │ ├── FpT1d.m │ ├── FpT2d.m │ ├── MRImask.m │ ├── ScaleA.m │ ├── Scaleb.m │ ├── barbara256.tif │ ├── defDDt.m │ ├── f_handleA.m │ ├── getA.m │ └── isinInterval.m ├── demo.m └── warm_up.m ├── TwIST ├── TwIST_v2 │ ├── MRImask.m │ ├── README.txt │ ├── TVnorm.m │ ├── TwIST.m │ ├── conv2c.m │ ├── demo_MRI.m │ ├── demo_Piecewise_cubic_polynomial.m │ ├── demo_l2_TV.m │ ├── demo_l2_l0.m │ ├── demo_l2_l1.m │ ├── demo_l2_l1_debias.m │ ├── demo_sinusoids_l2_l1.m │ ├── demo_wave_DWT_deconv.m │ ├── diffh.m │ ├── diffv.m │ ├── hard.m │ ├── l0norm.m │ ├── masked_FFT.m │ ├── masked_FFT_t.m │ ├── mex_vartotale.dll │ ├── mex_vartotale.m │ ├── soft.m │ └── tvdenoise.m └── bak │ └── TwIST_v2.zip ├── [ToolBox] ├── .gitkeep └── ksvdbox&omp │ ├── bak │ ├── ksvdbox13.zip │ ├── ksvdsbox11-min.zip │ ├── ksvdsbox11.zip │ ├── ompbox10.zip │ ├── ompsbox1.zip │ └── readme.html │ ├── ksvdbox13 │ ├── Contents.m │ ├── faq.txt │ ├── images │ │ ├── barbara.png │ │ ├── boat.png │ │ ├── house.png │ │ ├── lena.png │ │ └── peppers.png │ ├── ksvd.m │ ├── ksvddemo.m │ ├── ksvddenoise.m │ ├── ksvddenoisedemo.m │ ├── ksvdver.m │ ├── odct2dict.m │ ├── odct3dict.m │ ├── odctdict.m │ ├── odctndict.m │ ├── ompdenoise.m │ ├── ompdenoise1.m │ ├── ompdenoise2.m │ ├── ompdenoise3.m │ ├── private │ │ ├── add_dc.m │ │ ├── addtocols.c │ │ ├── addtocols.m │ │ ├── col2imstep.c │ │ ├── col2imstep.m │ │ ├── collincomb.c │ │ ├── collincomb.m │ │ ├── countcover.m │ │ ├── dictdist.m │ │ ├── im2colstep.c │ │ ├── im2colstep.m │ │ ├── imnormalize.m │ │ ├── iswhole.m │ │ ├── make.m │ │ ├── mexutils.c │ │ ├── mexutils.h │ │ ├── normcols.m │ │ ├── printf.m │ │ ├── reggrid.m │ │ ├── remove_dc.m │ │ ├── rowlincomb.c │ │ ├── rowlincomb.m │ │ ├── sampgrid.m │ │ ├── secs2hms.m │ │ ├── spdiag.m │ │ ├── sprow.c │ │ ├── sprow.m │ │ ├── timerclear.m │ │ ├── timereta.m │ │ └── timerinit.m │ ├── readme.txt │ └── showdict.m │ ├── ksvdsbox11 │ ├── Contents.m │ ├── ksvds.m │ ├── ksvdsdenoise.m │ ├── ksvdsdenoisedemo.m │ ├── ksvdsver.m │ ├── ompsdenoise.m │ ├── ompsdenoise2.m │ ├── ompsdenoise3.m │ ├── private │ │ ├── add_dc.m │ │ ├── addtocols.c │ │ ├── addtocols.m │ │ ├── col2imstep.c │ │ ├── col2imstep.m │ │ ├── collincomb.c │ │ ├── collincomb.m │ │ ├── countcover.m │ │ ├── im2colstep.c │ │ ├── im2colstep.m │ │ ├── imnormalize.m │ │ ├── iswhole.m │ │ ├── make.m │ │ ├── mexutils.c │ │ ├── mexutils.h │ │ ├── odctdict.m │ │ ├── printf.m │ │ ├── reggrid.m │ │ ├── remove_dc.m │ │ ├── rowlincomb.c │ │ ├── rowlincomb.m │ │ ├── sampgrid.m │ │ ├── secs2hms.m │ │ ├── showdict.m │ │ ├── sprow.c │ │ ├── sprow.m │ │ ├── timerclear.m │ │ ├── timereta.m │ │ └── timerinit.m │ ├── readme.txt │ └── volumes │ │ ├── vf-ankle.mat │ │ └── vm-head.mat │ ├── ompbox10 │ ├── Contents.m │ ├── faq.txt │ ├── omp.m │ ├── omp2.m │ ├── ompdemo.m │ ├── ompspeedtest.m │ ├── ompver.m │ ├── private │ │ ├── make.m │ │ ├── mexutils.c │ │ ├── mexutils.h │ │ ├── myblas.c │ │ ├── myblas.h │ │ ├── omp2mex.c │ │ ├── omp2mex.m │ │ ├── ompcore.c │ │ ├── ompcore.h │ │ ├── ompmex.c │ │ ├── ompmex.m │ │ ├── ompprof.c │ │ ├── ompprof.h │ │ ├── omputils.c │ │ ├── omputils.h │ │ └── printf.m │ └── readme.txt │ ├── ompsbox1 │ ├── Contents.m │ ├── dictsep.m │ ├── dicttsep.m │ ├── faq.txt │ ├── normdictsep.m │ ├── omps.m │ ├── omps2.m │ ├── ompspeedcompare.m │ ├── ompsver.m │ ├── private │ │ ├── dictsepmex.c │ │ ├── dictsepmex.m │ │ ├── dicttsepmex.c │ │ ├── dicttsepmex.m │ │ ├── make.m │ │ ├── mexutils.c │ │ ├── mexutils.h │ │ ├── myblas.c │ │ ├── myblas.h │ │ ├── ompprof.c │ │ ├── ompprof.h │ │ ├── omps2mex.c │ │ ├── omps2mex.m │ │ ├── ompscore.c │ │ ├── ompscore.h │ │ ├── ompsmex.c │ │ ├── ompsmex.m │ │ ├── omputils.c │ │ ├── omputils.h │ │ ├── printf.m │ │ ├── sparsedict.c │ │ └── sparsedict.h │ ├── readme.txt │ └── sparsedict.m │ └── ref_paper │ ├── KSVD-OMP-v2.pdf │ └── sparsedict.pdf └── l1magic ├── .DS_Store ├── Data ├── .DS_Store ├── RandomStates.mat ├── boats.mat └── camera.mat ├── Measurements ├── .DS_Store ├── A_f.m ├── A_fhp.m ├── At_f.m ├── At_fhp.m └── LineMask.m ├── Notes ├── .DS_Store ├── Figs │ ├── CVS │ │ ├── Entries │ │ ├── Repository │ │ └── Root │ ├── l1eqexample_minl2.eps │ ├── l1eqexample_minl2.pdf │ ├── l1eqexample_recovered.eps │ ├── l1eqexample_recovered.pdf │ ├── l1eqexample_signal.eps │ ├── l1eqexample_signal.pdf │ ├── phantom_backproj.eps │ ├── phantom_backproj.pdf │ ├── phantom_orig.eps │ ├── phantom_orig.pdf │ ├── phantom_sampling.eps │ ├── phantom_sampling.pdf │ ├── phantom_tv.eps │ └── phantom_tv.pdf ├── l1magic.bib ├── l1magic_notes.aux ├── l1magic_notes.bbl ├── l1magic_notes.blg ├── l1magic_notes.log ├── l1magic_notes.pdf └── l1magic_notes.tex ├── Optimization ├── .DS_Store ├── cgsolve.m ├── l1dantzig_pd.m ├── l1decode_pd.m ├── l1eq_pd.m ├── l1qc_logbarrier.m ├── l1qc_newton.m ├── tvdantzig_logbarrier.m ├── tvdantzig_newton.m ├── tveq_logbarrier.m ├── tveq_newton.m ├── tvqc_logbarrier.m └── tvqc_newton.m ├── README ├── l1dantzig_example.m ├── l1decode_example.m ├── l1eq_example.m ├── l1qc_example.m ├── tvdantzig_example.m ├── tveq_example.m ├── tveq_phantom_example.m ├── tvqc_example.m └── tvqc_quantization_example.m /3DCS/algorithms/gap_tv3d.m: -------------------------------------------------------------------------------- 1 | function [ x_3d ] = gap_tv3d( y,A_fun,At_fun,params ) 2 | %GAP_TV3D Total variation (TV)-based generalized alternating projection 3 | %method in three dimensions (3D). 4 | % x_3d=GAP_TV3D(y,A_fun,At_fun,params) returns the reconstructed three 5 | % dimensional volume x_3d, which follows the forward model of three 6 | % dimensional compressive sensing (3DCS) scheme i.e. y=A_fun(x_3d), where 7 | % A_fun is the forward model of three dimensional compressive sensing 8 | % FM_3DCS, y is the M-by-F measurement matrix, x_3d is the (m-by-n)-by-F 9 | % three dimensional signal, and params are the parameters used in the 10 | % algorithm. 11 | % [model] 12 | % min |TV_3(x_3d)|_1 13 | % s.t. y=A_fun(x_3d) 14 | % See also TVDENOISING, CS3D. 15 | 16 | % [0] parameters configuration 17 | lambda = params.lambda; 18 | tvweight = params.tvweight; 19 | tviter = params.tviter; 20 | maxiter = params.maxiter; 21 | 22 | rows = params.rows; 23 | cols = params.cols; 24 | nframe = params.nframe; 25 | 26 | Phi_sum = A_fun(At_fun(ones(size(y)))); % [cs] replaced by function handle 27 | 28 | % [1] initialization 29 | theta_3d = At_fun(y); 30 | yt = zeros(size(y)); 31 | for iter = 1:maxiter 32 | yb = A_fun(reshape(theta_3d,[rows*cols,nframe])); 33 | if(params.acc) 34 | yt = yt + (y-yb); 35 | theta_3d = theta_3d + lambda.*At_fun((yt-yb)./Phi_sum); 36 | else 37 | theta_3d = theta_3d + lambda.*At_fun((y-yb)./Phi_sum); 38 | end 39 | % TV denoising-based update of theta 40 | theta_3d = tvdenoising(theta_3d,tvweight,tviter); 41 | end 42 | 43 | x_3d = theta_3d; 44 | 45 | end 46 | 47 | -------------------------------------------------------------------------------- /3DCS/algorithms/gentv3dop.m: -------------------------------------------------------------------------------- 1 | function [ H, intraH, interH ] = gentv3dop( row,col,nChannel ) 2 | %GENTV3DOP generate discrete gradient operator matrix for three dimensional 3 | %total variation (TV) regularization. 4 | % H -- gradient operator 5 | % See also TV3D, GENTVOP. 6 | 7 | if nargin <3 8 | nChannel = 1; 9 | end 10 | 11 | h1=[-1,1]; 12 | h2=[-1;1]; 13 | h3=[1,-2,1]; 14 | h4=[1;-2;1]; 15 | h5=[-1,1;1,-1]; 16 | % H1 17 | H1=zeros(col*(row-1),col*row); 18 | for x=1:col 19 | for y=1:row-1 20 | H1(x+(y-1)*col,x+(y-1)*col)=h1(1); 21 | H1(x+(y-1)*col,x+y*col)=h1(2); 22 | end 23 | end 24 | H1=sparse(H1); 25 | % H2 26 | H2=zeros((col-1)*row,col*row); 27 | for x=1:col-1 28 | for y=1:row 29 | H2(x+(y-1)*(col-1),x+(y-1)*col)=h2(1); 30 | H2(x+(y-1)*(col-1),x+1+(y-1)*col)=h2(2); 31 | end 32 | end 33 | H2=sparse(H2); 34 | % H3 35 | H3=zeros(col*(row-2),col*row); 36 | for x=1:col 37 | for y=1:row-2 38 | H3(x+(y-1)*col,x+(y-1)*col)=h3(1); 39 | H3(x+(y-1)*col,x+y*col)=h3(2); 40 | H3(x+(y-1)*col,x+(y+1)*col)=h3(3); 41 | end 42 | end 43 | H3=sparse(H3); 44 | % H4 45 | H4=zeros((col-2)*row,col*row); 46 | for x=1:col-2 47 | for y=1:row 48 | H4(x+(y-1)*(col-2),x+(y-1)*col)=h4(1); 49 | H4(x+(y-1)*(col-2),x+1+(y-1)*col)=h4(2); 50 | H4(x+(y-1)*(col-2),x+2+(y-1)*col)=h4(3); 51 | end 52 | end 53 | H4=sparse(H4); 54 | % H5 55 | H5=zeros((col-1)*(row-1),col*row); 56 | for x=1:col-1 57 | for y=1:row-1 58 | H5(x+(y-1)*(col-1),x+(y-1)*col)=h5(1); 59 | H5(x+(y-1)*(col-1),x+1+(y-1)*col)=h5(2); 60 | H5(x+(y-1)*(col-1),x+y*col)=h5(3); 61 | H5(x+(y-1)*(col-1),x+1+y*col)=h5(4); 62 | end 63 | end 64 | H5=sparse(H5); 65 | 66 | % H=[H1;H2;H3;H4;H5]; 67 | H = [H1;H2]; 68 | % H = kron(eye(nChannel),H); 69 | H = repmat(H, 1 ,nChannel); 70 | intraH = H; 71 | 72 | H6 = zeros(col*row*(nChannel-1), col*row*nChannel); 73 | for x = 1:size(H6,1) 74 | H6(x,x)=-1; 75 | H6(x,x+col*row)=1; 76 | end 77 | interH = H6; 78 | 79 | H = [H;H6]; 80 | 81 | end -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexa64 -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexmaci -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexmaci64 -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexw32 -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexw64 -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/ifWHtrans.m: -------------------------------------------------------------------------------- 1 | function Y = ifWHtrans(X) 2 | % ifWHtrans computes fast inverse discrete Walsh-Hadamard transform 3 | % with sequency order. 4 | % 5 | % Since the forward and inverse transforms are exactly identical 6 | % operations, fastWHtrans.mexw32 is used to perform inverse transform. 7 | % 8 | % written by: Chengbo Li 9 | % Computational and Applied Mathematics Department, Rice University. 10 | % 02/15/2010 11 | 12 | Y = fWHtrans(X); 13 | % Perform scaling 14 | [m, n] = size(Y); 15 | Y = Y .* m; 16 | -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/newFWHTcmp.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/packages/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/newFWHTcmp.fig -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Solver/TVAL3.m: -------------------------------------------------------------------------------- 1 | function [U,out] = TVAL3(A,b,p,q,opts) 2 | % Accordingly choose the code based on the model selected by the user. 3 | % 4 | % 1) TV model: min sum ||D_i u||. 5 | % s.t. Au = b 6 | % 2) TV/L2 model: min sum ||D_i u|| + mu/2||Au-b||_2^2 7 | % 8 | % Please use the default one if the user doesn't have a specific model to 9 | % solver. 10 | % 11 | % Written by: Chengbo Li 12 | % Advisor: Prof. Yin Zhang and Wotao Yin 13 | % Computational and Applied Mathematics department, Rice University 14 | % May. 15, 2009 15 | 16 | if ~isfield(opts,'TVL2') 17 | opts.TVL2 = false; 18 | end 19 | 20 | if opts.TVL2 21 | [U, out] = ftvcs_al_TVL2p(A,b,p,q,opts); 22 | else 23 | [U, out] = ftvcs_alp(A,b,p,q,opts); 24 | end -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/User_Guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/packages/TVAL3_beta2.4/User_Guide.pdf -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/A_fWH.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % 3 | % A_fWH 4 | % 5 | % Written by: Chengbo Li 6 | % CAAM, Rice University 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | function b = A_fWH(x, OMEGA, P) 9 | 10 | 11 | N = length(x); 12 | 13 | x = x(:); 14 | fx = fWHtrans(x(P))*sqrt(N); 15 | b = fx(OMEGA); -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/At_fWH.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % 3 | % At_fWH 4 | % 5 | % Written by: Chengbo Li 6 | % CAAM, Rice University 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | function x = At_fWH(b, OMEGA, P) 9 | 10 | N = length(P); 11 | fx = zeros(N,1); 12 | fx(OMEGA) = b/sqrt(N); 13 | x = zeros(N,1); 14 | tmp = ifWHtrans(fx); 15 | x(P) = tmp(1:N); -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/Fp1d.m: -------------------------------------------------------------------------------- 1 | function Fpx = Fp1d(x,picks,n) 2 | 3 | [p,q] = size(x); 4 | msg = 'size of x not correct in Fp.m'; 5 | 6 | if q ~= 1 || p ~= n 7 | error(msg); 8 | end 9 | 10 | Fx = fft(x); 11 | Fx = Fx(picks); 12 | Fpx = [real(Fx); imag(Fx)]; -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/Fp2d.m: -------------------------------------------------------------------------------- 1 | function Fpx = Fp2d(x,picks,m,n) 2 | 3 | [p,q] = size(x); 4 | msg = 'size of x not correct in Fp2d.m'; 5 | 6 | if q == 1 7 | if p ~= (m*n) 8 | error(msg); 9 | else 10 | x = reshape(x,[m,n]); 11 | end 12 | elseif p ~= m || q ~= n 13 | error(msg); 14 | end 15 | 16 | Fx = fft2(x)/sqrt(m*n); 17 | Fx = Fx(picks); 18 | Fpx = [real(Fx); imag(Fx)]; 19 | -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/FpT1d.m: -------------------------------------------------------------------------------- 1 | function FpTy = FpT1d(y,picks,n) 2 | 3 | ly = length(y); 4 | rP = length(picks); 5 | if ly ~= 2*rP 6 | error('size not correct in FpT'); 7 | end 8 | 9 | FpTy = zeros(n,1); 10 | y = y(1:rP) + sqrt(-1)*y(rP+1:ly); 11 | FpTy(picks) = y; 12 | FpTy = real(ifft(FpTy)); -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/FpT2d.m: -------------------------------------------------------------------------------- 1 | function FpTy = FpT2d(y,picks,m,n) 2 | 3 | ly = length(y); 4 | rP = length(picks); 5 | if ly ~= 2*rP 6 | error('size not correct in FpT2d'); 7 | end 8 | 9 | FpTy = zeros(m,n); 10 | y = y(1:rP) + sqrt(-1)*y(rP+1:ly); 11 | FpTy(picks) = y; 12 | FpTy = real(ifft2(FpTy)*sqrt(m*n)); 13 | FpTy = FpTy(:); -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/MRImask.m: -------------------------------------------------------------------------------- 1 | function y = MRImask(n,beams) 2 | % 3 | % produces the fan MRI mask, of size n*n, 4 | % beams is the number of angles 5 | % 6 | m = ceil(sqrt(2)*n); 7 | aux = zeros(m,m); ima = aux; 8 | aux(round(m/2+1),:) = 1; 9 | angle = 180/beams; 10 | angles = [0:angle:180-angle]; 11 | for a = 1:length(angles) 12 | ang = angles(a); 13 | a = imrotate(aux,ang,'crop'); 14 | ima = ima + a; 15 | end 16 | ima = ima(round(m/2+1) - n/2:round(m/2+1) + n/2-1,... 17 | round(m/2+1) - n/2:round(m/2+1) + n/2-1); 18 | 19 | y = (ima > 0); 20 | -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/ScaleA.m: -------------------------------------------------------------------------------- 1 | function [mu,A,b] = ScaleA(n,mu,A,b,option) 2 | 3 | % Scales mu, A and f so that the largest eigenvalue of A'*A is 1 and the 4 | % new problem 5 | % 6 | % min sum_i (||wi|| + beta/2 ||Diu - wi||^2) + mu/2 ||Au - b||^2 7 | % 8 | % is equivalent to the old one. 9 | % 10 | % If option is assigned, mu will be scaled accordingly. 11 | % 12 | % Written by: Chengbo Li 13 | 14 | eopts.disp = 0; 15 | eopts.tol = .05; 16 | if ~isreal(A(rand(n,1),1)) 17 | eopts.isreal = false; 18 | end 19 | 20 | fh = @(x) A(A(x,1),2); 21 | s2 = eigs(fh,n,1,'lm',eopts); 22 | if real(s2) > 1 + 1e-10 23 | if option 24 | mu = mu*s2; 25 | end 26 | b = b/sqrt(s2); 27 | A = @(x,mode) A(x,mode)/sqrt(s2); 28 | end 29 | 30 | return -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/Scaleb.m: -------------------------------------------------------------------------------- 1 | function [mu,b,scl] = Scaleb(mu,b,option) 2 | 3 | % Scales mu and f so that the finite difference of f is neither too small 4 | % nor too large. 5 | % 6 | % If option is assigned, mu will be scaled accordingly. 7 | % 8 | % Written by: Chengbo Li 9 | 10 | 11 | threshold1 = .5; % threshold is chosen by experience. 12 | threshold2 = 1.5; 13 | scl = 1; 14 | b_dif = abs(max(b) - min(b)); 15 | 16 | if b_dif < threshold1 17 | scl = threshold1/b_dif; 18 | b = scl*b; 19 | if option 20 | mu = mu/scl; 21 | end 22 | else if b_dif > threshold2 23 | scl = threshold2/b_dif; 24 | b = scl*b; 25 | if option 26 | mu = mu/scl; 27 | end 28 | end 29 | end 30 | 31 | return -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/barbara256.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/packages/TVAL3_beta2.4/Utilities/barbara256.tif -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/defDDt.m: -------------------------------------------------------------------------------- 1 | function [D,Dt] = defDDt 2 | 3 | D = @(U) ForwardD(U); 4 | Dt = @(X,Y) Dive(X,Y); 5 | 6 | function [Dux,Duy] = ForwardD(U) 7 | % [ux,uy] = D u 8 | 9 | Dux = [diff(U,1,2), U(:,1) - U(:,end)]; 10 | Duy = [diff(U,1,1); U(1,:) - U(end,:)]; 11 | 12 | function DtXY = Dive(X,Y) 13 | % DtXY = D_1' X + D_2' Y 14 | 15 | DtXY = [X(:,end) - X(:, 1), -diff(X,1,2)]; 16 | DtXY = DtXY + [Y(end,:) - Y(1, :); -diff(Y,1,1)]; 17 | DtXY = DtXY(:); -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/f_handleA.m: -------------------------------------------------------------------------------- 1 | function y = f_handleA(A,u,mode) 2 | 3 | switch mode 4 | case 1 5 | y = A*u; 6 | case 2 7 | y = (u'*A)'; 8 | otherwise 9 | error('Unknown mode passed to f_handleA in ftv_cs.m'); 10 | end 11 | 12 | end -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/getA.m: -------------------------------------------------------------------------------- 1 | function [A, At] = getA(m,p,q,picks,mtx,dim) 2 | 3 | if strcmp(mtx,'randn') 4 | B = randn(m,p*q); 5 | 6 | % random A -- 1 7 | [B,R] = qr(B',0); 8 | B = B'; 9 | 10 | % %% random A -- 2 11 | % d = sqrt(sum(B'.^2)); 12 | % B = sparse(1:m,1:m,1./d)*B; 13 | 14 | 15 | A = @(x) B*x; 16 | At = @(y) (y'*B)'; 17 | elseif strcmp(mtx,'PF') 18 | if dim == 2 19 | % 2D partial Fourier 20 | A = @(x) Fp2d(x,picks,p,q); 21 | At = @(y) FpT2d(y,picks,p,q); 22 | elseif dim == 1 23 | % 1D partial Fourier 24 | A = @(x) Fp1d(x,picks,p); 25 | At = @(y) FpT1d(y,picks,p); 26 | end 27 | end -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/Utilities/isinInterval.m: -------------------------------------------------------------------------------- 1 | function res = isinInterval(val,lb,ub,eok) 2 | 3 | % Checks to make sure that val is a real scalar in [lb,ub] if eok is true, 4 | % or in (lb,ub) if eok is false. 5 | 6 | res = true; 7 | 8 | if ~isscalar(val), res = false; end 9 | if ~isreal(val), res = false; end 10 | if eok 11 | if val < lb || val > ub, res = false; end 12 | else 13 | if val <= lb || val >= ub, res = false; end 14 | end 15 | 16 | return -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/demo.m: -------------------------------------------------------------------------------- 1 | % This simple demo examines if TVAL3 works normally. Please try more demos 2 | % in the "Demos" directory, which would show users what TVAL3 is capable of. 3 | % 4 | % I: 64x64 phantom (real, two-dimentional) 5 | % A: random matrix without normality and orthogonality (real) 6 | % f: observation with/without noise (real) 7 | % 8 | % Written by: Chengbo Li 9 | % Advisor: Prof. Yin Zhang and Wotao Yin 10 | % CAAM department, Rice University 11 | % 05/21/2009 12 | 13 | clear; close all; 14 | path(path,genpath(pwd)); 15 | fullscreen = get(0,'ScreenSize'); 16 | 17 | % problem size 18 | n = 64; 19 | ratio = .3; 20 | p = n; q = n; % p x q is the size of image 21 | m = round(ratio*n^2); 22 | 23 | % sensing matrix 24 | A = rand(m,p*q)-.5; 25 | 26 | % original image 27 | I = phantom(n); 28 | nrmI = norm(I,'fro'); 29 | figure('Name','TVAL3','Position',... 30 | [fullscreen(1) fullscreen(2) fullscreen(3) fullscreen(4)]); 31 | subplot(121); imshow(I,[]); 32 | title('Original phantom','fontsize',18); drawnow; 33 | 34 | % observation 35 | f = A*I(:); 36 | favg = mean(abs(f)); 37 | 38 | % add noise 39 | f = f + .00*favg*randn(m,1); 40 | 41 | 42 | %% Run TVAL3 43 | clear opts 44 | opts.mu = 2^8; 45 | opts.beta = 2^5; 46 | opts.tol = 1E-3; 47 | opts.maxit = 300; 48 | opts.TVnorm = 1; 49 | opts.nonneg = true; 50 | 51 | t = cputime; 52 | [U, out] = TVAL3(A,f,p,q,opts); 53 | t = cputime - t; 54 | 55 | 56 | subplot(122); 57 | imshow(U,[]); 58 | title('Recovered by TVAL3','fontsize',18); 59 | xlabel(sprintf(' %2d%% measurements \n Rel-Err: %4.2f%%, CPU: %4.2fs ',ratio*100,norm(U-I,'fro')/nrmI*100,t),'fontsize',16); 60 | -------------------------------------------------------------------------------- /3DCS/packages/TVAL3_beta2.4/warm_up.m: -------------------------------------------------------------------------------- 1 | % 2 | % set paths: users must make sure that all folders and subfolders 3 | % are in cluded in MATLAB working paths. This can be done either 4 | % manually or by running the following line in MATLAB command window 5 | % 6 | path(path,genpath(pwd)); 7 | if exist('fWHtrans','file') ~= 3 8 | cd Fast_Walsh_Hadamard_Transform; 9 | mex -O fWHtrans.cpp 10 | cd ..; 11 | fprintf('Finished compiling the C++ code for fast Walsh-Hadamard transform!\n'); 12 | end 13 | fprintf('Finished adding paths! Welcome to use TVAL3 beta2.4.\n'); -------------------------------------------------------------------------------- /3DCS/packages/YUV2Image/clipValue.m: -------------------------------------------------------------------------------- 1 | function val = clipValue(val, valMin, valMax) 2 | % check if value is valid 3 | 4 | for i = 1 : 1 : size(val(:)) 5 | if val(i) < valMin 6 | val(i) = valMin; 7 | elseif val(i) > valMax 8 | val(i) = valMax; 9 | end 10 | end -------------------------------------------------------------------------------- /3DCS/packages/YUV2Image/conversion.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/packages/YUV2Image/conversion.mat -------------------------------------------------------------------------------- /3DCS/packages/YUV2Image/convertRgbToYuv.m: -------------------------------------------------------------------------------- 1 | function yuv = convertRgbToYuv(rgb) 2 | % convert row vector RGB [0, 255] to row vector YUV [0, 255] 3 | 4 | load conversion.mat; 5 | 6 | rgb = double(rgb); 7 | 8 | yuv = (rgbToYuv * rgb.').'; 9 | yuv(:, 2 : 3) = yuv(:, 2 : 3) + 127; 10 | 11 | yuv = uint8(clipValue(yuv, 0, 255)); -------------------------------------------------------------------------------- /3DCS/packages/YUV2Image/convertYuvToRgb.m: -------------------------------------------------------------------------------- 1 | function rgb = convertYuvToRgb(yuv) 2 | % convert row vector YUV [0, 255] in row vector RGB [0, 255] 3 | 4 | load conversion.mat; % load conversion matrices 5 | 6 | yuv = double(yuv); 7 | 8 | yuv(:, 2 : 3) = yuv(:, 2 : 3) - 127; 9 | rgb = (yuvToRgb *yuv.').'; 10 | 11 | rgb = uint8(clipValue(rgb, 0, 255)); -------------------------------------------------------------------------------- /3DCS/packages/YUV2Image/loadFileYuv.m: -------------------------------------------------------------------------------- 1 | % function mov = loadFileYuv(fileName, width, height, idxFrame) 2 | 3 | function [mov,imgRgb] = loadFileYuv(fileName, width, height, idxFrame) 4 | % load RGB movie [0, 255] from YUV 4:2:0 file 5 | 6 | fileId = fopen(fileName, 'r'); 7 | 8 | subSampleMat = [1, 1; 1, 1]; 9 | nrFrame = length(idxFrame); 10 | 11 | for f = 1 : 1 : nrFrame 12 | % search fileId position 13 | sizeFrame = 1.5 * width * height; 14 | fseek(fileId, (idxFrame(f) - 1) * sizeFrame, 'bof'); 15 | 16 | % read Y component 17 | buf = fread(fileId, width * height, 'uchar'); 18 | imgYuv(:, :, 1) = reshape(buf, width, height).'; % reshape 19 | 20 | % read U component 21 | buf = fread(fileId, width / 2 * height / 2, 'uchar'); 22 | imgYuv(:, :, 2) = kron(reshape(buf, width / 2, height / 2).', subSampleMat); % reshape and upsample 23 | 24 | % read V component 25 | buf = fread(fileId, width / 2 * height / 2, 'uchar'); 26 | imgYuv(:, :, 3) = kron(reshape(buf, width / 2, height / 2).', subSampleMat); % reshape and upsample 27 | 28 | % normalize YUV values 29 | % imgYuv = imgYuv / 255; 30 | 31 | % convert YUV to RGB 32 | imgRgb = reshape(convertYuvToRgb(reshape(imgYuv, height * width, 3)), height, width, 3); 33 | % imgRgb = ycbcr2rgb(imgYuv); 34 | %imwrite(imgRgb,'ActualBackground.bmp','bmp'); 35 | mov(f) = im2frame(imgRgb); 36 | % mov(f).cdata = uint8(imgRgb); 37 | % mov(f).colormap = []; 38 | % imwrite(imgRgb,'ActualBackground.bmp','bmp'); 39 | 40 | %figure, imshow(imgRgb); 41 | %name = 'ActualBackground.bmp'; 42 | %Image = imread(name, 'bmp'); 43 | %figure, imshow(Image); 44 | end 45 | fclose(fileId); -------------------------------------------------------------------------------- /3DCS/packages/YUV2Image/saveFileYuv.m: -------------------------------------------------------------------------------- 1 | function saveFileYuv(mov, fileName, mode) 2 | % save RGB movie [0, 255] to YUV 4:2:0 file 3 | 4 | switch mode 5 | case 1 % replace file 6 | fileId = fopen(fileName, 'w'); 7 | case 2 % append to file 8 | fileId = fopen(fileName, 'a'); 9 | otherwise 10 | fileId = fopen(fileName, 'w'); 11 | end 12 | 13 | dim = size(mov(1).cdata); 14 | nrFrame = length(mov); 15 | 16 | for f = 1 : 1 : nrFrame 17 | imgRgb = frame2im(mov(f)); 18 | 19 | % convert YUV to RGB 20 | imgYuv = reshape(convertRgbToYuv(reshape(imgRgb, dim(1) * dim(2), 3)), dim(1), dim(2), 3); 21 | 22 | % write Y component 23 | buf = reshape(imgYuv(:, :, 1).', [], 1); % reshape 24 | count = fwrite(fileId, buf, 'uchar'); 25 | 26 | % write U component 27 | buf = reshape(imgYuv(1 : 2 : end, 1 : 2 : end, 2).', [], 1); % downsample and reshape 28 | count = fwrite(fileId, buf, 'uchar'); 29 | 30 | % write V component 31 | buf = reshape(imgYuv(1 : 2 : end, 1 : 2 : end, 3).', [], 1); % downsample and reshape 32 | count = fwrite(fileId, buf, 'uchar'); 33 | end 34 | 35 | fclose(fileId); 36 | 37 | -------------------------------------------------------------------------------- /3DCS/packages/wavelet/formhg.m: -------------------------------------------------------------------------------- 1 | function T=formhg(chpack,level,t,h,g) 2 | % FORMHG: T=formhg(chpack,level,t,h,g) 3 | % Form the transform matrix T from h and g, refer for further 4 | % details to wavede.m, by which this sub routine is called. 5 | % chpack: 1 chooses wavelet packet decomposion 6 | % 0 chooses normal wavelet decomposion 7 | % level: the length in power of 2 of input signal 8 | % t: current decomposition level 9 | % h: low-pass filter coefficients 10 | % g: high-pass filter coefficients 11 | % T: transform matrix 12 | % Copyright (c) by Xuejun Liao 13 | % December 1997 14 | 15 | H=zeros(2^t,2^t/2); G=H; 16 | for i=1:2^t/2 % form the low-pass H and high-pass filter G 17 | L=length(h); 18 | if 2^t-2*(i-1)>=L 19 | H((1+2*(i-1)):(L+2*(i-1)),i)=h; 20 | G((1+2*(i-1)):(L+2*(i-1)),i)=g; 21 | else 22 | shift=L-(2^t-2*(i-1)); 23 | H((1+2*(i-1)):(L-shift+2*(i-1)),i)=h(1:(L-shift)); 24 | H(1:shift,i)=h((L-shift+1):L); 25 | G((1+2*(i-1)):(L-shift+2*(i-1)),i)=g(1:(L-shift)); 26 | G(1:shift,i)=g((L-shift+1):L); 27 | end 28 | end 29 | T=zeros(2^level); 30 | % contatenate H to G so as to form one transform matrix T. 31 | % In the wavelet case (choice==1), the upper left sub principal 32 | % matrix is [H';G'], and the complement sub principal-diagonal 33 | % matrix is left to be an anidentity matrix. In the wavelet packet 34 | % case (choice==2), [H';G'] is lined recursively along the principal- 35 | % diagonal. 36 | if chpack==0 37 | T(1:2^t/2,1:2^t)=H'; 38 | T((2^t/2+1):2^t,1:2^t)=G'; 39 | for i=(2^t+1):(2^level) 40 | T(i,i)=1; 41 | end 42 | else 43 | for i=0:(2^(level-t)-1) 44 | T((2^t*i+1):(2^t*i+2^t/2),(2^t*i+1):(2^t*i+2^t))=H'; 45 | T((2^t*i+2^t/2+1):(2^t*i+2^t),(2^t*i+1):(2^t*i+2^t))=G'; 46 | end 47 | end 48 | 49 | -------------------------------------------------------------------------------- /3DCS/packages/wavelet/get_waveletMatrix.m: -------------------------------------------------------------------------------- 1 | function [T,T_all] = get_waveletMatrix(h,sig_level,level,decompose_level) 2 | % T = get_waveletMatrix(sig_level,level,decompose_level) 3 | % construct the matrix of wavelet tranform 4 | % Copyright (C) 2008-2012 by Xuejun Liao @ Duke University 5 | % Comments to: xuejun.liao@gmail.com, xjliao@ee.duke.edu, (919)-660-5548 6 | % 11 November 2008 7 | 8 | %hgcode=4; h=choosehg(hgcode); 9 | 10 | %sig_level = 4; 11 | %level = 3; 12 | 13 | g = zeros(size(h)); 14 | L = length(h); 15 | for i=1:L 16 | g(i)=(-1)^(i-1)*h(L-i+1); 17 | end 18 | 19 | T = eye(2^sig_level); 20 | T_all = {T}; 21 | for t=sig_level:-1:max(level,decompose_level+1) 22 | T = formhg(0,sig_level,t,h,g)*T; 23 | T_all = [T_all {formhg(0,sig_level,t,h,g)}]; 24 | end 25 | 26 | -------------------------------------------------------------------------------- /3DCS/packages/wavelet/my_get_weight3d.m: -------------------------------------------------------------------------------- 1 | function weight = my_get_weight3d(row,col,T,block) 2 | 3 | % Xin Yuan, get the weight of coefficient for GAP 3D 4 | % initial date: 04/30/2013 5 | 6 | % Input: row col, T the video size or the coeffient size 7 | % Input: block, the blocksize 8 | 9 | % output: weight, will have the size [block_num_row block_num_col block_num_T], in order to weight the 10 | % coefficient one by one 11 | % Here we use the cosine weight to weight the coefficient the low frequency 12 | % will have the larger weight 13 | 14 | row_block = block.row; 15 | col_block = block.col; 16 | T_block = block.T; 17 | 18 | block_num_row = row/row_block; 19 | block_num_col = col/col_block; 20 | block_num_T = ceil(T/T_block); 21 | 22 | 23 | weight_row = 1e-5+cos((0:(block_num_row-1))/block_num_row*pi/2).^2; 24 | weight_col = 1e-5+cos((0:(block_num_col-1))/block_num_col*pi/2).^2; 25 | weight_T = 1e-5+cos((0:(block_num_T-1))/block_num_T*pi/2).^2; 26 | 27 | weight_row = kron(weight_row, ones(1,row_block)); 28 | weight_col = kron(weight_col, ones(1,col_block)); 29 | weight_T = kron(weight_T, ones(1,T_block)); 30 | 31 | weight_row_all = repmat(weight_row', [1, col, T]); 32 | weight_col_all = repmat(weight_col, [row, 1, T]); 33 | weight_T_all = reshape(repmat(weight_T, [row*col, 1]), [row, col, T] ); 34 | 35 | % weight_row_all = repmat(weight_row', [1, block_num_col, block_num_T]); 36 | % weight_col_all = repmat(weight_col, [block_num_row, 1, block_num_T]); 37 | % weight_T_all = reshape(repmat(weight_T, [block_num_row*block_num_col, 1]), [block_num_row, block_num_col, block_num_T] ); 38 | 39 | weight = weight_row_all+weight_col_all + weight_T_all; 40 | %weight = kron(weight_block, ones(row_block,col_block,T_block)); 41 | 42 | 43 | end -------------------------------------------------------------------------------- /3DCS/packages/wavelet/my_get_weight3d_tree.m: -------------------------------------------------------------------------------- 1 | function weight = my_get_weight3d_tree(row,col,T,block) 2 | 3 | % Xin Yuan, get the weight of coefficient for GAP 3D 4 | % initial date: 04/30/2013 5 | % Revised date: 05/04/2013, add the zero-tree structure of the weight for 6 | % wavelet tree 7 | 8 | 9 | % Input: row col, T the video size or the coeffient size 10 | % Input: block, the blocksize 11 | 12 | % output: weight, will have the size [block_num_row block_num_col block_num_T], in order to weight the 13 | % coefficient one by one 14 | % Here we use the cosine weight to weight the coefficient the low frequency 15 | % will have the larger weight 16 | 17 | 18 | row_block = block.row; 19 | col_block = block.col; 20 | T_block = block.T; 21 | 22 | block_num_row = length(row_block); 23 | block_num_T = ceil(T/T_block); 24 | %block_num_col = length(col_block); 25 | weight = zeros(row,col,T); 26 | 27 | weight_2D = zeros(row,col); 28 | weight_row = 1e-5+cos((0:(block_num_row-1))/block_num_row*pi/2).^2; 29 | weight_T = 1e-5+cos((0:(block_num_T-1))/block_num_T*pi/2).^2; 30 | %weight_col = 1e-5+cos((0:(block_num_col-1))/block_num_col*pi/2).^2; 31 | 32 | weight_2D((1:row_block(1)), (1:col_block(1))) = kron(weight_row(1),ones(row_block(1),col_block(1))); 33 | 34 | rowsum = row_block(1); 35 | colsum = col_block(1); 36 | for nR = 2:block_num_row 37 | 38 | temp_weight = kron(weight_row(nR), ones(row_block(nR),col_block(nR))); 39 | weight_2D(rowsum+(1:row_block(nR)), colsum+(1:col_block(nR))) = temp_weight; 40 | weight_2D(rowsum+(1:row_block(nR)), 1:colsum) = temp_weight; 41 | weight_2D(1:rowsum, colsum+(1:col_block(nR))) = temp_weight; 42 | 43 | rowsum = rowsum + row_block(nR); 44 | colsum = colsum + col_block(nR); 45 | end 46 | 47 | for nt = 1:block_num_T 48 | if(nt*T_block<=T) 49 | weight(:,:,(nt-1)*T_block+(1:T_block)) = repmat(weight_2D*weight_T(nt), [1 1 T_block]); 50 | else 51 | weight(:,:,((nt-1)*T_block+1):T) = repmat(weight_2D*weight_T(nt), [1, 1, T-((nt-1)*T_block)]); 52 | end 53 | end 54 | 55 | 56 | end -------------------------------------------------------------------------------- /3DCS/packages/wavelet/myfastinvtransform3_givenT.m: -------------------------------------------------------------------------------- 1 | function theta = myfastinvtransform3_givenT(w,T_row,T_col,T_t) 2 | 3 | % Xin Yuan, 3D dct or wavelet transformation 4 | % initial date: 04/30/2013 5 | [row col T] = size(w); 6 | % if strcmp(spbasis.space,'dct') 7 | % T_row = dct(eye(row)); 8 | % T_col = dct(eye(col)); 9 | % else 10 | % level = 3; 11 | % qmf = MakeONFilter('Daubechies',8); 12 | % sig_level_row = log2(row); 13 | % sig_level_col = log2(col); 14 | % T_row = get_waveletMatrix(qmf,sig_level_row,level,level); 15 | % T_col = get_waveletMatrix(qmf,sig_level_col,level,level); 16 | % end 17 | % 18 | % if strcmp(spbasis.time,'dct') 19 | % T_t = dct(eye(T)); 20 | % else 21 | % T = 2^(ceil(log2(T))); 22 | % % level = 2; 23 | % % qmf = MakeONFilter('Daubechies',8); 24 | % % sig_level_t = log2(row); 25 | % % T_t = get_waveletMatrix(qmf,sig_level_t,level,level); 26 | % level = 1; 27 | % qmf = MakeONFilter('Haar',4); % Here we use the 'Haar' wavelet and the second parameter now no meaning 28 | % sig_level_t = ceil(log2(T)); 29 | % T_t = get_waveletMatrix(qmf,sig_level_t,level,level); 30 | % end 31 | 32 | theta = shiftdim(reshape(T_t'*reshape(shiftdim(w,2),T,row*col),T,row,col),1); 33 | theta = reshape(T_row'*reshape(theta,row,col*T),row,col,T); 34 | theta = shiftdim(reshape(T_col'*reshape(shiftdim(theta,1),col,row*T),col,T,row),2); 35 | 36 | 37 | end -------------------------------------------------------------------------------- /3DCS/packages/wavelet/myfasttransform3_givenT.m: -------------------------------------------------------------------------------- 1 | function w = myfasttransform3_givenT(theta_temp,T_row,T_col,T_t) 2 | 3 | % Xin Yuan, 3D dct or wavelet transformation 4 | % initial date: 04/30/2013 5 | % Revised date: 05/09/2013 make the T domain also wavelet 6 | 7 | [row, col, T] = size(theta_temp); 8 | % if strcmp(spbasis.space,'dct') 9 | % T_row = dct(eye(row)); 10 | % T_col = dct(eye(col)); 11 | % else 12 | % level = 3; 13 | % qmf = MakeONFilter('Daubechies',8); 14 | % sig_level_row = log2(row); 15 | % sig_level_col = log2(col); 16 | % T_row = get_waveletMatrix(qmf,sig_level_row,level,level); 17 | % T_col = get_waveletMatrix(qmf,sig_level_col,level,level); 18 | % end 19 | % 20 | % if strcmp(spbasis.time,'dct') 21 | % T_t = dct(eye(T)); 22 | % else 23 | % T = 2^(ceil(log2(T))); 24 | % % level = 2; 25 | % % qmf = MakeONFilter('Daubechies',8); 26 | % % sig_level_t = log2(T); 27 | % % T_t = get_waveletMatrix(qmf,sig_level_t,level,level); 28 | % level = 1; 29 | % qmf = MakeONFilter('Haar',4); % Here we use the 'Haar' wavelet and the second parameter now no meaning 30 | % % qmf = MakeONFilter('Daubechies',4); 31 | % sig_level_t = ceil(log2(T)); 32 | % T_t = get_waveletMatrix(qmf,sig_level_t,level,level); 33 | % 34 | % end 35 | 36 | w = shiftdim(reshape(T_t*reshape(shiftdim(theta_temp,2),T,row*col),T,row,col),1); 37 | w = reshape(T_row*reshape(w,row,col*T),row,col,T); 38 | w = shiftdim(reshape(T_col*reshape(shiftdim(w,1),col,row*T),col,T,row),2); 39 | 40 | end -------------------------------------------------------------------------------- /3DCS/readme.md: -------------------------------------------------------------------------------- 1 | # Three-dimensional (3D) compressive sensing algorithms: towards real-time volumetric imaging 2 | This is a final project of *Matrix analysis and its applications*, Prof. Fangming Han, Fall 2016. 3 | 4 | Copyright [Y. Liu](https://github.com/liuyang12 "liuyang12"). 5 | ## Structure of directories 6 | 7 | | directory | discription | 8 | | :--------: | :----------: | 9 | | algorithms | MATLAB functions of all the algorithms applied in the project. (original) | 10 | | packages | algorithms adapted from the state-of-art algorithms. (adapted)| 11 | | scenes | static and dynamic scenes used in the project as test images or image sequences. (standard) | 12 | | tests | test code of the project applying the original functions and the adapted packages | 13 | | utils | utility functions for sparse reconstruction with respect to the quality and the (time) complexity of the results | 14 | 15 | ## Platform 16 | The test platform is MATLAB(R) 2016a operating on Windows(R) 10 (x64) with an Intel(R) Core(TM) Quad CPU at 3.60 GHz and 16 GB memory. 17 | 18 | ## Acknowledgement 19 | The author would like to thank Prof. Fangming Han for inspiring discussions and Dr. X. Yuan for providing original code and datasets of coded apertur compressive temporal imaging (CACTI). The author would like to share special thanks to the [WeLearn](https://github.com/WeLearnLab "WeLearnLab") group for endless help on promoting efficiency. 20 | -------------------------------------------------------------------------------- /3DCS/scenes/dynamic/noise_free/foreman.yuv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/scenes/dynamic/noise_free/foreman.yuv -------------------------------------------------------------------------------- /3DCS/scenes/static/angrybird.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/scenes/static/angrybird.jpg -------------------------------------------------------------------------------- /3DCS/scenes/static/angrybird64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/scenes/static/angrybird64.png -------------------------------------------------------------------------------- /3DCS/scenes/static/barbara.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/scenes/static/barbara.png -------------------------------------------------------------------------------- /3DCS/scenes/static/fire.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/scenes/static/fire.jpg -------------------------------------------------------------------------------- /3DCS/scenes/static/gi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/scenes/static/gi.png -------------------------------------------------------------------------------- /3DCS/scenes/static/house.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/scenes/static/house.png -------------------------------------------------------------------------------- /3DCS/scenes/static/phantom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/scenes/static/phantom.png -------------------------------------------------------------------------------- /3DCS/scenes/static/siemens.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/3DCS/scenes/static/siemens.png -------------------------------------------------------------------------------- /3DCS/tests/testfunc.m: -------------------------------------------------------------------------------- 1 | %TESTFUNC test the functions of the project 2 | 3 | %% [0] add *algorithms* and *packages* to operation path 4 | addpath('../algorithms') 5 | addpath(genpath('../packages')) 6 | 7 | %% [3.1.1] test the TV operator generator 8 | m = 3; % number of rows 9 | n = 4; % number of columns 10 | H = gentvop(m,n,1); 11 | -------------------------------------------------------------------------------- /3DCS/tests/testgap3d.m: -------------------------------------------------------------------------------- 1 | %TESTGAP3D Test three dimensional (3D) generalized alternating projection 2 | %(GAP) algorithm, that is GAP3D algorithm. 3 | clear; clc; 4 | % close all; 5 | % [0] add dependencies to path 6 | addpath('../utils') 7 | addpath('../algorithms') 8 | addpath(genpath('../packages')) 9 | 10 | % [1] load the CASSI dataset 11 | datadir = '../../data'; % data directory 12 | cassidir = '../../data/cassi'; % cassi data directory 13 | cassipath = sprintf('%s/CASSI_bird.mat',cassidir); % cassi data path 14 | load(cassipath); 15 | 16 | Phi = squeeze(Phi(:,:,:,1)); % Nx*Ny*Nt patterns 17 | y = Y(:,:,1); % Nx*Ny coded image 18 | x0 = slit; % Nx*Ny*Nt original image sequence (ground truth), 19 | % that is the forward model y=sum(Phi.*x0,3) 20 | [Nx,Ny,Nt] = size(Phi); 21 | 22 | %% [2] obtain the linear forward model of the reconstruction problem 23 | A_fun = @(f) fm_cassi(Phi,f); 24 | At_fun = @(y) fmt_cassi(Phi,y); 25 | 26 | x_rec_gap3d = run_gap_cassi(y,Phi); 27 | 28 | -------------------------------------------------------------------------------- /3DCS/utils/fm_3dcs.m: -------------------------------------------------------------------------------- 1 | function [ y ] = fm_3dcs( A,x ) 2 | %FM_3DCS Forward model of three dimensional (3D) compressive sensing (CS). 3 | % y=FM_3DCS(A,x) returns the multiple frame vector of forward calculation 4 | % of CS, that is y_k=A_k*x_k for frame k, where A is the M-by-N-by-F 5 | % sensing or measurement matrix, x is the N-by-F object matrix, and y is 6 | % the M-by-F measurement matrix. 7 | % See also FMT_3DCS. 8 | [M,N,F] = size(A); 9 | for k = 1:F 10 | y(:,k) = A(:,:,k)*x(:,k); 11 | end 12 | % y = sum(A.*repmat(x,[M 1 1]),2); 13 | end 14 | 15 | -------------------------------------------------------------------------------- /3DCS/utils/fm_cassi.m: -------------------------------------------------------------------------------- 1 | function [ y ] = fm_cassi( H,f ) 2 | %FM_CASSI Forward model of the coded aperture snapshot spectral imager 3 | %(CASSI). 4 | % y=FM_CASSI(H,f) returns the coded image of CASSI, that is 5 | % y=sum(H.*f,3), where H is Nx-by-Ny-by-Nt matrix denoting the code or 6 | % patterns of the imager, f is the original 3D sample with the same 7 | % dimensions as H. 8 | % See also FMT_CASSI. 9 | y = sum(H.*f,3); 10 | end 11 | 12 | -------------------------------------------------------------------------------- /3DCS/utils/fm_cs.m: -------------------------------------------------------------------------------- 1 | function [ y ] = fm_cs( A,x ) 2 | %FM_CS Forward model of compressive sensing (CS). 3 | % y=FM_CS(A,x) returns the vector of forward calculation of CS, that is 4 | % y=A*x, where A is the M-by-N sensing or measurement matrix, x is 5 | % the N-by-1 object vector, and y is the M-by-1 measurement vector. 6 | % See also FMT_CS. 7 | y = A*x; 8 | end 9 | 10 | -------------------------------------------------------------------------------- /3DCS/utils/fmt_3dcs.m: -------------------------------------------------------------------------------- 1 | function [ fy ] = fmt_3dcs( A,y ) 2 | %FMT_3DCS Forward model of three dimensional (3D) compressive sensing (CS). 3 | % fy=FMT_3DCS(A,y) returns the multiple frame vector of forward calculation 4 | % of CS, that is y_k=A_k*x_k for frame k, where A is the M-by-N-by-F 5 | % sensing or measurement matrix, y is the M-by-F measurement matrix and 6 | % fy is the N-by-F object matrix. 7 | % See also FMT_3DCS. 8 | [M,N,F] = size(A); 9 | for k = 1:F 10 | fy(:,k) = A(:,:,k)'*y(:,k); 11 | end 12 | 13 | end 14 | 15 | -------------------------------------------------------------------------------- /3DCS/utils/fmt_cassi.m: -------------------------------------------------------------------------------- 1 | function [ fy ] = fmt_cassi( H,y ) 2 | %FMT_CASSI Forward model of the coded aperture snapshot spectral imager 3 | %(CASSI). 4 | % fy=FMT_CASSI(H,y) returns the result of transpose of the measurement 5 | % matrix multiplies the measurement vector, that is fy=H.*y, 6 | % where H is Nx-by-Ny-by-Nt matrix denoting the code or patterns of the 7 | % imager, f is the original 3D sample with the same dimensions as H. 8 | % See also FM_CASSI. 9 | fy = bsxfun(@times,H,y); 10 | end -------------------------------------------------------------------------------- /3DCS/utils/fmt_cs.m: -------------------------------------------------------------------------------- 1 | function [ fy ] = fmt_cs( A,y ) 2 | %FMT_CS Transpose of forward model of compressive sensing (CS). 3 | % fy=FMT_CS(A,y) returns the vector of the transpose of forward 4 | % calculation of CS, that is fy=A'*y, where A is the M-by-N sensing or 5 | % measurement matrix, y is the M-by-1 measurement vector, and fy is the 6 | % N-by-1 result vector. 7 | % See also FM_CS. 8 | fy = A'*y; 9 | end -------------------------------------------------------------------------------- /3DCS/utils/getallfiles.m: -------------------------------------------------------------------------------- 1 | function [ filenames ] = getallfiles( filedir ) 2 | %GETALLFILES get all the file names of a directory 3 | % filenames=GETALLFILES(filedir) returns all the filenames of the filedir 4 | % in the form of cell. Each file can be access by filenames{$fileorder$} 5 | % then, where fileorder is the default order of the file in filedir. 6 | alldir = dir(filedir); 7 | alldir = alldir(~ismember({alldir.name},{'.','..'})); 8 | filenames = {alldir.name}'; 9 | filenames = strcat({[filedir, '\']}, filenames); 10 | end 11 | 12 | -------------------------------------------------------------------------------- /3DCS/utils/haarmtx.m: -------------------------------------------------------------------------------- 1 | function [ H ] = haarmtx( n ) 2 | %HAARMTX Haar wavelet matrix 3 | % H=HAARMTX(n) returns the Haar wavelet matrix, where n is the k-th power 4 | % of two (2^k). 5 | k = floor(log2(n)); 6 | if 2^k < n 7 | error('%d is not the power of 2.\n',n); 8 | end 9 | 10 | H = [1]; 11 | NC = 1/sqrt(2); 12 | LP = [ 1 1]; 13 | HP = [ 1 -1]; 14 | 15 | for i = 1:k 16 | H = NC*[kron(H,LP);kron(eye(size(H)),HP)]; 17 | end 18 | end 19 | 20 | -------------------------------------------------------------------------------- /3DCS/utils/imnorm.m: -------------------------------------------------------------------------------- 1 | function [ im_norm ] = imnorm( im_orig ) 2 | %IMNORM min-max normalization of the 2-d image to the range of [0,1] 3 | 4 | im_norm = (im_orig - min(min(min(im_orig))))... 5 | / (max(max(max(im_orig))) - min(min(min(im_orig)))); 6 | 7 | end 8 | 9 | -------------------------------------------------------------------------------- /3DCS/utils/imreadallfmt.m: -------------------------------------------------------------------------------- 1 | function [ im ] = imreadallfmt( impath ) 2 | %IMREADALLFMT read images of all formats 3 | % im=IMREADALLFMT(impath) returns the image matrix under such impath. 4 | % See also IMREAD. 5 | impathfmt = [impath '.jpg']; 6 | if ~exist(impathfmt,'file') 7 | impathfmt = [impath '.png']; 8 | elseif ~exist(impathfmt,'file') 9 | impathfmt = [impath '.bmp']; 10 | elseif ~exist(impathfmt,'file') 11 | impathfmt = [impath '.tif']; 12 | elseif ~exist(impathfmt,'file') 13 | error('specify image format and use imread instead.\n'); 14 | end 15 | im = imread(impathfmt); % read image 16 | 17 | end 18 | 19 | -------------------------------------------------------------------------------- /3DCS/utils/savevideoframes.m: -------------------------------------------------------------------------------- 1 | function [ ] = savevideoframes( vpath,fpath,params ) 2 | %SAVEVIDEOFRAMES Save all the frames of a video 3 | % SAVEVIDEOFRAMES(vpath,fpath,params) saves all the video frames from 4 | % vpath to the directory fpath. 5 | 6 | % [0] parameters configuration 7 | width = params.width; 8 | height = params.height; 9 | format = params.format; 10 | 11 | % [1] read the video file from vpath 12 | mov = yuv2mov(vpath,width,height,format); % convert 13 | 14 | % [2] save all the frames 15 | if ~exist(fpath,'dir') 16 | mkdir(fpath); 17 | end 18 | nframe = length(mov); 19 | for iframe = 1:nframe 20 | cur = mov(iframe).cdata; 21 | % if size(cur,3)>1 22 | % cur = rgb2gray(cur); 23 | % end 24 | imwrite(cur,sprintf('%s/frame%04d.png',fpath,iframe)); 25 | end 26 | 27 | -------------------------------------------------------------------------------- /3DCS/utils/setdefault.m: -------------------------------------------------------------------------------- 1 | function [ opts ] = setdefault( opts,deft ) 2 | %SETDEFAULT set default values to options by means of traversing the fields 3 | %of the default structure 4 | % SETDEFAULT(opts,deft) sets the default opts with all the fields in 5 | % deft. 6 | names = fieldnames(deft); 7 | for i = 1:length(names) 8 | if ~isfield(opts,names{i}) 9 | opts.(names{i}) = deft.(names{i}); % [default] initial value of penalty factor mu 10 | end 11 | end 12 | 13 | -------------------------------------------------------------------------------- /3DCS/utils/sparcons.m: -------------------------------------------------------------------------------- 1 | function [ sc ] = sparcons( sig,ref,zerodef ) 2 | %SPARCONS Sparse consistancy served as assessment of the consistancies of 3 | %the zero part and the nonzero part for sparse 1D signals 4 | % sc=SPARCONS(sig,ref) returns the sparse consistancy of sig with respect 5 | % to ref. 6 | if nargin < 3 7 | zerodef = 1e-10; % defined zero 8 | end 9 | sig = sig(:); 10 | ref = ref(:); 11 | Iz = find(abs(ref)=zerodef); % nonzero-valued index 13 | sc = length(find(abs(sig(Iz)) 0 34 | if nargin < 3, cg_tol = 1e-6; end 35 | if nargin < 4, cg_maxit = 30; end 36 | 37 | [y,flag,relres,iter] = pcg(A,b,cg_tol,cg_maxit,[],[],x0{ evenOdd + 1 } ); 38 | 39 | nA = nA + iter; 40 | nCG = nCG + 1; 41 | x0{evenOdd+1} = y; 42 | 43 | evenOdd = ~evenOdd; 44 | 45 | else 46 | y = nA; 47 | out2 = nCG; 48 | % and reset 49 | nA = 0; 50 | nCG = 0; 51 | x0={[],[]}; 52 | end 53 | -------------------------------------------------------------------------------- /NESTA_v1.1/Misc/LSQRwrapper.m: -------------------------------------------------------------------------------- 1 | function y = LSQRwrapper(x,transp,A,At) 2 | % y = LSQRwrapper(x,trans,A,At) 3 | % NESTA Version 1.1 4 | 5 | 6 | % Stephen Becker, 11/12/09 7 | 8 | if strcmpi(transp,'transp') 9 | y = At(x); 10 | elseif strcmpi(transp,'notransp') 11 | y = A(x); 12 | end 13 | -------------------------------------------------------------------------------- /NESTA_v1.1/Misc/LineMask.m: -------------------------------------------------------------------------------- 1 | % LineMask.m 2 | % 3 | % Returns the indicator of the domain in 2D fourier space for the 4 | % specified line geometry. 5 | % Usage : [M,Mh,mi,mhi] = LineMask(L,N) 6 | % 7 | % Written by : Justin Romberg 8 | % Created : 1/26/2004 9 | % Revised : 12/2/2004 10 | 11 | function [M,Mh,mi,mhi] = LineMask(L,N) 12 | 13 | 14 | thc = linspace(0, pi-pi/L, L); 15 | %thc = linspace(pi/(2*L), pi-pi/(2*L), L); 16 | 17 | M = zeros(N); 18 | 19 | % full mask 20 | for ll = 1:L 21 | 22 | if ((thc(ll) <= pi/4) | (thc(ll) > 3*pi/4)) 23 | yr = round(tan(thc(ll))*(-N/2+1:N/2-1))+N/2+1; 24 | for nn = 1:N-1 25 | M(yr(nn),nn+1) = 1; 26 | end 27 | else 28 | xc = round(cot(thc(ll))*(-N/2+1:N/2-1))+N/2+1; 29 | for nn = 1:N-1 30 | M(nn+1,xc(nn)) = 1; 31 | end 32 | end 33 | 34 | end 35 | 36 | 37 | % upper half plane mask (not including origin) 38 | Mh = zeros(N); 39 | Mh = M; 40 | Mh(N/2+2:N,:) = 0; 41 | Mh(N/2+1,N/2+1:N) = 0; 42 | 43 | 44 | M = ifftshift(M); 45 | mi = find(M); 46 | Mh = ifftshift(Mh); 47 | mhi = find(Mh); 48 | -------------------------------------------------------------------------------- /NESTA_v1.1/Misc/MakeRDSquares.m: -------------------------------------------------------------------------------- 1 | function x=MakeRDSquares(N,nbs,Dyna) 2 | % NESTA Version 1.1 3 | 4 | 5 | if nargin <3 6 | Dyna = 40; 7 | end 8 | 9 | if nargin <2 10 | nbs = 5; 11 | end 12 | 13 | if nargin <1 14 | N=256; 15 | end 16 | 17 | lmin = floor(8); 18 | lmax = floor(N/4); 19 | x = zeros(N,N); 20 | 21 | for ll=1:nbs 22 | ndx = 1+floor((N-lmax-1)*rand(1,1)); 23 | lx = min(N-ndx-1,floor(lmin + (lmax-lmin)*rand(1,1))); 24 | ndy = 1+floor((N-lmax-1)*rand(1,1)); 25 | ly = min(N-ndy-1,floor(lmin + (lmax-lmin)*rand(1,1))); 26 | x(ndx:ndx+lx-1,ndy:ndy+ly-1) = 1+10^(Dyna/20)*rand(1,1); 27 | end 28 | ind = find(x > 0.5); 29 | x(ind) = x(ind)-min(x(ind)); 30 | x(ind) = x(ind)/max(x(ind))*(10^(Dyna/20)-1)+1; 31 | 32 | -------------------------------------------------------------------------------- /NESTA_v1.1/Misc/calctv.m: -------------------------------------------------------------------------------- 1 | % Calculates the TV of N1xN2 image 2 | % x is the vector version of the image 3 | function [tv,val] = calctv(N1,N2,x) 4 | X = reshape(x,N1,N2); 5 | tv = sum(sum(sqrt([diff(X,1,2) zeros(N1,1)].^2 + [diff(X,1,1); zeros(1,N2)].^2 ))); 6 | val=max(max(sqrt([diff(X,1,2) zeros(N1,1)].^2 + [diff(X,1,1); zeros(1,N2)].^2 ))); 7 | end 8 | -------------------------------------------------------------------------------- /NESTA_v1.1/Misc/counter.m: -------------------------------------------------------------------------------- 1 | function out = counter( f, x ) 2 | % y = counter( f, x ) 3 | % returns y = f(x) 4 | % 5 | % n = counter() 6 | % returns the number of calls n made to the counter and zeros-out 7 | % the iteration counter 8 | % 9 | % This uses a persistent variable, but also 10 | % a global variable called COUNT_ 11 | % that may be accessed from anywhere. 12 | % Changing the value of COUNT_ is harmless, since 13 | % it will be overridden by the persistent variable 14 | % 15 | % Stephen Becker, srbecker@caltech.edu, March 2009 16 | % NESTA Version 1.1 17 | 18 | 19 | persistent n 20 | global COUNT_ 21 | if isempty(n), n = 0; end 22 | if isempty(COUNT_), COUNT_ = 0; end 23 | 24 | if nargin < 1 25 | out = n; 26 | n = 0; 27 | return 28 | end 29 | 30 | out = f(x); 31 | n = n + 1; 32 | COUNT_ = n; 33 | -------------------------------------------------------------------------------- /NESTA_v1.1/Misc/my_normest.m: -------------------------------------------------------------------------------- 1 | function [e,cnt] = my_normest(S,St,n,tol, maxiter) 2 | % [norm,iter_count] = my_normest( A, At, n, [tol], [maxiter] ) 3 | % estimates the spectral norm of A using the power method, 4 | % where A is a function handle to compute A(x) = A*x 5 | % and At is a function handle to compute At(x) = A'*x 6 | % 7 | % Copied from MATLAB's "normest" function, but allows function handles, not just sparse matrices 8 | if nargin < 4, tol = 1.e-6; end 9 | if nargin < 5, maxiter = 20; end 10 | if isempty(St) 11 | St = S; % we assume the matrix is symmetric; 12 | end 13 | x = ones(n,1); 14 | cnt = 0; 15 | e = norm(x); 16 | if e == 0, return, end 17 | x = x/e; 18 | e0 = 0; 19 | while abs(e-e0) > tol*e && cnt < maxiter 20 | e0 = e; 21 | Sx = S(x); 22 | if nnz(Sx) == 0 23 | Sx = rand(size(Sx)); 24 | end 25 | e = norm(Sx); 26 | x = St(Sx); 27 | x = x/norm(x); 28 | cnt = cnt+1; 29 | end 30 | end -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/NESTA_v1.1/RecPF_v1.1/.DS_Store -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/images/ortho1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/NESTA_v1.1/RecPF_v1.1/images/ortho1.jpg -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/images/ortho2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/NESTA_v1.1/RecPF_v1.1/images/ortho2.jpg -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/images/ortho3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/NESTA_v1.1/RecPF_v1.1/images/ortho3.jpg -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/images/ortho4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/NESTA_v1.1/RecPF_v1.1/images/ortho4.jpg -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/images/ortho5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/NESTA_v1.1/RecPF_v1.1/images/ortho5.jpg -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/images/ortho6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/NESTA_v1.1/RecPF_v1.1/images/ortho6.jpg -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/utilities/MRImask.m: -------------------------------------------------------------------------------- 1 | function y = MRImask(n,beams) 2 | % 3 | % produces the fan MRI mask, of size n*n, 4 | % beams is the number of angles 5 | % 6 | m = ceil(sqrt(2)*n); 7 | aux = zeros(m,m); ima = aux; 8 | aux(round(m/2+1),:) = 1; 9 | angle = 180/beams; 10 | angles = (0:angle:180-angle); 11 | for a = 1:length(angles) 12 | ang = angles(a); 13 | temp = imrotate(aux,ang,'crop'); 14 | ima = ima + temp; 15 | end 16 | ima = ima(round(m/2+1) - n/2:round(m/2+1) + n/2-1,... 17 | round(m/2+1) - n/2:round(m/2+1) + n/2-1); 18 | 19 | y = (ima > 0); 20 | -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/utilities/Wavedb1Phi.m: -------------------------------------------------------------------------------- 1 | function Y = Wavedb1Phi(X,trans) 2 | persistent s; 3 | 4 | level = 2; 5 | 6 | if ~trans; 7 | % Phi' * X 8 | [Y,s] = wavedec2(X,level,'db1'); 9 | else 10 | Y = waverec2(X(:),s,'db1'); 11 | end 12 | 13 | 14 | -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/utilities/dctPhi.m: -------------------------------------------------------------------------------- 1 | function Y = dctPhi(X,trans) 2 | if ~trans; 3 | Y = dct2(X); 4 | else 5 | Y = idct2(X); 6 | end 7 | -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/utilities/funcval.m: -------------------------------------------------------------------------------- 1 | function [fval_true,TVval,FIDval] = funcval(U,aTV,aL1,B,picks) 2 | 3 | global Ux Uy PsiTU 4 | 5 | [m,n] = size(U); 6 | 7 | fval_true = 0; 8 | 9 | if aL1 > 0 10 | fval_true = fval_true + aL1* sum(abs(PsiTU(:))); 11 | end 12 | 13 | if isempty(Ux) || isempty(Uy) 14 | [m,n] = size(U); 15 | Ux = [diff(U,1,1);U(1,:)-U(end,:)]; 16 | Uy = [diff(U,1,2),U(:,1)-U(:,end)]; 17 | end 18 | 19 | 20 | if aTV > 0 21 | temp = sum(sum(sqrt(Ux.^2 + Uy.^2))); 22 | fval_true = fval_true + aTV*temp; 23 | if nargout > 1 24 | TVval = temp; 25 | end 26 | end 27 | 28 | fu = fft2(U); 29 | temp = fu(picks)/sqrt(m*n) - B; 30 | temp = norm([real(temp);imag(temp)]); 31 | temp = .5*temp^2; 32 | fval_true = fval_true + temp;%/(m*n); 33 | if nargout > 2 34 | FIDval = temp; 35 | end 36 | 37 | 38 | -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/utilities/identityPhi.m: -------------------------------------------------------------------------------- 1 | function Y = identityPhi(X) 2 | Y = X; -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/utilities/selectPF.m: -------------------------------------------------------------------------------- 1 | function [picks,P] = selectPF(tol,n) 2 | 3 | halfn = round(n/2); 4 | [I,J] = meshgrid(1:n,1:n); 5 | P = abs(I - halfn*(rand(n) + .5)) < tol & ... 6 | abs(J - halfn*(rand(n) + .5)) < tol; 7 | 8 | P(halfn+1:n,:) = 0; 9 | P(halfn:halfn+1,:) = 1; 10 | P(:,halfn:halfn+1) = 1; 11 | P = ifftshift(P); 12 | P(1,1) = 1; 13 | 14 | picks = find(P); -------------------------------------------------------------------------------- /NESTA_v1.1/RecPF_v1.1/utilities/snr.m: -------------------------------------------------------------------------------- 1 | function x = snr(sig, ref) 2 | persistent ref_save; 3 | if nargin > 1; ref_save = ref; end; 4 | 5 | mse = mean((ref_save(:)-sig(:)).^2); 6 | if mse == 0; x = inf; return; end 7 | 8 | dv = var(ref_save(:),1); 9 | x = 10*log10(dv/mse); -------------------------------------------------------------------------------- /NESTA_v1.1/Setup_Nesta.m: -------------------------------------------------------------------------------- 1 | % 2 | % 3 | % Setup_Nesta 4 | % 5 | % sets up the path for Nesta 6 | % 7 | % 8 | % 9 | % Written by: Jerome Bobin, Caltech 10 | % Email: bobin@acm.caltech.edu 11 | % Created: May 2009 12 | % 13 | % NESTA NESTA Version 1.1 14 | % See also NESTA 15 | 16 | % This adds a relative path, so it only works 17 | % when you're in the NESTA directory 18 | 19 | %addpath RecPF_v1.1/solver/ 20 | %addpath Misc/ 21 | 22 | 23 | % This adds an absolute path, so it works 24 | % when the user is in any directory 25 | 26 | p = mfilename('fullpath'); % the location of this file 27 | path = fileparts(p); 28 | addpath( fullfile(path,'RecPF_v1.1','solver' ) ); 29 | addpath( fullfile(path,'Misc') ); 30 | -------------------------------------------------------------------------------- /OMP_SP_IHT_CoSaMP_GBP_IRLS/CS Recovery Algorithms.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/OMP_SP_IHT_CoSaMP_GBP_IRLS/CS Recovery Algorithms.pdf -------------------------------------------------------------------------------- /OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_CoSaMP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_CoSaMP.m -------------------------------------------------------------------------------- /OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_GBP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_GBP.m -------------------------------------------------------------------------------- /OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_IHT.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_IHT.m -------------------------------------------------------------------------------- /OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_IRLS.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_IRLS.m -------------------------------------------------------------------------------- /OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_OMP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_OMP.m -------------------------------------------------------------------------------- /OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_SP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/Demo_CS_SP.m -------------------------------------------------------------------------------- /OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/lena.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/OMP_SP_IHT_CoSaMP_GBP_IRLS/OMP_SP_IHT_CoSaMP_GBP_IRLS/lena.bmp -------------------------------------------------------------------------------- /OMP_SP_IHT_CoSaMP_GBP_IRLS/bak/CS_recovery_algorithms_OMP_SP_IHT_CoSaMP_GBP_IRLS.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/OMP_SP_IHT_CoSaMP_GBP_IRLS/bak/CS_recovery_algorithms_OMP_SP_IHT_CoSaMP_GBP_IRLS.rar -------------------------------------------------------------------------------- /SLOPE_code/cproxSortedL1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013, M. Bogdan, E. van den Berg, W. Su, and E.J. Candes 3 | * 4 | * This file is part of SLOPE Toolbox version 1.0. 5 | * 6 | * The SLOPE Toolbox is free software: you can redistribute it 7 | * and/or modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation, either version 3 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * The SLOPE Toolbox is distributed in the hope that it will 12 | * be useful, but WITHOUT ANY WARRANTY; without even the implied 13 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 | * See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the SLOPE Toolbox. If not, see 18 | * . 19 | */ 20 | 21 | #include 22 | #include "proxSortedL1.h" 23 | 24 | /* ----------------------------------------------------------------------- */ 25 | void cproxSortedL1(double *y, double *lambda, double *x, int *np, int *order) 26 | /* ----------------------------------------------------------------------- */ 27 | { int result; 28 | int n = *np; 29 | 30 | result = evaluateProx(y,lambda,x,(size_t)n,order); 31 | } 32 | -------------------------------------------------------------------------------- /SLOPE_code/data/testData_A.txt: -------------------------------------------------------------------------------- 1 | 5.3766714e-01 -1.3076883e+00 -1.3498869e+00 -2.0496606e-01 6.7149713e-01 1.0346930e+00 8.8839563e-01 1.4383803e+00 -1.0224245e-01 -3.0051296e-02 2 | 1.8338850e+00 -4.3359202e-01 3.0349235e+00 -1.2414435e-01 -1.2074869e+00 7.2688513e-01 -1.1470701e+00 3.2519054e-01 -2.4144704e-01 -1.6487902e-01 3 | -2.2588469e+00 3.4262447e-01 7.2540422e-01 1.4896976e+00 7.1723865e-01 -3.0344092e-01 -1.0688705e+00 -7.5492832e-01 3.1920674e-01 6.2770729e-01 4 | 8.6217332e-01 3.5783969e+00 -6.3054873e-02 1.4090345e+00 1.6302353e+00 2.9387147e-01 -8.0949869e-01 1.3702985e+00 3.1285860e-01 1.0932657e+00 5 | 3.1876524e-01 2.7694370e+00 7.1474290e-01 1.4171924e+00 4.8889377e-01 -7.8728280e-01 -2.9442842e+00 -1.7115164e+00 -8.6487992e-01 1.1092733e+00 6 | -------------------------------------------------------------------------------- /SLOPE_code/data/testData_b.txt: -------------------------------------------------------------------------------- 1 | 1.0734014e+00 2 | -5.3021346e+00 3 | 1.0966390e+00 4 | -3.9124089e-01 5 | -9.2884291e-01 6 | -------------------------------------------------------------------------------- /SLOPE_code/data/testData_lambda.txt: -------------------------------------------------------------------------------- 1 | 1.0000000e+00 9.0000000e-01 8.0000000e-01 7.0000000e-01 6.0000000e-01 5.0000000e-01 4.0000000e-01 3.0000000e-01 2.0000000e-01 1.0000000e-01 2 | -------------------------------------------------------------------------------- /SLOPE_code/data/testData_x0.txt: -------------------------------------------------------------------------------- 1 | -8.6365282e-01 2 | 7.7359091e-02 3 | -1.2141170e+00 4 | 0.0000000e+00 5 | 0.0000000e+00 6 | 0.0000000e+00 7 | 0.0000000e+00 8 | 0.0000000e+00 9 | 0.0000000e+00 10 | 0.0000000e+00 11 | -------------------------------------------------------------------------------- /SLOPE_code/doc/SLOPE.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/SLOPE_code/doc/SLOPE.pdf -------------------------------------------------------------------------------- /SLOPE_code/doc/SortedL1_SM.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/SLOPE_code/doc/SortedL1_SM.pdf -------------------------------------------------------------------------------- /SLOPE_code/makemex.m: -------------------------------------------------------------------------------- 1 | % Copyright 2013, M. Bogdan, E. van den Berg, W. Su, and E.J. Candes 2 | 3 | % This file is part of SLOPE Toolbox version 1.0. 4 | % 5 | % The SLOPE Toolbox is free software: you can redistribute it 6 | % and/or modify it under the terms of the GNU General Public License 7 | % as published by the Free Software Foundation, either version 3 of 8 | % the License, or (at your option) any later version. 9 | % 10 | % The SLOPE Toolbox is distributed in the hope that it will 11 | % be useful, but WITHOUT ANY WARRANTY; without even the implied 12 | % warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | % See the GNU General Public License for more details. 14 | % 15 | % You should have received a copy of the GNU General Public License 16 | % along with the SLOPE Toolbox. If not, see 17 | % . 18 | 19 | mex proxSortedL1Mex.c proxSortedL1.c 20 | -------------------------------------------------------------------------------- /SLOPE_code/proxSortedL1.R: -------------------------------------------------------------------------------- 1 | proxSortedL1 <- function(x,lambda) 2 | { 3 | # Copyright 2013, M. Bogdan, E. van den Berg, W. Su, and E.J. Candes 4 | 5 | # This file is part of SLOPE Toolbox version 1.0. 6 | # 7 | # The SLOPE Toolbox is free software: you can redistribute it 8 | # and/or modify it under the terms of the GNU General Public License 9 | # as published by the Free Software Foundation, either version 3 of 10 | # the License, or (at your option) any later version. 11 | # 12 | # The SLOPE Toolbox is distributed in the hope that it will 13 | # be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 | # See the GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with the SLOPE Toolbox. If not, see 19 | # . 20 | 21 | # Normalize x 22 | if (is.complex(x)) 23 | { 24 | sign = Arg(x) 25 | x = Mod(x) 26 | } 27 | else 28 | { 29 | sign = sign(x) 30 | x = abs(x) 31 | } 32 | s = sort(x, decreasing=TRUE, index.return=TRUE) 33 | s$ix <- s$ix - 1 34 | n <- length(x) 35 | 36 | # Apply prox and inverse ordering 37 | result <- .C("cproxSortedL1", as.double(s$x), as.double(lambda), 38 | as.double(vector("double",n)),as.integer(n), 39 | as.integer(s$ix))[[3]] 40 | 41 | # Restore sign or phase 42 | result <- result * sign 43 | 44 | return(result) 45 | } 46 | -------------------------------------------------------------------------------- /SLOPE_code/proxSortedL1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013, M. Bogdan, E. van den Berg, W. Su, and E.J. Candes 3 | * 4 | * This file is part of SLOPE Toolbox version 1.0. 5 | * 6 | * The SLOPE Toolbox is free software: you can redistribute it 7 | * and/or modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation, either version 3 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * The SLOPE Toolbox is distributed in the hope that it will 12 | * be useful, but WITHOUT ANY WARRANTY; without even the implied 13 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 | * See the GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the SLOPE Toolbox. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef __PROX_ORDERED_L1__ 22 | #define __PROX_ORDERED_L1__ 23 | 24 | #include 25 | 26 | int evaluateProx(double *y, double *lambda, double *x, size_t n, int *order); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /SLOPE_code/proxSortedL1.m: -------------------------------------------------------------------------------- 1 | function x = proxSortedL1(y,lambda) 2 | 3 | % Copyright 2013, M. Bogdan, E. van den Berg, W. Su, and E.J. Candes 4 | 5 | % This file is part of SLOPE Toolbox version 1.0. 6 | % 7 | % The SLOPE Toolbox is free software: you can redistribute it 8 | % and/or modify it under the terms of the GNU General Public License 9 | % as published by the Free Software Foundation, either version 3 of 10 | % the License, or (at your option) any later version. 11 | % 12 | % The SLOPE Toolbox is distributed in the hope that it will 13 | % be useful, but WITHOUT ANY WARRANTY; without even the implied 14 | % warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 | % See the GNU General Public License for more details. 16 | % 17 | % You should have received a copy of the GNU General Public License 18 | % along with the SLOPE Toolbox. If not, see 19 | % . 20 | 21 | % Normalization 22 | lambda = lambda(:); 23 | y = y(:); 24 | sgn = sign(y); % Returns phase for complex numbers 25 | [y,idx] = sort(abs(y),'descend'); 26 | 27 | % Simplify the problem 28 | k = find(y > lambda,1,'last'); 29 | 30 | % Compute solution and re-normalize 31 | n = numel(y); 32 | x = zeros(n,1); 33 | 34 | if (~isempty(k)) 35 | v1 = y(1:k); 36 | v2 = lambda(1:k); 37 | v = proxSortedL1Mex(v1,v2); 38 | x(idx(1:k)) = v; 39 | end 40 | 41 | % Restore signs 42 | x = sgn .* x; 43 | -------------------------------------------------------------------------------- /SLOPE_code/test.txt: -------------------------------------------------------------------------------- 1 | % Copyright 2013, M. Bogdan, E. van den Berg, W. Su, and E.J. Candes 2 | 3 | % This file is part of SLOPE Toolbox version 1.0. 4 | % 5 | % The SLOPE Toolbox is free software: you can redistribute it 6 | % and/or modify it under the terms of the GNU General Public License 7 | % as published by the Free Software Foundation, either version 3 of 8 | % the License, or (at your option) any later version. 9 | % 10 | % The SLOPE Toolbox is distributed in the hope that it will 11 | % be useful, but WITHOUT ANY WARRANTY; without even the implied 12 | % warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | % See the GNU General Public License for more details. 14 | % 15 | % You should have received a copy of the GNU General Public License 16 | % along with the SLOPE Toolbox. If not, see 17 | % . 18 | 19 | A = load('data/testData_A.txt'); 20 | b = load('data/testData_b.txt'); 21 | lambda = load('data/testData_lambda.txt'); 22 | 23 | [x,info] = Adlas(A,b,lambda); 24 | 25 | x 26 | -------------------------------------------------------------------------------- /SLOPE_code/testAdlas.R: -------------------------------------------------------------------------------- 1 | # Copyright 2013, M. Bogdan, E. van den Berg, W. Su, and E.J. Candes 2 | 3 | # This file is part of SLOPE Toolbox version 1.0. 4 | # 5 | # The SLOPE Toolbox is free software: you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License 7 | # as published by the Free Software Foundation, either version 3 of 8 | # the License, or (at your option) any later version. 9 | # 10 | # The SLOPE Toolbox is distributed in the hope that it will 11 | # be useful, but WITHOUT ANY WARRANTY; without even the implied 12 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | # See the GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with the SLOPE Toolbox. If not, see 17 | # . 18 | 19 | dyn.load('cproxSortedL1.so') 20 | source('proxSortedL1.R') 21 | source('Adlas.R') 22 | 23 | A <- as.matrix(read.table('data/testData_A.txt' ,header=FALSE,colClasses="numeric")) 24 | b <- as.matrix(read.table('data/testData_b.txt' ,header=FALSE,colClasses="numeric")) 25 | lambda <- as.matrix(read.table('data/testData_lambda.txt',header=FALSE,colClasses="numeric")) 26 | 27 | colnames(A) <- NULL 28 | colnames(b) <- NULL 29 | colnames(lambda) <- NULL 30 | 31 | info <- Adlas(A,b,lambda) 32 | 33 | print(info$x) 34 | -------------------------------------------------------------------------------- /SLOPE_code/testAdlas.m: -------------------------------------------------------------------------------- 1 | % Copyright 2013, M. Bogdan, E. van den Berg, W. Su, and E.J. Candes 2 | 3 | % This file is part of SLOPE Toolbox version 1.0. 4 | % 5 | % The SLOPE Toolbox is free software: you can redistribute it 6 | % and/or modify it under the terms of the GNU General Public License 7 | % as published by the Free Software Foundation, either version 3 of 8 | % the License, or (at your option) any later version. 9 | % 10 | % The SLOPE Toolbox is distributed in the hope that it will 11 | % be useful, but WITHOUT ANY WARRANTY; without even the implied 12 | % warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | % See the GNU General Public License for more details. 14 | % 15 | % You should have received a copy of the GNU General Public License 16 | % along with the SLOPE Toolbox. If not, see 17 | % . 18 | 19 | A = load('data/testData_A.txt'); 20 | b = load('data/testData_b.txt'); 21 | lambda = load('data/testData_lambda.txt'); 22 | 23 | [x,info] = Adlas(A,b,lambda); 24 | 25 | x 26 | -------------------------------------------------------------------------------- /TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexa64 -------------------------------------------------------------------------------- /TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexmaci -------------------------------------------------------------------------------- /TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexmaci64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexmaci64 -------------------------------------------------------------------------------- /TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexw32 -------------------------------------------------------------------------------- /TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/fWHtrans.mexw64 -------------------------------------------------------------------------------- /TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/ifWHtrans.m: -------------------------------------------------------------------------------- 1 | function Y = ifWHtrans(X) 2 | % ifWHtrans computes fast inverse discrete Walsh-Hadamard transform 3 | % with sequency order. 4 | % 5 | % Since the forward and inverse transforms are exactly identical 6 | % operations, fastWHtrans.mexw32 is used to perform inverse transform. 7 | % 8 | % written by: Chengbo Li 9 | % Computational and Applied Mathematics Department, Rice University. 10 | % 02/15/2010 11 | 12 | Y = fWHtrans(X); 13 | % Perform scaling 14 | [m, n] = size(Y); 15 | Y = Y .* m; 16 | -------------------------------------------------------------------------------- /TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/newFWHTcmp.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TVAL3_beta2.4/Fast_Walsh_Hadamard_Transform/newFWHTcmp.fig -------------------------------------------------------------------------------- /TVAL3_beta2.4/Solver/TVAL3.m: -------------------------------------------------------------------------------- 1 | function [U,out] = TVAL3(A,b,p,q,opts) 2 | % Accordingly choose the code based on the model selected by the user. 3 | % 4 | % 1) TV model: min sum ||D_i u||. 5 | % s.t. Au = b 6 | % 2) TV/L2 model: min sum ||D_i u|| + mu/2||Au-b||_2^2 7 | % 8 | % Please use the default one if the user doesn't have a specific model to 9 | % solver. 10 | % 11 | % Written by: Chengbo Li 12 | % Advisor: Prof. Yin Zhang and Wotao Yin 13 | % Computational and Applied Mathematics department, Rice University 14 | % May. 15, 2009 15 | 16 | if ~isfield(opts,'TVL2') 17 | opts.TVL2 = false; 18 | end 19 | 20 | if opts.TVL2 21 | [U, out] = ftvcs_al_TVL2p(A,b,p,q,opts); 22 | else 23 | [U, out] = ftvcs_alp(A,b,p,q,opts); 24 | end -------------------------------------------------------------------------------- /TVAL3_beta2.4/User_Guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TVAL3_beta2.4/User_Guide.pdf -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/A_fWH.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % 3 | % A_fWH 4 | % 5 | % Written by: Chengbo Li 6 | % CAAM, Rice University 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | function b = A_fWH(x, OMEGA, P) 9 | 10 | 11 | N = length(x); 12 | 13 | x = x(:); 14 | fx = fWHtrans(x(P))*sqrt(N); 15 | b = fx(OMEGA); -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/At_fWH.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % 3 | % At_fWH 4 | % 5 | % Written by: Chengbo Li 6 | % CAAM, Rice University 7 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | function x = At_fWH(b, OMEGA, P) 9 | 10 | N = length(P); 11 | fx = zeros(N,1); 12 | fx(OMEGA) = b/sqrt(N); 13 | x = zeros(N,1); 14 | tmp = ifWHtrans(fx); 15 | x(P) = tmp(1:N); -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/Fp1d.m: -------------------------------------------------------------------------------- 1 | function Fpx = Fp1d(x,picks,n) 2 | 3 | [p,q] = size(x); 4 | msg = 'size of x not correct in Fp.m'; 5 | 6 | if q ~= 1 || p ~= n 7 | error(msg); 8 | end 9 | 10 | Fx = fft(x); 11 | Fx = Fx(picks); 12 | Fpx = [real(Fx); imag(Fx)]; -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/Fp2d.m: -------------------------------------------------------------------------------- 1 | function Fpx = Fp2d(x,picks,m,n) 2 | 3 | [p,q] = size(x); 4 | msg = 'size of x not correct in Fp2d.m'; 5 | 6 | if q == 1 7 | if p ~= (m*n) 8 | error(msg); 9 | else 10 | x = reshape(x,[m,n]); 11 | end 12 | elseif p ~= m || q ~= n 13 | error(msg); 14 | end 15 | 16 | Fx = fft2(x)/sqrt(m*n); 17 | Fx = Fx(picks); 18 | Fpx = [real(Fx); imag(Fx)]; 19 | -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/FpT1d.m: -------------------------------------------------------------------------------- 1 | function FpTy = FpT1d(y,picks,n) 2 | 3 | ly = length(y); 4 | rP = length(picks); 5 | if ly ~= 2*rP 6 | error('size not correct in FpT'); 7 | end 8 | 9 | FpTy = zeros(n,1); 10 | y = y(1:rP) + sqrt(-1)*y(rP+1:ly); 11 | FpTy(picks) = y; 12 | FpTy = real(ifft(FpTy)); -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/FpT2d.m: -------------------------------------------------------------------------------- 1 | function FpTy = FpT2d(y,picks,m,n) 2 | 3 | ly = length(y); 4 | rP = length(picks); 5 | if ly ~= 2*rP 6 | error('size not correct in FpT2d'); 7 | end 8 | 9 | FpTy = zeros(m,n); 10 | y = y(1:rP) + sqrt(-1)*y(rP+1:ly); 11 | FpTy(picks) = y; 12 | FpTy = real(ifft2(FpTy)*sqrt(m*n)); 13 | FpTy = FpTy(:); -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/MRImask.m: -------------------------------------------------------------------------------- 1 | function y = MRImask(n,beams) 2 | % 3 | % produces the fan MRI mask, of size n*n, 4 | % beams is the number of angles 5 | % 6 | m = ceil(sqrt(2)*n); 7 | aux = zeros(m,m); ima = aux; 8 | aux(round(m/2+1),:) = 1; 9 | angle = 180/beams; 10 | angles = [0:angle:180-angle]; 11 | for a = 1:length(angles) 12 | ang = angles(a); 13 | a = imrotate(aux,ang,'crop'); 14 | ima = ima + a; 15 | end 16 | ima = ima(round(m/2+1) - n/2:round(m/2+1) + n/2-1,... 17 | round(m/2+1) - n/2:round(m/2+1) + n/2-1); 18 | 19 | y = (ima > 0); 20 | -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/ScaleA.m: -------------------------------------------------------------------------------- 1 | function [mu,A,b] = ScaleA(n,mu,A,b,option) 2 | 3 | % Scales mu, A and f so that the largest eigenvalue of A'*A is 1 and the 4 | % new problem 5 | % 6 | % min sum_i (||wi|| + beta/2 ||Diu - wi||^2) + mu/2 ||Au - b||^2 7 | % 8 | % is equivalent to the old one. 9 | % 10 | % If option is assigned, mu will be scaled accordingly. 11 | % 12 | % Written by: Chengbo Li 13 | 14 | eopts.disp = 0; 15 | eopts.tol = .05; 16 | if ~isreal(A(rand(n,1),1)) 17 | eopts.isreal = false; 18 | end 19 | 20 | fh = @(x) A(A(x,1),2); 21 | s2 = eigs(fh,n,1,'lm',eopts); 22 | if real(s2) > 1 + 1e-10 23 | if option 24 | mu = mu*s2; 25 | end 26 | b = b/sqrt(s2); 27 | A = @(x,mode) A(x,mode)/sqrt(s2); 28 | end 29 | 30 | return -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/Scaleb.m: -------------------------------------------------------------------------------- 1 | function [mu,b,scl] = Scaleb(mu,b,option) 2 | 3 | % Scales mu and f so that the finite difference of f is neither too small 4 | % nor too large. 5 | % 6 | % If option is assigned, mu will be scaled accordingly. 7 | % 8 | % Written by: Chengbo Li 9 | 10 | 11 | threshold1 = .5; % threshold is chosen by experience. 12 | threshold2 = 1.5; 13 | scl = 1; 14 | b_dif = abs(max(b) - min(b)); 15 | 16 | if b_dif < threshold1 17 | scl = threshold1/b_dif; 18 | b = scl*b; 19 | if option 20 | mu = mu/scl; 21 | end 22 | else if b_dif > threshold2 23 | scl = threshold2/b_dif; 24 | b = scl*b; 25 | if option 26 | mu = mu/scl; 27 | end 28 | end 29 | end 30 | 31 | return -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/barbara256.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TVAL3_beta2.4/Utilities/barbara256.tif -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/defDDt.m: -------------------------------------------------------------------------------- 1 | function [D,Dt] = defDDt 2 | 3 | D = @(U) ForwardD(U); 4 | Dt = @(X,Y) Dive(X,Y); 5 | 6 | function [Dux,Duy] = ForwardD(U) 7 | % [ux,uy] = D u 8 | 9 | Dux = [diff(U,1,2), U(:,1) - U(:,end)]; 10 | Duy = [diff(U,1,1); U(1,:) - U(end,:)]; 11 | 12 | function DtXY = Dive(X,Y) 13 | % DtXY = D_1' X + D_2' Y 14 | 15 | DtXY = [X(:,end) - X(:, 1), -diff(X,1,2)]; 16 | DtXY = DtXY + [Y(end,:) - Y(1, :); -diff(Y,1,1)]; 17 | DtXY = DtXY(:); -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/f_handleA.m: -------------------------------------------------------------------------------- 1 | function y = f_handleA(A,u,mode) 2 | 3 | switch mode 4 | case 1 5 | y = A*u; 6 | case 2 7 | y = (u'*A)'; 8 | otherwise 9 | error('Unknown mode passed to f_handleA in ftv_cs.m'); 10 | end 11 | 12 | end -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/getA.m: -------------------------------------------------------------------------------- 1 | function [A, At] = getA(m,p,q,picks,mtx,dim) 2 | 3 | if strcmp(mtx,'randn') 4 | B = randn(m,p*q); 5 | 6 | % random A -- 1 7 | [B,R] = qr(B',0); 8 | B = B'; 9 | 10 | % %% random A -- 2 11 | % d = sqrt(sum(B'.^2)); 12 | % B = sparse(1:m,1:m,1./d)*B; 13 | 14 | 15 | A = @(x) B*x; 16 | At = @(y) (y'*B)'; 17 | elseif strcmp(mtx,'PF') 18 | if dim == 2 19 | % 2D partial Fourier 20 | A = @(x) Fp2d(x,picks,p,q); 21 | At = @(y) FpT2d(y,picks,p,q); 22 | elseif dim == 1 23 | % 1D partial Fourier 24 | A = @(x) Fp1d(x,picks,p); 25 | At = @(y) FpT1d(y,picks,p); 26 | end 27 | end -------------------------------------------------------------------------------- /TVAL3_beta2.4/Utilities/isinInterval.m: -------------------------------------------------------------------------------- 1 | function res = isinInterval(val,lb,ub,eok) 2 | 3 | % Checks to make sure that val is a real scalar in [lb,ub] if eok is true, 4 | % or in (lb,ub) if eok is false. 5 | 6 | res = true; 7 | 8 | if ~isscalar(val), res = false; end 9 | if ~isreal(val), res = false; end 10 | if eok 11 | if val < lb || val > ub, res = false; end 12 | else 13 | if val <= lb || val >= ub, res = false; end 14 | end 15 | 16 | return -------------------------------------------------------------------------------- /TVAL3_beta2.4/demo.m: -------------------------------------------------------------------------------- 1 | % This simple demo examines if TVAL3 works normally. Please try more demos 2 | % in the "Demos" directory, which would show users what TVAL3 is capable of. 3 | % 4 | % I: 64x64 phantom (real, two-dimentional) 5 | % A: random matrix without normality and orthogonality (real) 6 | % f: observation with/without noise (real) 7 | % 8 | % Written by: Chengbo Li 9 | % Advisor: Prof. Yin Zhang and Wotao Yin 10 | % CAAM department, Rice University 11 | % 05/21/2009 12 | 13 | clear; close all; 14 | path(path,genpath(pwd)); 15 | fullscreen = get(0,'ScreenSize'); 16 | 17 | % problem size 18 | n = 64; 19 | ratio = .3; 20 | p = n; q = n; % p x q is the size of image 21 | m = round(ratio*n^2); 22 | 23 | % sensing matrix 24 | A = rand(m,p*q)-.5; 25 | 26 | % original image 27 | I = phantom(n); 28 | nrmI = norm(I,'fro'); 29 | figure('Name','TVAL3','Position',... 30 | [fullscreen(1) fullscreen(2) fullscreen(3) fullscreen(4)]); 31 | subplot(121); imshow(I,[]); 32 | title('Original phantom','fontsize',18); drawnow; 33 | 34 | % observation 35 | f = A*I(:); 36 | favg = mean(abs(f)); 37 | 38 | % add noise 39 | f = f + .00*favg*randn(m,1); 40 | 41 | 42 | %% Run TVAL3 43 | clear opts 44 | opts.mu = 2^8; 45 | opts.beta = 2^5; 46 | opts.tol = 1E-3; 47 | opts.maxit = 300; 48 | opts.TVnorm = 1; 49 | opts.nonneg = true; 50 | 51 | t = cputime; 52 | [U, out] = TVAL3(A,f,p,q,opts); 53 | t = cputime - t; 54 | 55 | 56 | subplot(122); 57 | imshow(U,[]); 58 | title('Recovered by TVAL3','fontsize',18); 59 | xlabel(sprintf(' %2d%% measurements \n Rel-Err: %4.2f%%, CPU: %4.2fs ',ratio*100,norm(U-I,'fro')/nrmI*100,t),'fontsize',16); 60 | -------------------------------------------------------------------------------- /TVAL3_beta2.4/warm_up.m: -------------------------------------------------------------------------------- 1 | % 2 | % set paths: users must make sure that all folders and subfolders 3 | % are in cluded in MATLAB working paths. This can be done either 4 | % manually or by running the following line in MATLAB command window 5 | % 6 | path(path,genpath(pwd)); 7 | if exist('fWHtrans','file') ~= 3 8 | cd Fast_Walsh_Hadamard_Transform; 9 | mex -O fWHtrans.cpp 10 | cd ..; 11 | fprintf('Finished compiling the C++ code for fast Walsh-Hadamard transform!\n'); 12 | end 13 | fprintf('Finished adding paths! Welcome to use TVAL3 beta2.4.\n'); -------------------------------------------------------------------------------- /TwIST/TwIST_v2/MRImask.m: -------------------------------------------------------------------------------- 1 | function y = MRImask(n,beams) 2 | % 3 | % produces the fan MRI mask, of size n*n, 4 | % beams is the number of angles 5 | % 6 | m = ceil(sqrt(2)*n); 7 | aux = zeros(m,m); ima = aux; 8 | aux(round(m/2+1),:) = 1; 9 | angle = 180/beams; 10 | angles = [0:angle:180-angle]; 11 | for a = 1:length(angles) 12 | ang = angles(a); 13 | a = imrotate(aux,ang,'crop'); 14 | ima = ima + a; 15 | end 16 | ima = ima(round(m/2+1) - n/2:round(m/2+1) + n/2-1,... 17 | round(m/2+1) - n/2:round(m/2+1) + n/2-1); 18 | 19 | y = (ima > 0); 20 | -------------------------------------------------------------------------------- /TwIST/TwIST_v2/README.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TwIST/TwIST_v2/README.txt -------------------------------------------------------------------------------- /TwIST/TwIST_v2/TVnorm.m: -------------------------------------------------------------------------------- 1 | function y = TVnorm(x) 2 | y = sum(sum(sqrt(diffh(x).^2+diffv(x).^2))); 3 | -------------------------------------------------------------------------------- /TwIST/TwIST_v2/conv2c.m: -------------------------------------------------------------------------------- 1 | function y = conv2c(x,h) 2 | % Circular 2D convolution 3 | x=wraparound(x,h); 4 | y=conv2(x,h,'valid'); 5 | 6 | 7 | function y = wraparound(x, m) 8 | % Extend x so as to wrap around on both axes, sufficient to allow a 9 | % "valid" convolution with m to return the cyclical convolution. 10 | % We assume mask origin near centre of mask for compatibility with 11 | % "same" option. 12 | [mx, nx] = size(x); 13 | [mm, nm] = size(m); 14 | if mm > mx | nm > nx 15 | error('Mask does not fit inside array') 16 | end 17 | 18 | mo = floor((1+mm)/2); no = floor((1+nm)/2); % reflected mask origin 19 | ml = mo-1; nl = no-1; % mask left/above origin 20 | mr = mm-mo; nr = nm-no; % mask right/below origin 21 | me = mx-ml+1; ne = nx-nl+1; % reflected margin in input 22 | mt = mx+ml; nt = nx+nl; % top of image in output 23 | my = mx+mm-1; ny = nx+nm-1; % output size 24 | 25 | y = zeros(my, ny); 26 | y(mo:mt, no:nt) = x; % central region 27 | if ml > 0 28 | y(1:ml, no:nt) = x(me:mx, :); % top side 29 | if nl > 0 30 | y(1:ml, 1:nl) = x(me:mx, ne:nx); % top left corner 31 | end 32 | if nr > 0 33 | y(1:ml, nt+1:ny) = x(me:mx, 1:nr); % top right corner 34 | end 35 | end 36 | if mr > 0 37 | y(mt+1:my, no:nt) = x(1:mr, :); % bottom side 38 | if nl > 0 39 | y(mt+1:my, 1:nl) = x(1:mr, ne:nx); % bottom left corner 40 | end 41 | if nr > 0 42 | y(mt+1:my, nt+1:ny) = x(1:mr, 1:nr); % bottom right corner 43 | end 44 | end 45 | if nl > 0 46 | y(mo:mt, 1:nl) = x(:, ne:nx); % left side 47 | end 48 | if nr > 0 49 | y(mo:mt, nt+1:ny) = x(:, 1:nr); % right side 50 | end 51 | -------------------------------------------------------------------------------- /TwIST/TwIST_v2/demo_MRI.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TwIST/TwIST_v2/demo_MRI.m -------------------------------------------------------------------------------- /TwIST/TwIST_v2/demo_Piecewise_cubic_polynomial.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TwIST/TwIST_v2/demo_Piecewise_cubic_polynomial.m -------------------------------------------------------------------------------- /TwIST/TwIST_v2/demo_l2_TV.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TwIST/TwIST_v2/demo_l2_TV.m -------------------------------------------------------------------------------- /TwIST/TwIST_v2/demo_l2_l0.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TwIST/TwIST_v2/demo_l2_l0.m -------------------------------------------------------------------------------- /TwIST/TwIST_v2/demo_l2_l1.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TwIST/TwIST_v2/demo_l2_l1.m -------------------------------------------------------------------------------- /TwIST/TwIST_v2/demo_l2_l1_debias.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TwIST/TwIST_v2/demo_l2_l1_debias.m -------------------------------------------------------------------------------- /TwIST/TwIST_v2/demo_sinusoids_l2_l1.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TwIST/TwIST_v2/demo_sinusoids_l2_l1.m -------------------------------------------------------------------------------- /TwIST/TwIST_v2/demo_wave_DWT_deconv.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TwIST/TwIST_v2/demo_wave_DWT_deconv.m -------------------------------------------------------------------------------- /TwIST/TwIST_v2/diffh.m: -------------------------------------------------------------------------------- 1 | function sol=diffh(x) 2 | h=[0 1 -1]; 3 | sol=conv2c(x,h); -------------------------------------------------------------------------------- /TwIST/TwIST_v2/diffv.m: -------------------------------------------------------------------------------- 1 | function sol=diffv(x) 2 | h=[0 1 -1]'; 3 | sol=conv2c(x,h); -------------------------------------------------------------------------------- /TwIST/TwIST_v2/hard.m: -------------------------------------------------------------------------------- 1 | function z = hard(x,lambda) 2 | % z = hard(x,lambda) 3 | % 4 | % --- Hard threshold ---- 5 | % 6 | % z is the solution of 7 | % 8 | % z= arg min_x = 0.5*|| y - x ||_2^2 + lambda || x ||_0, 9 | % 10 | 11 | z = x.*(abs(x) >= sqrt(2*lambda)); 12 | -------------------------------------------------------------------------------- /TwIST/TwIST_v2/l0norm.m: -------------------------------------------------------------------------------- 1 | function y = l0norm(x) 2 | % y = l0norm(x) 3 | % 4 | % --- l0 norm ox x 5 | y = sum(abs(x(:))~=0); 6 | -------------------------------------------------------------------------------- /TwIST/TwIST_v2/masked_FFT.m: -------------------------------------------------------------------------------- 1 | function y = masked_FFT(x,mask) 2 | % 3 | % Computes a 2D partial FFT transform, 4 | % only for those frequencies for which 5 | % mask is not zero. The result is returned 6 | % in an array of size (k,1) where k is 7 | % the number of non-zeros in mask. 8 | % The transpose of this operator is 9 | % available in the function masked_FFT_t.m 10 | % 11 | % Copyright, 2006, Mario Figueiredo. 12 | % 13 | % 14 | [n1 n2] = size(x); 15 | if n1~=n2 16 | disp('only square images, please!') 17 | return 18 | end 19 | n = n1; 20 | if floor(log2(n))~=log2(n) 21 | disp('only power of 2 sizes, please!') 22 | return 23 | end 24 | if sum(sum(size(mask)~=size(x)))~=0 25 | disp('Mask must have the same size as x'); 26 | return 27 | end 28 | ii = find(abs(mask)>0); 29 | Rf = fftshift(fft2(x)).*mask/n; 30 | y = Rf(ii); 31 | 32 | 33 | -------------------------------------------------------------------------------- /TwIST/TwIST_v2/masked_FFT_t.m: -------------------------------------------------------------------------------- 1 | function y = masked_FFT_t(x,mask) 2 | % 3 | % This is the transpose operator of the 4 | % partial FFT transform, implemented in 5 | % masked_FFT.m. See that file for details. 6 | % 7 | [n1,n2] = size(mask); 8 | if n1~=n2 9 | disp('only square images please!') 10 | return 11 | end 12 | n = n1; 13 | if floor(log2(n))~=log2(n) 14 | disp('only power of 2 sizes, please!') 15 | return 16 | end 17 | ii=find(abs(mask)>0); 18 | gg = zeros(n,n); 19 | gg(ii)=x./mask(ii); 20 | y = real(ifft2(ifftshift(gg)))*n; 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /TwIST/TwIST_v2/mex_vartotale.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TwIST/TwIST_v2/mex_vartotale.dll -------------------------------------------------------------------------------- /TwIST/TwIST_v2/mex_vartotale.m: -------------------------------------------------------------------------------- 1 | function [img_estimated]=mex_vartotale(img_noisy,lambda,varargin) 2 | % function [img_estimated]=mex_vartotale(img_noisy,lambda,varargin) 3 | % 4 | % 5 | % 6 | % ========================== INPUT PARAMETERS (required) ================= 7 | % Parameter Values 8 | % name and description 9 | % ======================================================================== 10 | % img_noisy (double) Noisy image of size ny. 11 | % lambda Regularization parameter (which is multiplied by the 12 | % TV penalty). 13 | % 14 | % ======================== OPTIONAL INPUT PARAMETERS ==================== 15 | % Parameter Values 16 | % name and description 17 | % ======================================================================= 18 | % itmax The maximum number of iterations. 19 | % Default: 300 20 | % epsilon (double) Maximum error tolerance stopping criterium. 21 | % Default: 0.0005 22 | % tau (double) Algorithm tau parameter. 23 | % Default: 0.249 24 | % 25 | % ====================== Output parameters =============================== 26 | % img_estimated Estimated image 27 | % 28 | % -------------------------------------------------------------------------------- /TwIST/TwIST_v2/soft.m: -------------------------------------------------------------------------------- 1 | function y = soft(x,T) 2 | 3 | y = max(abs(x) - T, 0); 4 | y = y./(y+T) .* x; 5 | 6 | -------------------------------------------------------------------------------- /TwIST/bak/TwIST_v2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/TwIST/bak/TwIST_v2.zip -------------------------------------------------------------------------------- /[ToolBox]/.gitkeep: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file !.gitkeep 4 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/bak/ksvdbox13.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/bak/ksvdbox13.zip -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/bak/ksvdsbox11-min.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/bak/ksvdsbox11-min.zip -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/bak/ksvdsbox11.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/bak/ksvdsbox11.zip -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/bak/ompbox10.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/bak/ompbox10.zip -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/bak/ompsbox1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/bak/ompsbox1.zip -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/Contents.m: -------------------------------------------------------------------------------- 1 | %KSVDBox - Implementation of the K-SVD and K-SVD denoise algorithms. 2 | % 3 | %Ron Rubinstein, Computer Science Department 4 | %Technion -- Israel Institute of Technology 5 | %ronrubin@cs.technion.ac.il 6 | % 7 | % 8 | %K-SVD dictionary training. 9 | % ksvd - K-SVD dictionary training. 10 | % 11 | %Signal denoising. 12 | % ompdenoise - OMP denoising. 13 | % ompdenoise1 - OMP denoising of 1-D signals. 14 | % ompdenoise2 - OMP denoising of 2-D signals. 15 | % ompdenoise3 - OMP denoising of 3-D signals. 16 | % ksvddenoise - K-SVD denoising. 17 | % 18 | %Overcomplete DCT dictionary. 19 | % odctdict - Overcomplete DCT dictionary. 20 | % odct2dict - 2-D overcomplete DCT dictionary. 21 | % odct3dict - 3-D overcomplete DCT dictionary. 22 | % odctndict - Multi-dimensional overcomplete DCT dictionary. 23 | % 24 | %Demonstrations. 25 | % ksvddemo - K-SVD training demonstration. 26 | % ksvddenoisedemo - K-SVD denoising demonstration. 27 | % 28 | %Miscellaneous. 29 | % showdict - Display a dictionary of image patches. 30 | % ksvdver - K-SVD toolbox version information. 31 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/images/barbara.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/ksvdbox13/images/barbara.png -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/images/boat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/ksvdbox13/images/boat.png -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/images/house.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/ksvdbox13/images/house.png -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/images/lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/ksvdbox13/images/lena.png -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/images/peppers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/ksvdbox13/images/peppers.png -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/ksvddemo.m: -------------------------------------------------------------------------------- 1 | function ksvddemo 2 | %KSVDDEMO K-SVD training demonstration. 3 | % KSVDDEMO generates random sparse examples over a random overcomplete 4 | % dictionary, adds noise, and uses K-SVD to recover the dictionary from 5 | % the examples. 6 | % 7 | % To run the demo, type KSVDDEMO from the Matlab prompt. 8 | % 9 | % See also KSVDDENOISEDEMO. 10 | 11 | 12 | % Ron Rubinstein 13 | % Computer Science Department 14 | % Technion, Haifa 32000 Israel 15 | % ronrubin@cs 16 | % 17 | % May 2009 18 | 19 | 20 | disp(' '); 21 | disp(' ********** K-SVD Demo **********'); 22 | disp(' '); 23 | disp(' This demo generates a random dictionary and random sparse examples over this'); 24 | disp(' dictionary. It then adds noise to the examples, and uses K-SVD to recover'); 25 | disp(' the dictionary. The demo plots the convergence of the K-SVD target function,'); 26 | disp(' and computes the fraction of correctly recovered atoms.'); 27 | disp(' '); 28 | 29 | 30 | % dictionary dimensions 31 | n = 20; 32 | m = 50; 33 | 34 | % number of examples 35 | L = 1500; 36 | 37 | % sparsity of each example 38 | k = 3; 39 | 40 | % noise power (dB) 41 | snr = 20; 42 | 43 | 44 | 45 | %% generate random dictionary and data %% 46 | 47 | D = normcols(randn(n,m)); 48 | 49 | Gamma = zeros(m,L); 50 | for i = 1:L 51 | p = randperm(m); 52 | Gamma(p(1:k),i) = randn(k,1); 53 | end 54 | 55 | X = D*Gamma; 56 | 57 | X = normcols(X) + 10^(-snr/20)*normcols(randn(n,L)); 58 | 59 | 60 | 61 | %% run k-svd training %% 62 | 63 | params.data = X; 64 | params.Tdata = k; 65 | params.dictsize = m; 66 | params.iternum = 30; 67 | params.memusage = 'high'; 68 | 69 | [Dksvd,g,err] = ksvd(params,''); 70 | 71 | 72 | %% show results %% 73 | 74 | figure; plot(err); title('K-SVD error convergence'); 75 | xlabel('Iteration'); ylabel('RMSE'); 76 | 77 | printf(' Dictionary size: %d x %d', n, m); 78 | printf(' Number of examples: %d', L); 79 | 80 | [dist,ratio] = dictdist(Dksvd,D); 81 | printf(' Ratio of recovered atoms: %.2f%%\n', ratio*100); 82 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/odct2dict.m: -------------------------------------------------------------------------------- 1 | function D = odct2dict(n,L) 2 | %ODCT2DICT 2-D overcomplete DCT dictionary. 3 | % D = ODCT2DICT([N1 N2],[L1 L2]) returns an overcomplete DCT dictionary 4 | % for signals of size N1xN2. The number of dictionary atoms in the i-th 5 | % dimension is Li, so the combined dictionary is of size (N1*N2)x(L1*L2). 6 | % 7 | % D = ODCT2DICT([N1 N2],L) specifies the total number of atoms in the 8 | % dictionary, instead of L1 and L2 individually. L1 and L2 in this case 9 | % are selected so that L1/L2 ~ N1/N2, by letting L1=ceil(sqrt(L*N1/N2)) 10 | % and L2=ceil(sqrt(L*N2/N1)). Note that the actual number of atoms in the 11 | % dictionary may be larger than L. 12 | % 13 | % D = ODCT2DICT(N,L) is shorthand for the call ODCT2DICT([N N],L), and 14 | % returns the overcomplete DCT dictionary for signals of size NxN. L is 15 | % the required size of the overcomplete dictionary, and is rounded up to 16 | % the nearest square integer. 17 | % 18 | % See also ODCTDICT, ODCT3DICT, ODCTNDICT. 19 | 20 | % Ron Rubinstein 21 | % Computer Science Department 22 | % Technion, Haifa 32000 Israel 23 | % ronrubin@cs 24 | % 25 | % April 2009 26 | 27 | D = odctndict(n,L,2); 28 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/odct3dict.m: -------------------------------------------------------------------------------- 1 | function D = odct3dict(n,L) 2 | %ODCT3DICT 3-D overcomplete DCT dictionary. 3 | % D = ODCT3DICT([N1 N2 N3],[L1 L2 L3]) returns an overcomplete DCT 4 | % dictionary for signals of size N1xN2xN3. The number of dictionary atoms 5 | % in the i-th dimension is Li, so the combined dictionary is of size 6 | % (N1*N2*N3) x (L1*L2*L3). 7 | % 8 | % D = ODCT3DICT([N1 N2 N3],L) specifies the total number of atoms in the 9 | % dictionary instead of each of the Li's individually. The Li's in this 10 | % case are selected so their relative sizes are roughly the same as the 11 | % relative sizes of the Ni's. Note that the actual number of atoms in the 12 | % dictionary may be larger than L, as rounding might be required for the 13 | % computation of the Li's. 14 | % 15 | % D = ODCT3DICT(N,L) is shorthand for the call ODCT2DICT([N N N],L), and 16 | % returns the overcomplete DCT dictionary for signals of size NxNxN. L is 17 | % the required size of the overcomplete dictionary, and is rounded up to 18 | % the nearest cubic integer. 19 | % 20 | % See also ODCTDICT, ODCT2DICT, ODCTNDICT. 21 | 22 | % Ron Rubinstein 23 | % Computer Science Department 24 | % Technion, Haifa 32000 Israel 25 | % ronrubin@cs 26 | % 27 | % April 2009 28 | 29 | D = odctndict(n,L,3); 30 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/odctdict.m: -------------------------------------------------------------------------------- 1 | function D = odctdict(n,L) 2 | %ODCTDICT Overcomplete DCT dictionary. 3 | % D = ODCTDICT(N,L) returns the overcomplete DCT dictionary of size NxL 4 | % for signals of length N. 5 | % 6 | % See also ODCT2DICT, ODCT3DICT, ODCTNDICT. 7 | 8 | % Ron Rubinstein 9 | % Computer Science Department 10 | % Technion, Haifa 32000 Israel 11 | % ronrubin@cs 12 | % 13 | % April 2009 14 | 15 | 16 | %% original implementation by ronrubin 17 | % D = zeros(n,L); 18 | % D(:,1) = 1/sqrt(n); 19 | % for k = 2:L 20 | % v = cos((0:n-1)*pi*(k-1)/L)'; 21 | % v = v-mean(v); 22 | % D(:,k) = v/norm(v); 23 | % end 24 | 25 | %% accelerated by Zhihong Zhang 26 | D = zeros(n,L); 27 | D(:,1) = 1/sqrt(n); 28 | 29 | [X,Y] = ndgrid(0:n-1,2:L); 30 | V = cos(X.*pi.*(Y-1)./L); 31 | V = V-mean(V); 32 | V = V./repmat(vecnorm(V),n,1); 33 | 34 | D(:,2:end) = V; 35 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/odctndict.m: -------------------------------------------------------------------------------- 1 | function D = odctndict(n,L,p) 2 | %ODCTNDICT Multi-dimensional overcomplete DCT dictionary. 3 | % D = ODCTNDICT([N1 N2 ... Np],[L1 L2 ... Lp]) returns an overcomplete DCT 4 | % dictionary for p-dimensional signals of size N1xN2x...xNp. The number of 5 | % DCT atoms in the i-th dimension is Li, so the combined dictionary is of 6 | % size (N1*N2*...*Np) x (L1*L2*...*Lp). 7 | % 8 | % D = ODCTNDICT([N1 N2 ... Np],L) specifies the total number of atoms in 9 | % the dictionary instead of each of the Li's individually. The Li's in 10 | % this case are selected so their relative sizes are roughly the same as 11 | % the relative sizes of the Ni's. Note that the actual number of atoms in 12 | % the dictionary may be larger than L, as rounding might be required for 13 | % the computation of the Li's. 14 | % 15 | % D = ODCTNDICT(N,L,P) is shorthand for the call ODCTNDICT(N*ones(1,P),L), 16 | % and returns the overcomplete DCT dictionary for P-dimensional signals of 17 | % size NxNx...xN. L is the required size of the overcomplete dictionary, 18 | % and is rounded up to the nearest integer with a whole P-th root. 19 | % 20 | % See also ODCTDICT, ODCT2DICT, ODCT3DICT. 21 | 22 | % Ron Rubinstein 23 | % Computer Science Department 24 | % Technion, Haifa 32000 Israel 25 | % ronrubin@cs 26 | % 27 | % April 2009 28 | 29 | if (nargin==2) 30 | p = length(n); 31 | end 32 | 33 | if (length(n)==1) 34 | n = n*ones(1,p); 35 | end 36 | 37 | if (length(L)==1 && p>1) 38 | N = prod(n); 39 | L = ceil((L*(n.^p/N).^(1/(p-1))).^(1/p)); 40 | end 41 | 42 | D = odctdict(n(1),L(1)); 43 | for i = 2:p 44 | D = kron(D,odctdict(n(i),L(i))); 45 | end 46 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/add_dc.m: -------------------------------------------------------------------------------- 1 | function x = add_dc(y,dc,columns) 2 | %ADD_DC Add DC channel to signals. 3 | % X = ADD_DC(Y,DC) adds the specified DC value to the (possibly 4 | % multi-dimensional) signal Y, returning the result as X. DC should be a 5 | % scalar value. 6 | % 7 | % X = ADD_DC(Y,DC,'columns') where Y is a 2D matrix and DC is an array of 8 | % length size(Y,2), treats the columns of Y as individual 1D signals, 9 | % adding to each one the corresponding DC value from the DC array. X is 10 | % the same size as Y and contains the resulting signals. 11 | % 12 | % See also REMOVE_DC. 13 | 14 | % Ron Rubinstein 15 | % Computer Science Department 16 | % Technion, Haifa 32000 Israel 17 | % ronrubin@cs 18 | % 19 | % April 2009 20 | 21 | 22 | if (nargin==3 && strcmpi(columns,'columns')), columns = 1; 23 | else columns = 0; 24 | end 25 | 26 | if (columns) 27 | x = addtocols(y,dc); 28 | else 29 | x = y + dc; 30 | end 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/addtocols.m: -------------------------------------------------------------------------------- 1 | %ADDTOCOLS Add values to the columns of a matrix. 2 | % Y=ADDTOCOLS(X,V) adds to each column of the MxN matrix X the 3 | % corresponding value from the N-element vector V. 4 | % 5 | % See also NORMCOLS. 6 | 7 | 8 | % Ron Rubinstein 9 | % Computer Science Department 10 | % Technion, Haifa 32000 Israel 11 | % ronrubin@cs 12 | % 13 | % June 2005 14 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/col2imstep.m: -------------------------------------------------------------------------------- 1 | %COL2IMSTEP Rearrange matrix columns into blocks. 2 | % A = COL2IMSTEP(B,[MM NN],[N1 N2]) rearranges the columns of B into 3 | % sliding N1-by-N2 blocks producing the matrix A of size MM-by-NN. B is 4 | % usually the result of calling IM2COLSTEP(...) with a stepsize of 1, or 5 | % using Matlab's IM2COL(..,'sliding'). Overlapping blocks are summed in A. 6 | % 7 | % A = COL2IMSTEP(B,[MM NN],[N1 N2],[S1 S2]) arranges the blocks in A with 8 | % a step size of (S1,S2) between them. The first block is at A(1:N1,1:N2), 9 | % and the rest are at A((1:N1)+i*S1,(1:N2)+j*S2). Overlapping blocks are 10 | % summed in A. Note that B is usually the result of calling 11 | % IM2COLSTEP(...) with a stepsize of [S1 S2]. 12 | % 13 | % A = IM2COLSTEP(B,[MM NN KK],[N1 N2 N3],[S1 S2 S3]) generates a 3-D 14 | % output matrix A. The step size [S1 S2 S3] may be ommitted, and defaults 15 | % to [1 1 1]. 16 | % 17 | % See also IM2COLSTEP, IM2COL, COUNTCOVER. 18 | 19 | 20 | % Ron Rubinstein 21 | % Computer Science Department 22 | % Technion, Haifa 32000 Israel 23 | % ronrubin@cs 24 | % 25 | % August 2009 26 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/collincomb.m: -------------------------------------------------------------------------------- 1 | %COLLINCOMB Linear combination of matrix columns. 2 | % Y = COLLINCOMB(A,COLS,X) computes a linear combination of the columns of 3 | % the matrix A. The column indices are specified in the vector COLS, and 4 | % the correspoinding coefficients are specified in the vector X. The 5 | % vectors COLS and X must be of the same length. 6 | % 7 | % The call Y = COLLINCOMB(A,COLS,X) is essentially equivalent to 8 | % 9 | % Y = A(:,COLS)*X . 10 | % 11 | % However, it is implemented much more efficiently. 12 | % 13 | % Y = COLLINCOMB(A,ROWS,COLS,X) only works on the rows of A specified 14 | % in ROWS, returning a vector of length equal to ROWS. This call is 15 | % essentially equivalent to the command 16 | % 17 | % Y = A(ROWS,COLS)*X . 18 | % 19 | % See also ROWLINCOMB. 20 | 21 | 22 | % Ron Rubinstein 23 | % Computer Science Department 24 | % Technion, Haifa 32000 Israel 25 | % ronrubin@cs 26 | % 27 | % April 2009 28 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/countcover.m: -------------------------------------------------------------------------------- 1 | function cnt = countcover(sz,blocksize,stepsize) 2 | %COUNTCOVER Covering of signal samples by blocks 3 | % CNT = COUNTCOVER(SZ,BLOCKSIZE,STEPSIZE) assumes a p-dimensional signal 4 | % of size SZ=[N1 N2 ... Np] covered by (possibly overlapping) blocks of 5 | % size BLOCKSIZE=[M1 M2 ... Mp]. The blocks start at position (1,1,..,1) 6 | % and are shifted between them by steps of size STEPSIZE=[S1 S2 ... Sp]. 7 | % COUNTCOVER returns a matrix the same size as the signal, containing in 8 | % each entry the number of blocks covering that sample. 9 | % 10 | % See also IM2COLSTEP, COL2IMSTEP, IM2COL. 11 | 12 | 13 | % Ron Rubinstein 14 | % Computer Science Department 15 | % Technion, Haifa 32000 Israel 16 | % ronrubin@cs 17 | % 18 | % August 2008 19 | 20 | 21 | cnt = ones(sz); 22 | for k = 1:length(sz) 23 | 24 | % this code is modified from function NDGRID, so it computes one 25 | % output argument of NDGRID at a time (to conserve memory) 26 | ids = (1:sz(k))'; 27 | s = sz; s(k) = []; 28 | ids = reshape(ids(:,ones(1,prod(s))),[length(ids) s]); 29 | ids = permute(ids,[2:k 1 k+1:length(sz)]); 30 | 31 | cnt = cnt .* max( min(floor((ids-1)/stepsize(k)),floor((sz(k)-blocksize(k))/stepsize(k))) - ... 32 | max(ceil((ids-blocksize(k))/stepsize(k)),0) + 1 , 0 ); 33 | end 34 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/dictdist.m: -------------------------------------------------------------------------------- 1 | function [dist,ratio] = dictdist(approxD,D,epsilon) 2 | %DICTDIST Distance between dictionaries. 3 | % [DIST,RATIO] = DICTDIST(APPROXD,D) computes the distance between the 4 | % approximate dictionary APPROXD and the true dictionary D, where APPROXD 5 | % is NxK and D is NxM. 6 | % 7 | % The distance between the dictionary APPROXD and a single atom A of D is 8 | % defined as: 9 | % 10 | % DIST(APPROXD,A) = min { 1-abs(APPROXD(:,i)' * A) } 11 | % i 12 | % 13 | % The distance between the dictionaries APPROXD and D is defined as: 14 | % 15 | % DIST(APPROXD,D) = sum { dist(APPROXD, D(:,k)) } / M 16 | % k 17 | % 18 | % Note that 0 <= DIST(APPROXD,D) <= 1, where 0 implies that all atoms in D 19 | % appear in APPROXD, and 1 implies that the atoms of D are orthogonal to 20 | % APPROXD. 21 | % 22 | % The similarity ratio between APPROXD and D is defined as: 23 | % 24 | % RATIO(APPROXD,D) = #(atoms in D that appear in APPROXD) / M 25 | % 26 | % where two atoms are considered identical when DIST(A1,A2) < EPSILON with 27 | % EPSILON=0.01 by default. Note that 0 <= RATIO(APPROXD,D) <= 1, where 0 28 | % means APPROXD and D have no identical atoms, and 1 means that all atoms 29 | % of D appear in APPROXD. 30 | % 31 | % [DIST,RATIO] = DICTDIST(DICT1,DICT2,EPSILON) specifies a different value 32 | % for EPSILON. 33 | 34 | % Ron Rubinstein 35 | % Computer Science Department 36 | % Technion, Haifa 32000 Israel 37 | % ronrubin@cs 38 | % 39 | % October 2007 40 | 41 | 42 | if (nargin < 3), epsilon = 0.01; end 43 | 44 | [n,m] = size(D); 45 | 46 | approxD = normcols(approxD*spdiag(sign(approxD(1,:)))); 47 | D = normcols(D*spdiag(sign(D(1,:)))); 48 | 49 | identical_atoms = 0; 50 | dist = 0; 51 | 52 | for i = 1:m 53 | atom = D(:,i); 54 | distances = 1-abs(atom'*approxD); 55 | mindist = min(distances); 56 | dist = dist + mindist; 57 | identical_atoms = identical_atoms + (mindist < epsilon); 58 | end 59 | 60 | dist = dist / m; 61 | ratio = identical_atoms / m; 62 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/im2colstep.m: -------------------------------------------------------------------------------- 1 | %IM2COLSTEP Rearrange matrix blocks into columns. 2 | % B = IM2COLSTEP(A,[N1 N2]) converts each sliding N1-by-N2 block of the 3 | % 2-D matrix A into a column of B, with no zero padding. B has N1*N2 rows 4 | % and will contain as many columns as there are N1-by-N2 neighborhoods in 5 | % A. Each column of B contains a neighborhood of A reshaped as NHOOD(:), 6 | % where NHOOD is a matrix containing an N1-by-N2 neighborhood of A. 7 | % 8 | % B = IM2COLSTEP(A,[N1 N2],[S1 S2]) extracts neighborhoods of A with a 9 | % step size of (S1,S2) between them. The first extracted neighborhood is 10 | % A(1:N1,1:N2), and the rest are of the form A((1:N1)+i*S1,(1:N2)+j*S2). 11 | % Note that to ensure coverage of all A by neighborhoods, 12 | % (size(A,i)-Ni)/Si must be whole for i=1,2. The default function behavior 13 | % corresponds to [S1 S2] = [1 1]. Setting S1>=N1 and S2>=N2 results in no 14 | % overlap between the neighborhoods. 15 | % 16 | % B = IM2COLSTEP(A,[N1 N2 N3],[S1 S2 S3]) operates on a 3-D matrix A. The 17 | % step size [S1 S2 S3] may be ommitted, and defaults to [1 1 1]. 18 | % 19 | % Note: the call IM2COLSTEP(A,[N1 N2]) produces the same output as 20 | % Matlab's IM2COL(A,[N1 N2],'sliding'). However, it is significantly 21 | % faster. 22 | % 23 | % See also COL2IMSTEP, IM2COL, COUNTCOVER. 24 | 25 | 26 | % Ron Rubinstein 27 | % Computer Science Department 28 | % Technion, Haifa 32000 Israel 29 | % ronrubin@cs 30 | % 31 | % August 2009 32 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/imnormalize.m: -------------------------------------------------------------------------------- 1 | function y = imnormalize(x) 2 | %IMNORMALIZE Normalize image values. 3 | % Y = IMNORMALIZE(X) linearly transforms the intensity values of the image 4 | % X to tightly cover the range [0,1]. If X has more than one channel, the 5 | % channels are handled as one and normalized using the same transform. 6 | 7 | 8 | % Ron Rubinstein 9 | % Computer Science Department 10 | % Technion, Haifa 32000 Israel 11 | % ronrubin@cs 12 | % 13 | % May 2004 14 | 15 | 16 | maxval = max(x(:)); 17 | minval = min(x(:)); 18 | 19 | y = (x-minval) / (maxval-minval); 20 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/iswhole.m: -------------------------------------------------------------------------------- 1 | function z = iswhole(x,epsilon) 2 | %ISWHOLE Determine whole numbers with finite precision. 3 | % Z = ISWHOLE(X,EPSILON) returns a matrix the same size as X, containing 4 | % 1's where X is whole up to precision EPSILON, and 0's elsewhere. 5 | % 6 | % Z = ISWHOLE(X) uses the default value of EPSILON=1e-6. 7 | 8 | 9 | % Ron Rubinstein 10 | % Computer Science Department 11 | % Technion, Haifa 32000 Israel 12 | % ronrubin@cs 13 | % 14 | % May 2005 15 | 16 | if (nargin<2), epsilon = 1e-6; end 17 | z = abs(round(x)-x) < epsilon; 18 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/make.m: -------------------------------------------------------------------------------- 1 | function make 2 | %MAKE Build the KSVDBox MEX support files. 3 | % MAKE compiles the KSVDBox supporting MEX functions, using Matlab's 4 | % default MEX compiler. If the MEX compiler has not been set-up before, 5 | % please run 6 | % 7 | % mex -setup 8 | % 9 | % before using this MAKE file. 10 | 11 | % Ron Rubinstein 12 | % Computer Science Department 13 | % Technion, Haifa 32000 Israel 14 | % ronrubin@cs 15 | % 16 | % August 2009 17 | 18 | 19 | % detect platform 20 | 21 | compstr = computer; 22 | is64bit = strcmp(compstr(end-1:end),'64'); 23 | 24 | 25 | % compilation parameters 26 | 27 | compile_params = cell(0); 28 | if (is64bit) 29 | compile_params{1} = '-largeArrayDims'; 30 | end 31 | 32 | 33 | % Compile files % 34 | 35 | sourcefiles = {{'addtocols.c'}, {'collincomb.c'}, {'rowlincomb.c'}, {'sprow.c','mexutils.c'}, {'im2colstep.c'}, {'col2imstep.c'}}; 36 | 37 | for i = 1:length(sourcefiles) 38 | printf('Compiling %s...', sourcefiles{i}{1}); 39 | mex(sourcefiles{i}{:},compile_params{:}); 40 | end 41 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/normcols.m: -------------------------------------------------------------------------------- 1 | function y = normcols(x) 2 | %NORMCOLS Normalize matrix columns. 3 | % Y = NORMCOLS(X) normalizes the columns of X to unit length, returning 4 | % the result as Y. 5 | % 6 | % See also ADDTOCOLS. 7 | 8 | 9 | % Ron Rubinstein 10 | % Computer Science Department 11 | % Technion, Haifa 32000 Israel 12 | % ronrubin@cs 13 | % 14 | % April 2009 15 | 16 | 17 | y = x*spdiag(1./sqrt(sum(x.*x))); 18 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/printf.m: -------------------------------------------------------------------------------- 1 | function str = printf(varargin) 2 | %PRINTF Print formatted text to screen. 3 | % PRINTF(FMT,VAL1,VAL2,...) formats the data in VAL1,VAL2,... according to 4 | % the format string FMT, and prints the result to the screen. 5 | % 6 | % The call to PRINTF(FMT,VAL1,VAL2,...) simply invokes the call 7 | % DISP(SPRINTF(FMT,VAL1,VAL2,...)). For a complete description of the 8 | % format string options see function SPRINTF. 9 | % 10 | % STR = PRINTF(...) also returns the formatted string. 11 | 12 | 13 | % Ron Rubinstein 14 | % Computer Science Department 15 | % Technion, Haifa 32000 Israel 16 | % ronrubin@cs 17 | % 18 | % April 2008 19 | 20 | 21 | if (nargout>0) 22 | str = sprintf(varargin{:}); 23 | disp(str); 24 | else 25 | disp(sprintf(varargin{:})); 26 | end 27 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/remove_dc.m: -------------------------------------------------------------------------------- 1 | function [y,dc] = remove_dc(x,columns) 2 | %REMOVE_DC Remove DC channel from signals. 3 | % [Y,DC] = REMOVE_DC(X) removes the DC channel (i.e. the mean) from the 4 | % specified (possibly multi-dimensional) signal X. Y is the DC-free 5 | % signal and is the same size as X. DC is a scalar containing the mean of 6 | % the signal X. 7 | % 8 | % [Y,DC] = REMOVE_DC(X,'columns') where X is a 2D matrix, treats the 9 | % columns of X as a set of 1D signals, removing the DC channel from each 10 | % one individually. Y is the same size as X and contains the DC-free 11 | % signals. DC is a row vector of length size(X,2) containing the means of 12 | % the signals in X. 13 | % 14 | % See also ADD_DC. 15 | 16 | 17 | if (nargin==2 && strcmpi(columns,'columns')), columns = 1; 18 | else columns = 0; 19 | end 20 | 21 | if (columns) 22 | dc = mean(x); 23 | y = addtocols(x,-dc); 24 | else 25 | if (ndims(x)==2) % temporary, will remove in future 26 | warning('Treating 2D matrix X as a single signal and not each column individually'); 27 | end 28 | dc = mean(x(:)); 29 | y = x-dc; 30 | end 31 | 32 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/rowlincomb.m: -------------------------------------------------------------------------------- 1 | %ROWLINCOMB Linear combination of matrix rows. 2 | % Y = ROWLINCOMB(X,A,ROWS) computes a linear combination of the rows of 3 | % the matrix A. The row indices are specified in the vector ROWS, and the 4 | % correspoinding coefficients are specified in the vector X. The vectors 5 | % ROWS and X must be of the same length. The call Y = ROWLINCOMB(X,A,ROWS) 6 | % is essentially equivalent to the command 7 | % 8 | % Y = X'*A(ROWS,:) . 9 | % 10 | % However, it is implemented much more efficiently. 11 | % 12 | % Y = ROWLINCOMB(X,A,ROWS,COLS) only works on the columns of A specified 13 | % in COLS, returning a vector of length equal to COLS. This call is 14 | % essentially equivalent to the command 15 | % 16 | % Y = X'*A(ROWS,COLS) . 17 | % 18 | % See also COLLINCOMB. 19 | 20 | 21 | % Ron Rubinstein 22 | % Computer Science Department 23 | % Technion, Haifa 32000 Israel 24 | % ronrubin@cs 25 | % 26 | % April 2009 27 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/secs2hms.m: -------------------------------------------------------------------------------- 1 | function [h,m,s] = secs2hms(t) 2 | %SECS2HMS Convert seconds to hours, minutes and seconds. 3 | % [H,M,S] = SECS2HMS(T) converts the specified number of seconds T to 4 | % hours, minutes and seconds. H and M are whole numbers, and S is real. 5 | % 6 | % Example: Estimate the remaining time of a loop 7 | % 8 | % n = 10; tic; 9 | % for i = 1:n 10 | % pause(1); 11 | % [h,m,s] = secs2hms( (n-i)*toc/i ); 12 | % printf('estimated remaining time: %02d:%02d:%05.2f',h,m,s); 13 | % end 14 | 15 | 16 | % Ron Rubinstein 17 | % Computer Science Department 18 | % Technion, Haifa 32000 Israel 19 | % ronrubin@cs 20 | % 21 | % April 2008 22 | 23 | 24 | s = t; 25 | h = fix(s/3600); 26 | s = rem(s,3600); 27 | m = fix(s/60); 28 | s = rem(s,60); 29 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/spdiag.m: -------------------------------------------------------------------------------- 1 | function Y = spdiag(V,K) 2 | %SPDIAG Sparse diagonal matrices. 3 | % SPDIAG(V,K) when V is a vector with N components is a sparse square 4 | % matrix of order N+ABS(K) with the elements of V on the K-th diagonal. 5 | % K = 0 is the main diagonal, K > 0 is above the main diagonal and K < 0 6 | % is below the main diagonal. 7 | % 8 | % SPDIAG(V) is the same as SPDIAG(V,0) and puts V on the main diagonal. 9 | % 10 | % See also DIAG, SPDIAGS. 11 | 12 | 13 | % Ron Rubinstein 14 | % Computer Science Department 15 | % Technion, Haifa 32000 Israel 16 | % ronrubin@cs 17 | % 18 | % June 2008 19 | 20 | 21 | if (nargin<2) 22 | K = 0; 23 | end 24 | 25 | n = length(V) + abs(K); 26 | 27 | if (K>0) 28 | i = 1:length(V); 29 | j = K+1:n; 30 | elseif (K<0) 31 | i = -K+1:n; 32 | j = 1:length(V); 33 | else 34 | i = 1:n; 35 | j = 1:n; 36 | end 37 | 38 | Y = sparse(i,j,V(:),n,n); -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/sprow.m: -------------------------------------------------------------------------------- 1 | %SPROW Extract row of sparse matrix. 2 | % X = SPROW(A,J) where A is a sparse matrix, returns the nonzero values in 3 | % the row A(J,:). 4 | % 5 | % [X,ID] = SPROW(A,J) also returns the column indices of the nonzeros. 6 | % 7 | % Note that the call [X,ID] = SPROW(A,J) is equivalent (but more efficient 8 | % than) the Matlab code 9 | % 10 | % IDS = find(A(J,:)); 11 | % X = A(J,IDS); 12 | 13 | 14 | % Ron Rubinstein 15 | % Computer Science Department 16 | % Technion, Haifa 32000 Israel 17 | % ronrubin@cs 18 | % 19 | % August 2009 20 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/private/timerclear.m: -------------------------------------------------------------------------------- 1 | function timerclear() 2 | %TIMERCLEAR Clear all timers. 3 | % TIMERCLEAR clears all currenly registered timers, invalidating all 4 | % timer ids. 5 | % 6 | % Note: since registered timers do not consume CPU power except for when 7 | % the TIMER<*> functions are called, this function is only useful in 8 | % situations where a large number of timers have been initialized, and 9 | % there is a need to reclaim memory. 10 | % 11 | % See also TIMERINIT, TIMERETA. 12 | 13 | 14 | % Ron Rubinstein 15 | % Computer Science Department 16 | % Technion, Haifa 32000 Israel 17 | % ronrubin@cs 18 | % 19 | % June 2008 20 | 21 | 22 | global utiltbx_timer_start_times % start times 23 | global utiltbx_time_lastdisp % last display times 24 | global utiltbx_timer_iternums % iteration numbers 25 | global utiltbx_timer_lastiter % last queried iteration numbers 26 | global utiltbx_timer_name % timer names 27 | global utiltbx_timer_callfun % timer calling functions 28 | 29 | 30 | % clear all timers % 31 | 32 | utiltbx_timer_start_times = []; 33 | utiltbx_time_lastdisp = []; 34 | utiltbx_timer_iternums = []; 35 | utiltbx_timer_lastiter = []; 36 | utiltbx_timer_name = []; 37 | utiltbx_timer_callfun = []; 38 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdbox13/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | KSVDBox v13 README 3 | October 18, 2009 4 | 5 | 6 | 7 | KSVDBox installation: 8 | --------------------- 9 | 10 | 1. Make sure OMPBox v10 is installed prior to installing this package. 11 | 2. Unpack the contents of the compressed file to a new directory, named e.g. "ksvdbox". 12 | 3. If you have not done so before, configure Matlab's MEX compiler by entering 13 | >> mex -setup 14 | prior to using MAKE. For optimal performance, it is recommended that you select a compiler 15 | that performs optimizations. For instance, in Windows, MS Visual Studio is preferred to Lcc. 16 | 4. Within Matlab, navigate to the KSVDBox directory, and then to the "private" directory within it, 17 | and enter MAKE to run the compilation script. 18 | 5. Add the KSVDBox package directory to the Matlab path (you can use the ADDPATH command for this). 19 | Do not add the private directory to the path. 20 | 21 | 22 | KSVDBox quick start: 23 | -------------------- 24 | 25 | 1. Enter "ksvddemo" and "ksvddenoisedemo" at the Matlab command prompt to run some 26 | demonstrations of the package. 27 | 2. For a complete list of functions in the package, enter 28 | >> help ksvdbox 29 | This assumes the package was installed to a directory named "ksvdbox". If not, replace ksvdbox 30 | in the above with the (unqualified) name of the KSVDBox installation directory. 31 | 32 | Also see faq.txt for some frequently asked questions about the package. 33 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/Contents.m: -------------------------------------------------------------------------------- 1 | %KSVDSBox - Implementation of the Sparse K-SVD algorithm. 2 | % 3 | %Ron Rubinstein, Computer Science Department 4 | %Technion -- Israel Institute of Technology 5 | %ronrubin@cs.technion.ac.il 6 | % 7 | % 8 | %Sparse K-SVD dictionary training. 9 | % ksvds - Sparse K-SVD dictionary training. 10 | % 11 | %Signal denoising. 12 | % ompsdenoise - Sparse OMP denoising. 13 | % ompsdenoise2 - Sparse OMP denoising of 2-D signals. 14 | % ompsdenoise3 - Sparse OMP denoising of 3-D signals. 15 | % ksvdsdenoise - Sparse K-SVD denoising. 16 | % 17 | %Miscellaneous. 18 | % ksvdsdenoisedemo - Sparse K-SVD denoising demonstration. 19 | % ksvdsver - Sparse K-SVD toolbox version information. 20 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/ksvdsver.m: -------------------------------------------------------------------------------- 1 | function v = ksvdsver(history) 2 | %KSVDSVER Sparse K-SVD toolbox version information. 3 | % KSVDSVER displays the current Sparse KSVD toolbox version information. 4 | % 5 | % KSVDSVER('history') also displays history information about the previous 6 | % versions of the Sparse KSVD toolbox and their change logs. 7 | % 8 | % V = KSVDSVER returns the version number of the current KSVD toolbox, and 9 | % does not display any information. 10 | 11 | % Ron Rubinstein 12 | % Computer Science Department 13 | % Technion, Haifa 32000 Israel 14 | % ronrubin@cs 15 | % 16 | % October 2009 17 | 18 | 19 | ver = 11; 20 | 21 | if (nargout>0) 22 | if (nargin>0) 23 | error('Invalid number of parameters.'); 24 | end 25 | v = ver; 26 | 27 | else 28 | 29 | if (nargin==0 || (nargin==1 && strcmpi(history,'history'))) 30 | 31 | disp(' '); 32 | disp('-----------------------------------------'); 33 | printf(' Sparse KSVD Toolbox version %d ',ver); 34 | disp('-----------------------------------------'); 35 | disp(' '); 36 | 37 | else 38 | error('Unknown parameters.'); 39 | end 40 | 41 | if (nargin>0) 42 | 43 | disp(' '); 44 | disp(' '); 45 | disp('Sparse K-SVD Toolbox version 11, 18.10.09'); 46 | disp('------------------------------------------'); 47 | disp(' '); 48 | disp('First public release.'); 49 | disp(' '); 50 | disp(' '); 51 | 52 | end 53 | end 54 | 55 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/add_dc.m: -------------------------------------------------------------------------------- 1 | function x = add_dc(y,dc,columns) 2 | %ADD_DC Add DC channel to signals. 3 | % X = ADD_DC(Y,DC) adds the specified DC value to the (possibly 4 | % multi-dimensional) signal Y, returning the result as X. DC should be a 5 | % scalar value. 6 | % 7 | % X = ADD_DC(Y,DC,'columns') where Y is a 2D matrix and DC is an array of 8 | % length size(Y,2), treats the columns of Y as individual 1D signals, 9 | % adding to each one the corresponding DC value from the DC array. X is 10 | % the same size as Y and contains the resulting signals. 11 | % 12 | % See also REMOVE_DC. 13 | 14 | % Ron Rubinstein 15 | % Computer Science Department 16 | % Technion, Haifa 32000 Israel 17 | % ronrubin@cs 18 | % 19 | % April 2009 20 | 21 | 22 | if (nargin==3 && strcmpi(columns,'columns')), columns = 1; 23 | else columns = 0; 24 | end 25 | 26 | if (columns) 27 | x = addtocols(y,dc); 28 | else 29 | x = y + dc; 30 | end 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/addtocols.m: -------------------------------------------------------------------------------- 1 | %ADDTOCOLS Add values to the columns of a matrix. 2 | % Y=ADDTOCOLS(X,V) adds to each column of the MxN matrix X the 3 | % corresponding value from the N-element vector V. 4 | % 5 | % See also NORMCOLS. 6 | 7 | 8 | % Ron Rubinstein 9 | % Computer Science Department 10 | % Technion, Haifa 32000 Israel 11 | % ronrubin@cs 12 | % 13 | % June 2005 14 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/col2imstep.m: -------------------------------------------------------------------------------- 1 | %COL2IMSTEP Rearrange matrix columns into blocks. 2 | % A = COL2IMSTEP(B,[MM NN],[N1 N2]) rearranges the columns of B into 3 | % sliding N1-by-N2 blocks producing the matrix A of size MM-by-NN. B is 4 | % usually the result of calling IM2COLSTEP(...) with a stepsize of 1, or 5 | % using Matlab's IM2COL(..,'sliding'). Overlapping blocks are summed in A. 6 | % 7 | % A = COL2IMSTEP(B,[MM NN],[N1 N2],[S1 S2]) arranges the blocks in A with 8 | % a step size of (S1,S2) between them. The first block is at A(1:N1,1:N2), 9 | % and the rest are at A((1:N1)+i*S1,(1:N2)+j*S2). Overlapping blocks are 10 | % summed in A. Note that B is usually the result of calling 11 | % IM2COLSTEP(...) with a stepsize of [S1 S2]. 12 | % 13 | % A = IM2COLSTEP(B,[MM NN KK],[N1 N2 N3],[S1 S2 S3]) generates a 3-D 14 | % output matrix A. The step size [S1 S2 S3] may be ommitted, and defaults 15 | % to [1 1 1]. 16 | % 17 | % See also IM2COLSTEP, IM2COL, COUNTCOVER. 18 | 19 | 20 | % Ron Rubinstein 21 | % Computer Science Department 22 | % Technion, Haifa 32000 Israel 23 | % ronrubin@cs 24 | % 25 | % August 2009 26 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/collincomb.m: -------------------------------------------------------------------------------- 1 | %COLLINCOMB Linear combination of matrix columns. 2 | % Y = COLLINCOMB(A,COLS,X) computes a linear combination of the columns of 3 | % the matrix A. The column indices are specified in the vector COLS, and 4 | % the correspoinding coefficients are specified in the vector X. The 5 | % vectors COLS and X must be of the same length. 6 | % 7 | % The call Y = COLLINCOMB(A,COLS,X) is essentially equivalent to 8 | % 9 | % Y = A(:,COLS)*X . 10 | % 11 | % However, it is implemented much more efficiently. 12 | % 13 | % Y = COLLINCOMB(A,ROWS,COLS,X) only works on the rows of A specified 14 | % in ROWS, returning a vector of length equal to ROWS. This call is 15 | % essentially equivalent to the command 16 | % 17 | % Y = A(ROWS,COLS)*X . 18 | % 19 | % See also ROWLINCOMB. 20 | 21 | 22 | % Ron Rubinstein 23 | % Computer Science Department 24 | % Technion, Haifa 32000 Israel 25 | % ronrubin@cs 26 | % 27 | % April 2009 28 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/countcover.m: -------------------------------------------------------------------------------- 1 | function cnt = countcover(sz,blocksize,stepsize) 2 | %COUNTCOVER Covering of signal samples by blocks 3 | % CNT = COUNTCOVER(SZ,BLOCKSIZE,STEPSIZE) assumes a p-dimensional signal 4 | % of size SZ=[N1 N2 ... Np] covered by (possibly overlapping) blocks of 5 | % size BLOCKSIZE=[M1 M2 ... Mp]. The blocks start at position (1,1,..,1) 6 | % and are shifted between them by steps of size STEPSIZE=[S1 S2 ... Sp]. 7 | % COUNTCOVER returns a matrix the same size as the signal, containing in 8 | % each entry the number of blocks covering that sample. 9 | % 10 | % See also IM2COLSTEP, COL2IMSTEP, IM2COL. 11 | 12 | 13 | % Ron Rubinstein 14 | % Computer Science Department 15 | % Technion, Haifa 32000 Israel 16 | % ronrubin@cs 17 | % 18 | % August 2008 19 | 20 | 21 | cnt = ones(sz); 22 | for k = 1:length(sz) 23 | 24 | % this code is modified from function NDGRID, so it computes one 25 | % output argument of NDGRID at a time (to conserve memory) 26 | ids = (1:sz(k))'; 27 | s = sz; s(k) = []; 28 | ids = reshape(ids(:,ones(1,prod(s))),[length(ids) s]); 29 | ids = permute(ids,[2:k 1 k+1:length(sz)]); 30 | 31 | cnt = cnt .* max( min(floor((ids-1)/stepsize(k)),floor((sz(k)-blocksize(k))/stepsize(k))) - ... 32 | max(ceil((ids-blocksize(k))/stepsize(k)),0) + 1 , 0 ); 33 | end 34 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/im2colstep.m: -------------------------------------------------------------------------------- 1 | %IM2COLSTEP Rearrange matrix blocks into columns. 2 | % B = IM2COLSTEP(A,[N1 N2]) converts each sliding N1-by-N2 block of the 3 | % 2-D matrix A into a column of B, with no zero padding. B has N1*N2 rows 4 | % and will contain as many columns as there are N1-by-N2 neighborhoods in 5 | % A. Each column of B contains a neighborhood of A reshaped as NHOOD(:), 6 | % where NHOOD is a matrix containing an N1-by-N2 neighborhood of A. 7 | % 8 | % B = IM2COLSTEP(A,[N1 N2],[S1 S2]) extracts neighborhoods of A with a 9 | % step size of (S1,S2) between them. The first extracted neighborhood is 10 | % A(1:N1,1:N2), and the rest are of the form A((1:N1)+i*S1,(1:N2)+j*S2). 11 | % Note that to ensure coverage of all A by neighborhoods, 12 | % (size(A,i)-Ni)/Si must be whole for i=1,2. The default function behavior 13 | % corresponds to [S1 S2] = [1 1]. Setting S1>=N1 and S2>=N2 results in no 14 | % overlap between the neighborhoods. 15 | % 16 | % B = IM2COLSTEP(A,[N1 N2 N3],[S1 S2 S3]) operates on a 3-D matrix A. The 17 | % step size [S1 S2 S3] may be ommitted, and defaults to [1 1 1]. 18 | % 19 | % Note: the call IM2COLSTEP(A,[N1 N2]) produces the same output as 20 | % Matlab's IM2COL(A,[N1 N2],'sliding'). However, it is significantly 21 | % faster. 22 | % 23 | % See also COL2IMSTEP, IM2COL, COUNTCOVER. 24 | 25 | 26 | % Ron Rubinstein 27 | % Computer Science Department 28 | % Technion, Haifa 32000 Israel 29 | % ronrubin@cs 30 | % 31 | % August 2009 32 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/imnormalize.m: -------------------------------------------------------------------------------- 1 | function y = imnormalize(x) 2 | %IMNORMALIZE Normalize image values. 3 | % Y = IMNORMALIZE(X) linearly transforms the intensity values of the image 4 | % X to tightly cover the range [0,1]. If X has more than one channel, the 5 | % channels are handled as one and normalized using the same transform. 6 | 7 | 8 | % Ron Rubinstein 9 | % Computer Science Department 10 | % Technion, Haifa 32000 Israel 11 | % ronrubin@cs 12 | % 13 | % May 2004 14 | 15 | 16 | maxval = max(x(:)); 17 | minval = min(x(:)); 18 | 19 | y = (x-minval) / (maxval-minval); 20 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/iswhole.m: -------------------------------------------------------------------------------- 1 | function z = iswhole(x,epsilon) 2 | %ISWHOLE Determine whole numbers with finite precision. 3 | % Z = ISWHOLE(X,EPSILON) returns a matrix the same size as X, containing 4 | % 1's where X is whole up to precision EPSILON, and 0's elsewhere. 5 | % 6 | % Z = ISWHOLE(X) uses the default value of EPSILON=1e-6. 7 | 8 | 9 | % Ron Rubinstein 10 | % Computer Science Department 11 | % Technion, Haifa 32000 Israel 12 | % ronrubin@cs 13 | % 14 | % May 2005 15 | 16 | if (nargin<2), epsilon = 1e-6; end 17 | z = abs(round(x)-x) < epsilon; 18 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/make.m: -------------------------------------------------------------------------------- 1 | function make 2 | %MAKE Build the KSVDSBox MEX support files. 3 | % MAKE compiles the KSVDSBox supporting MEX functions, using Matlab's 4 | % default MEX compiler. If the MEX compiler has not been set-up before, 5 | % please run 6 | % 7 | % mex -setup 8 | % 9 | % before using this MAKE file. 10 | 11 | % Ron Rubinstein 12 | % Computer Science Department 13 | % Technion, Haifa 32000 Israel 14 | % ronrubin@cs 15 | % 16 | % August 2009 17 | 18 | 19 | % detect platform 20 | 21 | compstr = computer; 22 | is64bit = strcmp(compstr(end-1:end),'64'); 23 | 24 | 25 | % compilation parameters 26 | 27 | compile_params = cell(0); 28 | if (is64bit) 29 | compile_params{1} = '-largeArrayDims'; 30 | end 31 | 32 | 33 | % Compile files % 34 | 35 | sourcefiles = {{'addtocols.c'}, {'collincomb.c'}, {'rowlincomb.c'}, {'sprow.c','mexutils.c'}, {'im2colstep.c'}, {'col2imstep.c'}}; 36 | 37 | for i = 1:length(sourcefiles) 38 | printf('Compiling %s...', sourcefiles{i}{1}); 39 | mex(sourcefiles{i}{:},compile_params{:}); 40 | end 41 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/odctdict.m: -------------------------------------------------------------------------------- 1 | function D = odctdict(n,L) 2 | %ODCTDICT Overcomplete DCT dictionary. 3 | % D = ODCTDICT(N,L) returns the overcomplete DCT dictionary of size NxL 4 | % for signals of length N. 5 | % 6 | % See also ODCT2DICT, ODCT3DICT, ODCTNDICT. 7 | 8 | % Ron Rubinstein 9 | % Computer Science Department 10 | % Technion, Haifa 32000 Israel 11 | % ronrubin@cs 12 | % 13 | % April 2009 14 | 15 | 16 | %% original implementation by ronrubin 17 | % D = zeros(n,L); 18 | % D(:,1) = 1/sqrt(n); 19 | % for k = 2:L 20 | % v = cos((0:n-1)*pi*(k-1)/L)'; 21 | % v = v-mean(v); 22 | % D(:,k) = v/norm(v); 23 | % end 24 | 25 | %% accelerated by Zhihong Zhang 26 | D = zeros(n,L); 27 | D(:,1) = 1/sqrt(n); 28 | 29 | [X,Y] = ndgrid(0:n-1,2:L); 30 | V = cos(X.*pi.*(Y-1)./L); 31 | V = V-mean(V); 32 | V = V./repmat(vecnorm(V),n,1); 33 | 34 | D(:,2:end) = V; 35 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/printf.m: -------------------------------------------------------------------------------- 1 | function str = printf(varargin) 2 | %PRINTF Print formatted text to screen. 3 | % PRINTF(FMT,VAL1,VAL2,...) formats the data in VAL1,VAL2,... according to 4 | % the format string FMT, and prints the result to the screen. 5 | % 6 | % The call to PRINTF(FMT,VAL1,VAL2,...) simply invokes the call 7 | % DISP(SPRINTF(FMT,VAL1,VAL2,...)). For a complete description of the 8 | % format string options see function SPRINTF. 9 | % 10 | % STR = PRINTF(...) also returns the formatted string. 11 | 12 | 13 | % Ron Rubinstein 14 | % Computer Science Department 15 | % Technion, Haifa 32000 Israel 16 | % ronrubin@cs 17 | % 18 | % April 2008 19 | 20 | 21 | if (nargout>0) 22 | str = sprintf(varargin{:}); 23 | disp(str); 24 | else 25 | disp(sprintf(varargin{:})); 26 | end 27 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/remove_dc.m: -------------------------------------------------------------------------------- 1 | function [y,dc] = remove_dc(x,columns) 2 | %REMOVE_DC Remove DC channel from signals. 3 | % [Y,DC] = REMOVE_DC(X) removes the DC channel (i.e. the mean) from the 4 | % specified (possibly multi-dimensional) signal X. Y is the DC-free 5 | % signal and is the same size as X. DC is a scalar containing the mean of 6 | % the signal X. 7 | % 8 | % [Y,DC] = REMOVE_DC(X,'columns') where X is a 2D matrix, treats the 9 | % columns of X as a set of 1D signals, removing the DC channel from each 10 | % one individually. Y is the same size as X and contains the DC-free 11 | % signals. DC is a row vector of length size(X,2) containing the means of 12 | % the signals in X. 13 | % 14 | % See also ADD_DC. 15 | 16 | 17 | if (nargin==2 && strcmpi(columns,'columns')), columns = 1; 18 | else columns = 0; 19 | end 20 | 21 | if (columns) 22 | dc = mean(x); 23 | y = addtocols(x,-dc); 24 | else 25 | if (ndims(x)==2) % temporary, will remove in future 26 | warning('Treating 2D matrix X as a single signal and not each column individually'); 27 | end 28 | dc = mean(x(:)); 29 | y = x-dc; 30 | end 31 | 32 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/rowlincomb.m: -------------------------------------------------------------------------------- 1 | %ROWLINCOMB Linear combination of matrix rows. 2 | % Y = ROWLINCOMB(X,A,ROWS) computes a linear combination of the rows of 3 | % the matrix A. The row indices are specified in the vector ROWS, and the 4 | % correspoinding coefficients are specified in the vector X. The vectors 5 | % ROWS and X must be of the same length. The call Y = ROWLINCOMB(X,A,ROWS) 6 | % is essentially equivalent to the command 7 | % 8 | % Y = X'*A(ROWS,:) . 9 | % 10 | % However, it is implemented much more efficiently. 11 | % 12 | % Y = ROWLINCOMB(X,A,ROWS,COLS) only works on the columns of A specified 13 | % in COLS, returning a vector of length equal to COLS. This call is 14 | % essentially equivalent to the command 15 | % 16 | % Y = X'*A(ROWS,COLS) . 17 | % 18 | % See also COLLINCOMB. 19 | 20 | 21 | % Ron Rubinstein 22 | % Computer Science Department 23 | % Technion, Haifa 32000 Israel 24 | % ronrubin@cs 25 | % 26 | % April 2009 27 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/secs2hms.m: -------------------------------------------------------------------------------- 1 | function [h,m,s] = secs2hms(t) 2 | %SECS2HMS Convert seconds to hours, minutes and seconds. 3 | % [H,M,S] = SECS2HMS(T) converts the specified number of seconds T to 4 | % hours, minutes and seconds. H and M are whole numbers, and S is real. 5 | % 6 | % Example: Estimate the remaining time of a loop 7 | % 8 | % n = 10; tic; 9 | % for i = 1:n 10 | % pause(1); 11 | % [h,m,s] = secs2hms( (n-i)*toc/i ); 12 | % printf('estimated remaining time: %02d:%02d:%05.2f',h,m,s); 13 | % end 14 | 15 | 16 | % Ron Rubinstein 17 | % Computer Science Department 18 | % Technion, Haifa 32000 Israel 19 | % ronrubin@cs 20 | % 21 | % April 2008 22 | 23 | 24 | s = t; 25 | h = fix(s/3600); 26 | s = rem(s,3600); 27 | m = fix(s/60); 28 | s = rem(s,60); 29 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/sprow.m: -------------------------------------------------------------------------------- 1 | %SPROW Extract row of sparse matrix. 2 | % X = SPROW(A,J) where A is a sparse matrix, returns the nonzero values in 3 | % the row A(J,:). 4 | % 5 | % [X,ID] = SPROW(A,J) also returns the column indices of the nonzeros. 6 | % 7 | % Note that the call [X,ID] = SPROW(A,J) is equivalent (but more efficient 8 | % than) the Matlab code 9 | % 10 | % IDS = find(A(J,:)); 11 | % X = A(J,IDS); 12 | 13 | 14 | % Ron Rubinstein 15 | % Computer Science Department 16 | % Technion, Haifa 32000 Israel 17 | % ronrubin@cs 18 | % 19 | % August 2009 20 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/private/timerclear.m: -------------------------------------------------------------------------------- 1 | function timerclear() 2 | %TIMERCLEAR Clear all timers. 3 | % TIMERCLEAR clears all currenly registered timers, invalidating all 4 | % timer ids. 5 | % 6 | % Note: since registered timers do not consume CPU power except for when 7 | % the TIMER<*> functions are called, this function is only useful in 8 | % situations where a large number of timers have been initialized, and 9 | % there is a need to reclaim memory. 10 | % 11 | % See also TIMERINIT, TIMERETA. 12 | 13 | 14 | % Ron Rubinstein 15 | % Computer Science Department 16 | % Technion, Haifa 32000 Israel 17 | % ronrubin@cs 18 | % 19 | % June 2008 20 | 21 | 22 | global utiltbx_timer_start_times % start times 23 | global utiltbx_time_lastdisp % last display times 24 | global utiltbx_timer_iternums % iteration numbers 25 | global utiltbx_timer_lastiter % last queried iteration numbers 26 | global utiltbx_timer_name % timer names 27 | global utiltbx_timer_callfun % timer calling functions 28 | 29 | 30 | % clear all timers % 31 | 32 | utiltbx_timer_start_times = []; 33 | utiltbx_time_lastdisp = []; 34 | utiltbx_timer_iternums = []; 35 | utiltbx_timer_lastiter = []; 36 | utiltbx_timer_name = []; 37 | utiltbx_timer_callfun = []; 38 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | KSVDSBox v11 README 3 | October 18, 2009 4 | 5 | 6 | 7 | KSVDSBox installation: 8 | ---------------------- 9 | 10 | 1. Make sure OMPSBox v1 is installed prior to installing this package. 11 | 2. Unpack the contents of the compressed file to a new directory, named e.g. "ksvdsbox". 12 | 3. If you have not done so before, configure Matlab's MEX compiler by entering 13 | >> mex -setup 14 | prior to using MAKE. For optimal performance, it is recommended that you select a compiler 15 | that performs optimizations. For instance, in Windows, MS Visual Studio is preferred to Lcc. 16 | 4. Within Matlab, navigate to the KSVDSBox directory, and then to the "private" directory within it, 17 | and enter MAKE to run the compilation script. 18 | 5. Add the KSVDSBox package directory to the Matlab path (you can use the ADDPATH command for this). 19 | Do not add the private directory to the path. 20 | 21 | 22 | KSVDSBox quick start: 23 | --------------------- 24 | 25 | 1. Enter "ksvdsdenoisedemo" at the Matlab command prompt to run a demonstration of Sparse K-SVD 26 | denoising. 27 | 2. For a complete list of functions in the package, enter 28 | >> help ksvdsbox 29 | This assumes the package was installed to a directory named "ksvdsbox". If not, replace ksvdsbox 30 | in the above with the (unqualified) name of the KSVDSBox installation directory. 31 | 32 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/volumes/vf-ankle.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/ksvdsbox11/volumes/vf-ankle.mat -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ksvdsbox11/volumes/vm-head.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/ksvdsbox11/volumes/vm-head.mat -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompbox10/Contents.m: -------------------------------------------------------------------------------- 1 | %OMPBox - Implementation of Batch-OMP and OMP-Cholesky. 2 | % 3 | %Ron Rubinstein, Computer Science Department 4 | %Technion -- Israel Institute of Technology 5 | %ronrubin@cs.technion.ac.il 6 | % 7 | % 8 | %Orthogonal Matching Pursuit. 9 | % omp - Sparsity-constrained Orthogonal Matching Pursuit. 10 | % omp2 - Error-constrained Orthogonal Matching Pursuit. 11 | % 12 | %Demonstrations. 13 | % ompdemo - Demonstration of the OMP toolbox. 14 | % ompspeedtest - Test the speed of the OMP functions. 15 | % 16 | %Miscellaneous. 17 | % ompver - OMPBox version information. 18 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompbox10/faq.txt: -------------------------------------------------------------------------------- 1 | 2 | OMPBox Frequently Asked Questions 3 | --------------------------------- 4 | 5 | 6 | Q. Your package does not work! I get an error like this: 7 | 8 | ??? Attempt to execute SCRIPT ompbox\private\ompmex as a function: 9 | C:\............................................\ompbox\private\ompmex.m 10 | 11 | Error in ==> omp at 162 12 | gamma = ompmex(D,X,DtX,G,T,sparse_gamma,msgdelta,profile); 13 | 14 | A. OMPBox comes as source code, and requires compilation. Please read the README file 15 | and follow the directions - it is actually quite easy. 16 | 17 | 18 | 19 | Q. I suspect OMP is running terribly slow. Can I verify this? What can be done? 20 | 21 | A. You can run OMPSPEEDTEST to verify your suspicion. You will note that the 22 | function uses a slightly different number of signals every run - this is because 23 | before it begins the actual test, it performs a small speed evaluation and 24 | selects the number of signals to code based on the speed of the system. If the 25 | number of selected signals is less than, say, 1000 or so, then yes, OMP is indeed 26 | running very slow. The most probabe cause of this, assuming you are using a decent 27 | Pentium IV processor or faster, is compiling OMP with a compiler that does not perform 28 | optimization (e.g. LCC). Make sure you are compiling using MS-Visual Studio on Windows, 29 | GCC on Linux, or any other descent compiler, and that you did not disable optimization 30 | (if you do not know how to do this, you probably did not). Run "mex -setup" from 31 | the Matlab prompt to verify your compiler selection, and recompile if needed. 32 | 33 | 34 | 35 | Q. Your package does not compile/run/work on my system. 36 | 37 | A. Well, unfortunately I only have access to a limited number of system configurations. 38 | So, if you are experiencing an error on your system, please let me know! These things 39 | can usually be corrected easily - for everyone's benefit. 40 | 41 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompbox10/ompspeedtest.m: -------------------------------------------------------------------------------- 1 | function ompspeedtest 2 | %OMPSPEEDTEST Test the speed of the OMP functions. 3 | % OMPSPEEDTEST invokes the three operation modes of OMP and compares 4 | % their speeds. The function automatically selects the number of signals 5 | % for the test based on the speed of the system. 6 | % 7 | % To run the test, type OMPSPEEDTEST from the Matlab prompt. 8 | % 9 | % See also OMPDEMO. 10 | 11 | 12 | % Ron Rubinstein 13 | % Computer Science Department 14 | % Technion, Haifa 32000 Israel 15 | % ronrubin@cs 16 | % 17 | % August 2009 18 | 19 | 20 | 21 | % random dictionary % 22 | 23 | n = 512; 24 | L = 1000; 25 | T = 8; 26 | 27 | D = randn(n,L); 28 | D = D*diag(1./sqrt(sum(D.*D))); % normalize the dictionary 29 | 30 | 31 | % select signal number according to computer speed % 32 | 33 | x = randn(n,20); 34 | tic; omp(D,x,[],T,'messages',-1); t=toc; 35 | signum = ceil(20/(t/20)); % approximately 20 seconds of OMP-Cholesky 36 | 37 | 38 | % generate random signals % 39 | 40 | X = randn(n,signum); 41 | 42 | 43 | % run OMP % 44 | 45 | printf('\nRunning OMP-Cholesky...'); 46 | tic; omp(D,X,[],T,'messages',4); t1=toc; 47 | 48 | printf('\nRunning Batch-OMP...'); 49 | tic; omp(D,X,D'*D,T,'messages',1); t2=toc; 50 | 51 | printf('\nRunning Batch-OMP with D''*X specified...'); 52 | tic; omp(D'*X,D'*D,T,'messages',1); t3=toc; 53 | 54 | 55 | % display summary % 56 | 57 | printf('\n\nSpeed summary for %d signals, dictionary size %d x %d:\n', signum, n, L); 58 | printf('Call syntax Algorithm Total time'); 59 | printf('--------------------------------------------------------'); 60 | printf('OMP(D,X,[],T) OMP-Cholesky %5.2f seconds', t1); 61 | printf('OMP(D,X,G,T) Batch-OMP %5.2f seconds', t2); 62 | printf('OMP(DtX,G,T) Batch-OMP with D''*X %5.2f seconds\n', t3); 63 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompbox10/private/make.m: -------------------------------------------------------------------------------- 1 | function make 2 | %MAKE Build the OMPBox package. 3 | % MAKE compiles all OMPBox MEX functions, using Matlab's default MEX 4 | % compiler. If the MEX compiler has not been set-up before, please run 5 | % 6 | % mex -setup 7 | % 8 | % before using this MAKE file. 9 | 10 | % Ron Rubinstein 11 | % Computer Science Department 12 | % Technion, Haifa 32000 Israel 13 | % ronrubin@cs 14 | % 15 | % August 2009 16 | 17 | 18 | % detect platform 19 | 20 | compstr = computer; 21 | is64bit = strcmp(compstr(end-1:end),'64'); 22 | 23 | 24 | % compilation parameters 25 | 26 | compile_params = cell(0); 27 | if (is64bit) 28 | compile_params{1} = '-largeArrayDims'; 29 | end 30 | 31 | 32 | % Compile files % 33 | 34 | ompsources = {'mexutils.c','ompcore.c','omputils.c','myblas.c','ompprof.c'}; 35 | 36 | disp('Compiling ompmex...'); 37 | mex('ompmex.c', ompsources{:},compile_params{:}); 38 | 39 | disp('Compiling omp2mex...'); 40 | mex('omp2mex.c',ompsources{:},compile_params{:}); 41 | 42 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompbox10/private/omp2mex.m: -------------------------------------------------------------------------------- 1 | %This is the Matlab interface to the OMP2 MEX implementation. 2 | %The function is not for independent use, only through omp2.m. 3 | 4 | 5 | %OMP2MEX Matlab interface to the OMP2 MEX implementation. 6 | % GAMMA = OMP2MEX(D,X,DtX,XtX,G,EPSILON,SPARSE_G,MSGDELTA,MAXATOMS,PROFILE) 7 | % invokes the OMP2 MEX function according to the specified parameters. Not 8 | % all the parameters are required. Those among D, X, DtX, XtX and G which 9 | % are not specified should be passed as []. 10 | % 11 | % EPSILON - the target error. 12 | % SPARSE_G - returns a sparse GAMMA when nonzero, full GAMMA when zero. 13 | % MSGDELTA - the delay in secs between messages. Zero means no messages. 14 | % MAXATOMS - the max number of atoms per signal, negative for no max. 15 | % PROFILE - nonzero means that profiling information should be printed. 16 | 17 | 18 | % Ron Rubinstein 19 | % Computer Science Department 20 | % Technion, Haifa 32000 Israel 21 | % ronrubin@cs 22 | % 23 | % April 2009 24 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompbox10/private/ompmex.m: -------------------------------------------------------------------------------- 1 | %This is the Matlab interface to the OMP MEX implementation. 2 | %The function is not for independent use, only through omp.m. 3 | 4 | 5 | %OMPMEX Matlab interface to the OMP MEX implementation. 6 | % GAMMA = OMPMEX(D,X,DtX,G,L,SPARSE_G,MSGDELTA,PROFILE) invokes the OMP 7 | % MEX function according to the specified parameters. Not all the 8 | % parameters are required. Those among D, X, DtX and G which are not 9 | % specified should be passed as []. 10 | % 11 | % L - the target sparsity. 12 | % SPARSE_G - returns a sparse GAMMA when nonzero, full GAMMA when zero. 13 | % MSGDELTA - the delay in secs between messages. Zero means no messages. 14 | % PROFILE - nonzero means that profiling information should be printed. 15 | 16 | 17 | % Ron Rubinstein 18 | % Computer Science Department 19 | % Technion, Haifa 32000 Israel 20 | % ronrubin@cs 21 | % 22 | % April 2009 23 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompbox10/private/printf.m: -------------------------------------------------------------------------------- 1 | function str = printf(varargin) 2 | %PRINTF Print formatted text to screen. 3 | % PRINTF(FMT,VAL1,VAL2,...) formats the data in VAL1,VAL2,... according to 4 | % the format string FMT, and prints the result to the screen. 5 | % 6 | % The call to PRINTF(FMT,VAL1,VAL2,...) simply invokes the call 7 | % DISP(SPRINTF(FMT,VAL1,VAL2,...)). For a complete description of the 8 | % format string options see function SPRINTF. 9 | % 10 | % STR = PRINTF(...) also returns the formatted string. 11 | 12 | 13 | % Ron Rubinstein 14 | % Computer Science Department 15 | % Technion, Haifa 32000 Israel 16 | % ronrubin@cs 17 | % 18 | % April 2008 19 | 20 | 21 | if (nargout>0) 22 | str = sprintf(varargin{:}); 23 | disp(str); 24 | else 25 | disp(sprintf(varargin{:})); 26 | end 27 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompbox10/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | OMPBox v10 README 3 | October 18, 2009 4 | 5 | 6 | 7 | OMPBox installation: 8 | -------------------- 9 | 10 | 1. Unpack the contents of the compressed file to a new directory, named e.g. "ompbox". 11 | 2. If you have not done so before, configure Matlab's MEX compiler by entering 12 | >> mex -setup 13 | prior to using MAKE. For optimal performance, it is recommended that you select a compiler 14 | that performs optimizations. For instance, in Windows, MS Visual Studio is preferred to Lcc. 15 | 3. Within Matlab, navigate to the OMPBox directory, and then to the "private" directory within it, 16 | and enter MAKE to run the compilation script. 17 | 4. Add the OMPBox package directory to the Matlab path (you can use the ADDPATH command for this). 18 | Do not add the private directory to the path. 19 | 20 | 21 | OMPBox quick start: 22 | ------------------- 23 | 24 | 1. Enter "ompdemo" at the Matlab command prompt to run a short demo of the package. 25 | 2. Enter "ompspeedtest" to test the speed of the various OMP implementations. 26 | 3. For a complete list of functions in the package, enter 27 | >> help ompbox 28 | This assumes the package was installed to a directory named "ompbox". If not, replace ompbox 29 | in the above with the (unqualified) name of the OMPBox installation directory. 30 | 31 | Also see faq.txt for some frequently asked questions about the package. 32 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/Contents.m: -------------------------------------------------------------------------------- 1 | %OMPSBox - Implementation of Sparse Batch-OMP and OMP-Cholesky. 2 | % 3 | %Ron Rubinstein, Computer Science Department 4 | %Technion -- Israel Institute of Technology 5 | %ronrubin@cs.technion.ac.il 6 | % 7 | % 8 | %Sparse Orthogonal Matching Pursuit. 9 | % omps - Sparsity-constrained Sparse Orthogonal Matching Pursuit. 10 | % omps2 - Error-constrained Sparse Orthogonal Matching Pursuit. 11 | % 12 | %Sparse-separable dictionaries. 13 | % dictsep - Sparse-separable dictionary forward operator. 14 | % dicttsep - Sparse-separable dictionary transpose operator. 15 | % normdictsep - Sparse-separable dictionary normalization. 16 | % 17 | %Miscellaneous. 18 | % sparsedict - Overview of sparse dictionaries and sparse OMP. 19 | % ompspeedcompare - Speed comparison of standard vs. sparse OMP. 20 | % ompsver - OMPSBox version information. 21 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/dictsep.m: -------------------------------------------------------------------------------- 1 | function x = dictsep(Bsep,A,Gamma) 2 | %DICTSEP Sparse-separable dictionary forward operator. 3 | % X = DICTSEP(Bsep,A,GAMMA) computes the dictionary operator X=B*A*GAMMA 4 | % for the sparse dictionary D=B*A and the sparse matrix GAMMA. The cell 5 | % array Bsep and the sparse matrix A represent the sparse dictionary, see 6 | % 'help sparsedict' for more information. 7 | % 8 | % Note: In general, the explicit Matlab call 9 | % 10 | % X = kron(kron(Bsep{3},Bsep{2}),Bsep{1})*A*GAMMA 11 | % 12 | % will be faster than the call 13 | % 14 | % X = dictsep(Bsep,A,GAMMA) 15 | % 16 | % due to the sparsity of GAMMA and the highly optimized Matlab 17 | % implementation (note that this is not the case for DICTTSEP, which is 18 | % faster than its Matlab code equivalent). Thus, DICTSEP is mostly useful 19 | % for cases where memory constraints prohibit the computation of the full 20 | % base dictionary B. 21 | % 22 | % See also DICTTSEP, SPARSEDICT. 23 | 24 | 25 | % Ron Rubinstein 26 | % Computer Science Department 27 | % Technion, Haifa 32000 Israel 28 | % ronrubin@cs 29 | % 30 | % October 2009 31 | 32 | 33 | x = dictsepmex(Bsep,A,Gamma); 34 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/dicttsep.m: -------------------------------------------------------------------------------- 1 | function y = dicttsep(Bsep,A,x) 2 | %DICTTSEP Sparse-separable dictionary transpose operator. 3 | % Y = DICTTSEP(Bsep,A,X) computes the dictionary operator Y=(B*A)'*X for 4 | % the sparse dictionary D=B*A and the matrix X. The cell array Bsep and 5 | % the sparse matrix A represent the sparse dictionary, see 'help 6 | % sparsedict' for more information. 7 | % 8 | % Note: the call 9 | % 10 | % Y = dicttsep(Bsep,A,X) 11 | % 12 | % is equivalent to the explicit call 13 | % 14 | % Y = A'*B'*X 15 | % 16 | % where B=kron(kron(Bsep{3},Bsep{2}),Bsep{1}). However, the first syntax 17 | % is significantly faster. 18 | % 19 | % See also DICTSEP, SPARSEDICT. 20 | 21 | 22 | % Ron Rubinstein 23 | % Computer Science Department 24 | % Technion, Haifa 32000 Israel 25 | % ronrubin@cs 26 | % 27 | % October 2009 28 | 29 | 30 | y = dicttsepmex(Bsep,A,x); 31 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/faq.txt: -------------------------------------------------------------------------------- 1 | 2 | OMPSBox Frequently Asked Questions 3 | ----------------------------------- 4 | 5 | 6 | Q. Your package does not work! I get an error like this: 7 | 8 | ??? Attempt to execute SCRIPT ompsbox\private\dictsepmex as a function: 9 | C:\............................................\ompsbox\private\dictsepmex.m 10 | 11 | Error in ==> dictsep at 31 12 | x = dictsepmex(Bsep,A,Gamma); 13 | 14 | Error in ==> omps at 145 15 | atomnorms(i) = sum(dictsep(B,A,gamma(:,i)).^2); 16 | 17 | A. OMPSBox comes as source code, and requires compilation. Please read the README file 18 | and follow the directions - it is actually quite easy. 19 | 20 | 21 | 22 | Q. Your package does not compile/run/work on my system. 23 | 24 | A. Well, unfortunately I only have access to a limited number of system configurations. 25 | So, if you are experiencing an error on your system, please let me know! These things 26 | can usually be corrected easily - for everyone's benefit. 27 | 28 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/normdictsep.m: -------------------------------------------------------------------------------- 1 | function Aout = normdictsep(Bsep,A) 2 | %NORMDICTSEP Sparse-separable dictionary normalization. 3 | % Aout = NORMDICTSEP(Bsep,A) normalizes the columns of A such that the 4 | % sparse-separable dictioanry (Bsep,Aout) has unit-energy atoms. 5 | % 6 | % See also SPARSEDICT. 7 | 8 | % Ron Rubinstein 9 | % Computer Science Department 10 | % Technion, Haifa 32000 Israel 11 | % ronrubin@cs 12 | % 13 | % October 2009 14 | 15 | 16 | atomnorms = zeros(size(A,2),1); 17 | gamma = speye(size(A,2)); 18 | 19 | for i = 1:size(A,2) 20 | atomnorms(i) = sqrt(sum(dictsep(Bsep,A,gamma(:,i)).^2)); 21 | end 22 | 23 | Aout = A*spdiags(1./atomnorms,0,size(A,2),size(A,2)); 24 | 25 | end 26 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/ompsver.m: -------------------------------------------------------------------------------- 1 | function v = ompsver(history) 2 | %OMPSVER OMPSBox version information. 3 | % OMPSVER displays the current Sparse OMP toolbox version information. 4 | % 5 | % OMPSVER('history') also displays history information about the previous 6 | % versions of the Sparse OMP toolbox and their change logs. 7 | % 8 | % V = OMPSVER returns the version number of the current Sparse OMP 9 | % toolbox, and does not display any information. 10 | 11 | 12 | % Ron Rubinstein 13 | % Computer Science Department 14 | % Technion, Haifa 32000 Israel 15 | % ronrubin@cs 16 | % 17 | % October 2009 18 | 19 | 20 | ver = 1; 21 | 22 | if (nargout>0) 23 | if (nargin>0) 24 | error('Invalid number of parameters.'); 25 | end 26 | v = ver; 27 | 28 | else 29 | 30 | if (nargin==0 || (nargin==1 && strcmpi(history,'history'))) 31 | 32 | disp(' '); 33 | disp('--------------------------------------'); 34 | printf(' Sparse OMP Toolbox version %d ',ver); 35 | disp('--------------------------------------'); 36 | disp(' '); 37 | 38 | else 39 | error('Unknown parameters.'); 40 | end 41 | 42 | if (nargin>0) 43 | 44 | 45 | disp(' '); 46 | disp(' '); 47 | disp('Sparse OMP Toolbox version 1, 18.10.09'); 48 | disp('---------------------------------------'); 49 | disp(' '); 50 | disp('First public release.'); 51 | disp(' '); 52 | disp(' '); 53 | 54 | 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/private/dictsepmex.m: -------------------------------------------------------------------------------- 1 | %This is the Matlab interface to the MEX implementation of the sparse 2 | %dictionary forward operator. The function is not for independent use, only 3 | %through dictsep.m. 4 | 5 | 6 | %DICTSEPMEX Matlab interface to the sparse dictionary forward operator. 7 | % X = DICTSEPMEX(Bsep,A,GAMMA) applies the sparse dictionary (Bsep,A) to 8 | % the specified sparse matrix GAMMA, producing X = B*A*GAMMA. 9 | 10 | 11 | % Ron Rubinstein 12 | % Computer Science Department 13 | % Technion, Haifa 32000 Israel 14 | % ronrubin@cs 15 | % 16 | % August 2009 17 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/private/dicttsepmex.m: -------------------------------------------------------------------------------- 1 | %This is the Matlab interface to the MEX implementation of the sparse 2 | %dictionary transpose operator. The function is not for independent use, 3 | %only through dicttsep.m. 4 | 5 | 6 | %DICTTSEPMEX Matlab interface to the sparse dictionary transpose operator 7 | % Y = DICTTSEPMEX(Bsep,A,X) applies the transpose of the sparse dictionary 8 | % (Bsep,A) to the specified matrix X, producing Y = (B*A)'*X. 9 | 10 | 11 | % Ron Rubinstein 12 | % Computer Science Department 13 | % Technion, Haifa 32000 Israel 14 | % ronrubin@cs 15 | % 16 | % August 2009 17 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/private/make.m: -------------------------------------------------------------------------------- 1 | function make 2 | %MAKE Build the OMPSBox package. 3 | % MAKE compiles all OMPSBox MEX functions, using Matlab's default MEX 4 | % compiler. If the MEX compiler has not been set-up before, please run 5 | % 6 | % mex -setup 7 | % 8 | % before using this MAKE file. 9 | 10 | % Ron Rubinstein 11 | % Computer Science Department 12 | % Technion, Haifa 32000 Israel 13 | % ronrubin@cs 14 | % 15 | % August 2009 16 | 17 | 18 | % detect platform 19 | 20 | compstr = computer; 21 | is64bit = strcmp(compstr(end-1:end),'64'); 22 | 23 | 24 | % compilation parameters 25 | 26 | compile_params = cell(0); 27 | if (is64bit) 28 | compile_params{1} = '-largeArrayDims'; 29 | end 30 | 31 | 32 | % Compile files % 33 | 34 | dictsources = {'mexutils.c','myblas.c','sparsedict.c'}; 35 | ompsources = {'mexutils.c','ompscore.c','omputils.c','myblas.c','ompprof.c','sparsedict.c'}; 36 | 37 | disp('Compiling ompsmex...'); 38 | mex('ompsmex.c', ompsources{:},compile_params{:}); 39 | 40 | disp('Compiling omps2mex...'); 41 | mex('omps2mex.c', ompsources{:},compile_params{:}); 42 | 43 | disp('Compiling dictsepmex...'); 44 | mex('dictsepmex.c', dictsources{:},compile_params{:}); 45 | 46 | disp('Compiling dicttsepmex...'); 47 | mex('dicttsepmex.c', dictsources{:},compile_params{:}); 48 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/private/omps2mex.m: -------------------------------------------------------------------------------- 1 | %This is the Matlab interface to the Sparse OMP2 MEX implementation. 2 | %The function is not for independent use, only through omps2.m. 3 | 4 | 5 | %OMPS2MEX Matlab interface to the Sparse OMP2 MEX implementation. 6 | % GAMMA = OMPS2MEX(Bsep,A,X,G,EPSILON,SPARSE_G,MSGDELTA,MAXATOMS,PROFILE) 7 | % invokes the OMP2 MEX function according to the specified parameters. The 8 | % parameter G is not required, and if not specified, [] should be passed. 9 | % 10 | % EPSILON - the target error. 11 | % SPARSE_G - returns a sparse GAMMA when nonzero, full GAMMA when zero. 12 | % MSGDELTA - the delay in secs between messages. Zero means no messages. 13 | % MAXATOMS - the max number of atoms per signal, negative for no max. 14 | % PROFILE - nonzero means that profiling information should be printed. 15 | 16 | 17 | % Ron Rubinstein 18 | % Computer Science Department 19 | % Technion, Haifa 32000 Israel 20 | % ronrubin@cs 21 | % 22 | % August 2009 23 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/private/ompsmex.m: -------------------------------------------------------------------------------- 1 | %This is the Matlab interface to the Sparse OMP MEX implementation. 2 | %The function is not for independent use, only through omps.m. 3 | 4 | 5 | %OMPSMEX Matlab interface to the Sparse OMP MEX implementation. 6 | % GAMMA = OMPSMEX(Bsep,A,X,G,L,SPARSE_G,MSGDELTA,PROFILE) invokes the OMP 7 | % MEX function according to the specified parameters. The parameter G is 8 | % not required, and if not specified, should be passed as []. 9 | % 10 | % L - the target sparsity. 11 | % SPARSE_G - returns a sparse GAMMA when nonzero, full GAMMA when zero. 12 | % MSGDELTA - the delay in secs between messages. Zero means no messages. 13 | % PROFILE - nonzero means that profiling information should be printed. 14 | 15 | 16 | % Ron Rubinstein 17 | % Computer Science Department 18 | % Technion, Haifa 32000 Israel 19 | % ronrubin@cs 20 | % 21 | % August 2009 22 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/private/printf.m: -------------------------------------------------------------------------------- 1 | function str = printf(varargin) 2 | %PRINTF Print formatted text to screen. 3 | % PRINTF(FMT,VAL1,VAL2,...) formats the data in VAL1,VAL2,... according to 4 | % the format string FMT, and prints the result to the screen. 5 | % 6 | % The call to PRINTF(FMT,VAL1,VAL2,...) simply invokes the call 7 | % DISP(SPRINTF(FMT,VAL1,VAL2,...)). For a complete description of the 8 | % format string options see function SPRINTF. 9 | % 10 | % STR = PRINTF(...) also returns the formatted string. 11 | 12 | 13 | % Ron Rubinstein 14 | % Computer Science Department 15 | % Technion, Haifa 32000 Israel 16 | % ronrubin@cs 17 | % 18 | % April 2008 19 | 20 | 21 | if (nargout>0) 22 | str = sprintf(varargin{:}); 23 | disp(str); 24 | else 25 | disp(sprintf(varargin{:})); 26 | end 27 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ompsbox1/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | OMPSBox v1 README 3 | October 18, 2009 4 | 5 | 6 | 7 | OMPSBox installation: 8 | --------------------- 9 | 10 | 1. Unpack the contents of the compressed file to a new directory, named e.g. "ompsbox". 11 | 2. If you have not done so before, configure Matlab's MEX compiler by entering 12 | >> mex -setup 13 | prior to using MAKE. For optimal performance, it is recommended that you select a compiler 14 | that performs optimizations. For instance, in Windows, MS Visual Studio is preferred to Lcc. 15 | 3. Within Matlab, navigate to the OMPSBox directory, and then to the "private" directory within it, 16 | and enter MAKE to run the compilation script. 17 | 4. Add the OMPSBox package directory to the Matlab path (you can use the ADDPATH command for this). 18 | Do not add the private directory to the path. 19 | 20 | 21 | OMPSBox quick start: 22 | -------------------- 23 | 24 | 1. Enter "help sparsedict" at the Matlab prompt for an overview of sparse dictionaries in OMPSBox. 25 | 2. Enter "ompspeedcompare" to test the OMPSBox installation and compare the speed of sparse and standard OMP. 26 | 3. For a complete list of functions in the package, enter 27 | >> help ompsbox 28 | This assumes the package was installed to a directory named "ompsbox". If not, replace ompsbox 29 | in the above with the (unqualified) name of the OMPSBox installation directory. 30 | 31 | Also see faq.txt for some frequently asked questions about the package. 32 | -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ref_paper/KSVD-OMP-v2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/ref_paper/KSVD-OMP-v2.pdf -------------------------------------------------------------------------------- /[ToolBox]/ksvdbox&omp/ref_paper/sparsedict.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/[ToolBox]/ksvdbox&omp/ref_paper/sparsedict.pdf -------------------------------------------------------------------------------- /l1magic/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/.DS_Store -------------------------------------------------------------------------------- /l1magic/Data/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Data/.DS_Store -------------------------------------------------------------------------------- /l1magic/Data/RandomStates.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Data/RandomStates.mat -------------------------------------------------------------------------------- /l1magic/Data/boats.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Data/boats.mat -------------------------------------------------------------------------------- /l1magic/Data/camera.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Data/camera.mat -------------------------------------------------------------------------------- /l1magic/Measurements/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Measurements/.DS_Store -------------------------------------------------------------------------------- /l1magic/Measurements/A_f.m: -------------------------------------------------------------------------------- 1 | % A_f.m 2 | % 3 | % Takes "scrambled Fourier" measurements. 4 | % 5 | % Usage: b = A_f(x, OMEGA, P) 6 | % 7 | % x - N vector 8 | % 9 | % b - K vector = [real part; imag part] 10 | % 11 | % OMEGA - K/2 vector denoting which Fourier coefficients to use 12 | % (the real and imag parts of each freq are kept). 13 | % 14 | % P - Permutation to apply to the input vector. Fourier coeffs of 15 | % x(P) are calculated. 16 | % Default = 1:N (no scrambling). 17 | % 18 | % Written by: Justin Romberg, Caltech 19 | % Created: October 2005 20 | % Email: jrom@acm.caltech.edu 21 | % 22 | 23 | function b = A_f(x, OMEGA, P) 24 | 25 | N = length(x); 26 | if (nargin < 3), P = 1:N; end 27 | 28 | fx = 1/sqrt(N)*fft(x(P)); 29 | b = [sqrt(2)*real(fx(OMEGA)); sqrt(2)*imag(fx(OMEGA))]; 30 | 31 | -------------------------------------------------------------------------------- /l1magic/Measurements/A_fhp.m: -------------------------------------------------------------------------------- 1 | % A_fhp.m 2 | % 3 | % Takes measurements in the upper half-plane of the 2D Fourier transform. 4 | % 5 | % Usage: b = A_fhp(x, OMEGA) 6 | % 7 | % x - N vector 8 | % 9 | % b - K vector = [mean; real part(OMEGA); imag part(OMEGA)] 10 | % 11 | % OMEGA - K/2-1 vector denoting which Fourier coefficients to use 12 | % (the real and imag parts of each freq are kept). 13 | % 14 | % Written by: Justin Romberg, Caltech 15 | % Created: October 2005 16 | % Email: jrom@acm.caltech.edu 17 | % 18 | 19 | function y = A_fhp(x, OMEGA) 20 | 21 | n = round(sqrt(length(x))); 22 | 23 | yc = 1/n*fft2(reshape(x,n,n)); 24 | y = [yc(1,1); sqrt(2)*real(yc(OMEGA)); sqrt(2)*imag(yc(OMEGA))]; 25 | 26 | -------------------------------------------------------------------------------- /l1magic/Measurements/At_f.m: -------------------------------------------------------------------------------- 1 | % At_f.m 2 | % 3 | % Adjoint for "scrambled Fourier" measurements. 4 | % 5 | % Usage: x = At_f(b, N, OMEGA, P) 6 | % 7 | % b - K vector = [real part; imag part] 8 | % 9 | % N - length of output x 10 | % 11 | % OMEGA - K/2 vector denoting which Fourier coefficients to use 12 | % (the real and imag parts of each freq are kept). 13 | % 14 | % P - Permutation to apply to the input vector. Fourier coeffs of 15 | % x(P) are embedded. 16 | % Default = 1:N (no scrambling). 17 | % 18 | % Written by: Justin Romberg, Caltech 19 | % Created: October 2005 20 | % Email: jrom@acm.caltech.edu 21 | % 22 | 23 | 24 | function x = At_f(b, N, OMEGA, P) 25 | 26 | if (nargin < 4), P = 1:N; end 27 | 28 | K = length(b); 29 | fx = zeros(N,1); 30 | fx(OMEGA) = sqrt(2)*b(1:K/2) + i*sqrt(2)*b(K/2+1:K); 31 | x = zeros(N,1); 32 | x(P) = sqrt(N)*real(ifft(fx)); 33 | -------------------------------------------------------------------------------- /l1magic/Measurements/At_fhp.m: -------------------------------------------------------------------------------- 1 | % At_fhp.m 2 | % 3 | % Adjoint of At_fhp (2D Fourier half plane measurements). 4 | % 5 | % Usage: x = At_fhp(b, OMEGA, n) 6 | % 7 | % b - K vector = [mean; real part(OMEGA); imag part(OMEGA)] 8 | % 9 | % OMEGA - K/2-1 vector denoting which Fourier coefficients to use 10 | % (the real and imag parts of each freq are kept). 11 | % 12 | % n - Image is nxn pixels 13 | % 14 | % x - N vector 15 | % 16 | % Written by: Justin Romberg, Caltech 17 | % Created: October 2005 18 | % Email: jrom@acm.caltech.edu 19 | % 20 | 21 | function x = At_fhp(y, OMEGA, n) 22 | 23 | K = length(y); 24 | 25 | fx = zeros(n,n); 26 | fx(1,1) = y(1); 27 | fx(OMEGA) = sqrt(2)*(y(2:(K+1)/2) + i*y((K+3)/2:K)); 28 | x = reshape(real(n*ifft2(fx)), n*n, 1); 29 | -------------------------------------------------------------------------------- /l1magic/Measurements/LineMask.m: -------------------------------------------------------------------------------- 1 | % LineMask.m 2 | % 3 | % Returns the indicator of the domain in 2D fourier space for the 4 | % specified line geometry. 5 | % Usage : [M,Mh,mi,mhi] = LineMask(L,N) 6 | % 7 | % Written by : Justin Romberg 8 | % Created : 1/26/2004 9 | % Revised : 12/2/2004 10 | 11 | function [M,Mh,mi,mhi] = LineMask(L,N) 12 | 13 | 14 | thc = linspace(0, pi-pi/L, L); 15 | %thc = linspace(pi/(2*L), pi-pi/(2*L), L); 16 | 17 | M = zeros(N); 18 | 19 | % full mask 20 | for ll = 1:L 21 | 22 | if ((thc(ll) <= pi/4) | (thc(ll) > 3*pi/4)) 23 | yr = round(tan(thc(ll))*(-N/2+1:N/2-1))+N/2+1; 24 | for nn = 1:N-1 25 | M(yr(nn),nn+1) = 1; 26 | end 27 | else 28 | xc = round(cot(thc(ll))*(-N/2+1:N/2-1))+N/2+1; 29 | for nn = 1:N-1 30 | M(nn+1,xc(nn)) = 1; 31 | end 32 | end 33 | 34 | end 35 | 36 | 37 | % upper half plane mask (not including origin) 38 | Mh = zeros(N); 39 | Mh = M; 40 | Mh(N/2+2:N,:) = 0; 41 | Mh(N/2+1,N/2+1:N) = 0; 42 | 43 | 44 | M = ifftshift(M); 45 | mi = find(M); 46 | Mh = ifftshift(Mh); 47 | mhi = find(Mh); 48 | -------------------------------------------------------------------------------- /l1magic/Notes/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Notes/.DS_Store -------------------------------------------------------------------------------- /l1magic/Notes/Figs/CVS/Entries: -------------------------------------------------------------------------------- 1 | /l1eqexample_minl2.eps/1.1/Mon Nov 21 08:22:29 2005// 2 | /l1eqexample_minl2.pdf/1.1/Mon Nov 21 08:22:29 2005// 3 | /l1eqexample_recovered.eps/1.1/Mon Nov 21 08:22:29 2005// 4 | /l1eqexample_recovered.pdf/1.1/Mon Nov 21 08:22:29 2005// 5 | /l1eqexample_signal.eps/1.1/Mon Nov 21 08:22:29 2005// 6 | /l1eqexample_signal.pdf/1.1/Mon Nov 21 08:22:29 2005// 7 | /phantom_backproj.eps/1.1/Mon Nov 21 23:31:13 2005// 8 | /phantom_backproj.pdf/1.1/Mon Nov 21 23:31:13 2005// 9 | /phantom_orig.eps/1.1/Mon Nov 21 23:31:13 2005// 10 | /phantom_orig.pdf/1.1/Mon Nov 21 23:31:13 2005// 11 | /phantom_sampling.eps/1.1/Mon Nov 21 23:31:13 2005// 12 | /phantom_sampling.pdf/1.1/Mon Nov 21 23:31:13 2005// 13 | /phantom_tv.eps/1.1/Mon Nov 21 23:31:13 2005// 14 | /phantom_tv.pdf/1.1/Mon Nov 21 23:31:13 2005// 15 | D 16 | -------------------------------------------------------------------------------- /l1magic/Notes/Figs/CVS/Repository: -------------------------------------------------------------------------------- 1 | l1magic/Notes/Figs -------------------------------------------------------------------------------- /l1magic/Notes/Figs/CVS/Root: -------------------------------------------------------------------------------- 1 | :ext:jrom@acm.caltech.edu:/home/jrom/CVS/ -------------------------------------------------------------------------------- /l1magic/Notes/Figs/l1eqexample_minl2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Notes/Figs/l1eqexample_minl2.pdf -------------------------------------------------------------------------------- /l1magic/Notes/Figs/l1eqexample_recovered.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Notes/Figs/l1eqexample_recovered.pdf -------------------------------------------------------------------------------- /l1magic/Notes/Figs/l1eqexample_signal.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Notes/Figs/l1eqexample_signal.pdf -------------------------------------------------------------------------------- /l1magic/Notes/Figs/phantom_backproj.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Notes/Figs/phantom_backproj.pdf -------------------------------------------------------------------------------- /l1magic/Notes/Figs/phantom_orig.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Notes/Figs/phantom_orig.pdf -------------------------------------------------------------------------------- /l1magic/Notes/Figs/phantom_sampling.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Notes/Figs/phantom_sampling.pdf -------------------------------------------------------------------------------- /l1magic/Notes/Figs/phantom_tv.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Notes/Figs/phantom_tv.pdf -------------------------------------------------------------------------------- /l1magic/Notes/l1magic_notes.blg: -------------------------------------------------------------------------------- 1 | This is BibTeX, Version 0.99c (Web2C 7.5.5) 2 | The top-level auxiliary file: l1magic_notes.aux 3 | The style file: plain.bst 4 | Database file #1: l1magic.bib 5 | You've used 20 entries, 6 | 2118 wiz_defined-function locations, 7 | 597 strings with 6608 characters, 8 | and the built_in function-call counts, 5461 in all, are: 9 | = -- 528 10 | > -- 277 11 | < -- 0 12 | + -- 113 13 | - -- 88 14 | * -- 331 15 | := -- 979 16 | add.period$ -- 63 17 | call.type$ -- 20 18 | change.case$ -- 100 19 | chr.to.int$ -- 0 20 | cite$ -- 20 21 | duplicate$ -- 207 22 | empty$ -- 416 23 | format.name$ -- 88 24 | if$ -- 1107 25 | int.to.chr$ -- 0 26 | int.to.str$ -- 20 27 | missing$ -- 22 28 | newline$ -- 105 29 | num.names$ -- 40 30 | pop$ -- 113 31 | preamble$ -- 1 32 | purify$ -- 84 33 | quote$ -- 0 34 | skip$ -- 144 35 | stack$ -- 0 36 | substring$ -- 218 37 | swap$ -- 19 38 | text.length$ -- 0 39 | text.prefix$ -- 0 40 | top$ -- 0 41 | type$ -- 70 42 | warning$ -- 0 43 | while$ -- 50 44 | width$ -- 22 45 | write$ -- 216 46 | -------------------------------------------------------------------------------- /l1magic/Notes/l1magic_notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Notes/l1magic_notes.pdf -------------------------------------------------------------------------------- /l1magic/Optimization/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Algorithm-and-Toolbox/CS-algorithms/89e09c33f0aeee592df7c3bc8f0fc0a9b24c3372/l1magic/Optimization/.DS_Store -------------------------------------------------------------------------------- /l1magic/Optimization/cgsolve.m: -------------------------------------------------------------------------------- 1 | % cgsolve.m 2 | % 3 | % Solve a symmetric positive definite system Ax = b via conjugate gradients. 4 | % 5 | % Usage: [x, res, iter] = cgsolve(A, b, tol, maxiter, verbose) 6 | % 7 | % A - Either an NxN matrix, or a function handle. 8 | % 9 | % b - N vector 10 | % 11 | % tol - Desired precision. Algorithm terminates when 12 | % norm(Ax-b)/norm(b) < tol . 13 | % 14 | % maxiter - Maximum number of iterations. 15 | % 16 | % verbose - If 0, do not print out progress messages. 17 | % If and integer greater than 0, print out progress every 'verbose' iters. 18 | % 19 | % Written by: Justin Romberg, Caltech 20 | % Email: jrom@acm.caltech.edu 21 | % Created: October 2005 22 | % 23 | 24 | function [x, res, iter] = cgsolve(A, b, tol, maxiter, verbose) 25 | 26 | if (nargin < 5), verbose = 1; end 27 | 28 | implicit = isa(A,'function_handle'); 29 | 30 | x = zeros(length(b),1); 31 | r = b; 32 | d = r; 33 | delta = r'*r; 34 | delta0 = b'*b; 35 | numiter = 0; 36 | bestx = x; 37 | bestres = sqrt(delta/delta0); 38 | while ((numiter < maxiter) && (delta > tol^2*delta0)) 39 | 40 | % q = A*d 41 | if (implicit), q = A(d); else q = A*d; end 42 | 43 | alpha = delta/(d'*q); 44 | x = x + alpha*d; 45 | 46 | if (mod(numiter+1,50) == 0) 47 | % r = b - Aux*x 48 | if (implicit), r = b - A(x); else r = b - A*x; end 49 | else 50 | r = r - alpha*q; 51 | end 52 | 53 | deltaold = delta; 54 | delta = r'*r; 55 | beta = delta/deltaold; 56 | d = r + beta*d; 57 | numiter = numiter + 1; 58 | if (sqrt(delta/delta0) < bestres) 59 | bestx = x; 60 | bestres = sqrt(delta/delta0); 61 | end 62 | 63 | if ((verbose) && (mod(numiter,verbose)==0)) 64 | disp(sprintf('cg: Iter = %d, Best residual = %8.3e, Current residual = %8.3e', ... 65 | numiter, bestres, sqrt(delta/delta0))); 66 | end 67 | 68 | end 69 | 70 | if (verbose) 71 | disp(sprintf('cg: Iterations = %d, best residual = %14.8e', numiter, bestres)); 72 | end 73 | x = bestx; 74 | res = bestres; 75 | iter = numiter; 76 | 77 | -------------------------------------------------------------------------------- /l1magic/README: -------------------------------------------------------------------------------- 1 | 2 | 3 | l1 magic 4 | -------- 5 | 6 | This package contains code for solving seven optimization problems. A detailed explanation is given in the file l1magic.pdf. 7 | 8 | The main directory contains MATLAB m-files which contain simple examples for each of the recovery problems. They illustrate how the code should be used (it is fairly straightforward). The prefixes on the example files are as follows: 9 | "l1eq" = L1 minimization with equality constraints, 10 | "l1qc" = L1 minimization with quadratic (L2 norm) constraints, 11 | "l1decode" = L1 norm approximation (for channel decoding), 12 | "11dantzig" = L1 minimization with minimal residual correlation (the Dantzig selector). 13 | "tveq" = TV minimization with equality constraints, 14 | "tvqc" = TV minimization with quadratic constrains, 15 | "tvdantzig" = TV minimization with minimal residual correlation. 16 | 17 | The 'Optimization' directory contains the m-files for the actual interior-point optimization algorithms. 18 | 19 | The 'Measurements' directory contains implementations of some relevant large-scale measurement matrices that are used in the examples. 20 | 21 | The 'Data' directory contains test images for the examples. 22 | 23 | The code will only run on MATLAB 7.0 and higher. The incompatibility with previous versions comes from the way function handles are used. 24 | 25 | If you have questions or comments, please contact 26 | Justin Romberg 27 | Caltech, Applied and Computational Mathematics, jrom@acm.caltech.edu 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /l1magic/l1dantzig_example.m: -------------------------------------------------------------------------------- 1 | % l1dantzig_example.m 2 | % 3 | % Test out l1dantzig code (l1 minimization with bounded residual correlation). 4 | % 5 | % Written by: Justin Romberg, Caltech 6 | % Email: jrom@acm.caltech.edu 7 | % Created: October 2005 8 | % 9 | 10 | % put optimization code in path if not already there 11 | path(path, './Optimization'); 12 | 13 | % signal length 14 | N = 512; 15 | 16 | % number of spikes to put down 17 | T = 20; 18 | 19 | % number of observations to make 20 | K = 120; 21 | 22 | % random +/- 1 signal 23 | x = zeros(N,1); 24 | q = randperm(N); 25 | x(q(1:T)) = sign(randn(T,1)); 26 | 27 | % measurement matrix = random projection 28 | disp('Creating measurment matrix...'); 29 | A = randn(K,N); 30 | A = orth(A')'; 31 | disp('Done.'); 32 | 33 | % noisy observations 34 | sigma = 0.005; 35 | e = sigma*randn(K,1); 36 | y = A*x + e; 37 | 38 | % initial guess = min energy 39 | x0 = A'*y; 40 | 41 | % Dantzig selection 42 | epsilon = 3e-3; 43 | tic 44 | xp = l1dantzig_pd(x0, A, [], y, epsilon, 5e-2); 45 | toc 46 | 47 | 48 | % large scale 49 | % Afun = @(z) A*z; 50 | % Atfun = @(z) A'*z; 51 | % tic 52 | % xp = l1dantzig_pd(x0, Afun, Atfun, y, epsilon, 5e-2, 50, 1e-8, 500); 53 | % toc 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /l1magic/l1decode_example.m: -------------------------------------------------------------------------------- 1 | % l1decode_example.m 2 | % 3 | % Test out l1decode code. 4 | % 5 | % Written by: Justin Romberg, Caltech 6 | % Email: jrom@acm.caltech.edu 7 | % Created: October 2005 8 | % 9 | 10 | path(path, './Optimization'); 11 | 12 | % source length 13 | N = 256; 14 | 15 | % codeword length 16 | M = 4*N; 17 | 18 | % number of perturbations 19 | T = round(.2*M); 20 | 21 | % coding matrix 22 | G = randn(M,N); 23 | 24 | % source word 25 | x = randn(N,1); 26 | 27 | % code word 28 | c = G*x; 29 | 30 | % channel: perturb T randomly chosen entries 31 | q = randperm(M); 32 | y = c; 33 | y(q(1:T)) = randn(T,1); 34 | 35 | % recover 36 | x0 = inv(G'*G)*G'*y; 37 | xp = l1decode_pd(x0, G, [], y, 1e-4, 30); 38 | 39 | % large scale 40 | % gfun = @(z) G*z; 41 | % gtfun = @(z) G'*z; 42 | % xp = l1decode_pd(x0, gfun, gtfun, y, 1e-3, 25, 1e-8, 200); 43 | -------------------------------------------------------------------------------- /l1magic/l1eq_example.m: -------------------------------------------------------------------------------- 1 | % l1eq_example.m 2 | % 3 | % Test out l1eq code (l1 minimization with equality constraints). 4 | % 5 | % Written by: Justin Romberg, Caltech 6 | % Email: jrom@acm.caltech.edu 7 | % Created: October 2005 8 | % 9 | 10 | % put key subdirectories in path if not already there 11 | path(path, './Optimization'); 12 | path(path, './Data'); 13 | 14 | % To reproduce the example in the documentation, uncomment the 15 | % two lines below 16 | %load RandomStates 17 | %rand('state', rand_state); 18 | %randn('state', randn_state); 19 | 20 | % signal length 21 | N = 512; 22 | % number of spikes in the signal 23 | T = 20; 24 | % number of observations to make 25 | K = 120; 26 | 27 | % random +/- 1 signal 28 | x = zeros(N,1); 29 | q = randperm(N); 30 | x(q(1:T)) = sign(randn(T,1)); 31 | 32 | % measurement matrix 33 | disp('Creating measurment matrix...'); 34 | A = randn(K,N); 35 | A = orth(A')'; 36 | disp('Done.'); 37 | 38 | % observations 39 | y = A*x; 40 | 41 | % initial guess = min energy 42 | x0 = A'*y; 43 | 44 | % solve the LP 45 | tic 46 | xp = l1eq_pd(x0, A, [], y, 1e-3); 47 | toc 48 | 49 | % large scale 50 | % Afun = @(z) A*z; 51 | % Atfun = @(z) A'*z; 52 | % tic 53 | % xp = l1eq_pd(x0, Afun, Atfun, y, 1e-3, 30, 1e-8, 200); 54 | % toc 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /l1magic/l1qc_example.m: -------------------------------------------------------------------------------- 1 | % l1qc_example.m 2 | % 3 | % Test out l1qc code (l1 minimization with quadratic constraint). 4 | % 5 | % Written by: Justin Romberg, Caltech 6 | % Email: jrom@acm.caltech.edu 7 | % Created: October 2005 8 | % 9 | 10 | % put optimization code in path if not already there 11 | path(path, './Optimization'); 12 | 13 | % signal length 14 | N = 512; 15 | 16 | % number of spikes to put down 17 | T = 20; 18 | 19 | % number of observations to make 20 | K = 120; 21 | 22 | % random +/- 1 signal 23 | x = zeros(N,1); 24 | q = randperm(N); 25 | x(q(1:T)) = sign(randn(T,1)); 26 | 27 | % measurement matrix 28 | disp('Creating measurment matrix...'); 29 | A = randn(K,N); 30 | A = orth(A')'; 31 | disp('Done.'); 32 | 33 | % noisy observations 34 | sigma = 0.005; 35 | e = sigma*randn(K,1); 36 | y = A*x + e; 37 | 38 | % initial guess = min energy 39 | x0 = A'*y; 40 | 41 | % take epsilon a little bigger than sigma*sqrt(K) 42 | epsilon = sigma*sqrt(K)*sqrt(1 + 2*sqrt(2)/sqrt(K)); 43 | 44 | tic 45 | xp = l1qc_logbarrier(x0, A, [], y, epsilon, 1e-3); 46 | toc 47 | 48 | % large scale 49 | % Afun = @(z) A*z; 50 | % Atfun = @(z) A'*z; 51 | % tic 52 | % xp = l1qc_logbarrier(x0, Afun, Atfun, y, epsilon, 1e-3, 50, 1e-8, 500); 53 | % toc 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /l1magic/tvdantzig_example.m: -------------------------------------------------------------------------------- 1 | % tvdantzig_example.m 2 | % 3 | % Test out tvdantzig code (TV minimization with bounded residual correlation). 4 | % 5 | % Written by: Justin Romberg, Caltech 6 | % Email: jrom@acm.caltech.edu 7 | % Created: October 2005 8 | % 9 | 10 | % use implicit, matrix-free algorithms ? 11 | largescale = 0; 12 | 13 | path(path, './Optimization'); 14 | path(path, './Measurements'); 15 | path(path, './Data'); 16 | 17 | 18 | % test image = 32x32 piece of cameraman's arm 19 | load camera 20 | I = camera(81:112,37:68); 21 | n = 32; 22 | N = n*n; 23 | I = I/norm(I(:)); 24 | I = I - mean(I(:)); 25 | x = reshape(I,N,1); 26 | 27 | 28 | % num obs 29 | K = 300; 30 | 31 | % permutation P and observation set OMEGA 32 | P = randperm(N)'; 33 | q = randperm(N/2-1)+1; 34 | OMEGA = q(1:K/2)'; 35 | 36 | 37 | 38 | % measurement matrix 39 | if (largescale) 40 | A = @(z) A_f(z, OMEGA, P); 41 | At = @(z) At_f(z, N, OMEGA, P); 42 | % obsevations 43 | b = A(x); 44 | % initial point 45 | x0 = At(b); 46 | else 47 | FT = 1/sqrt(N)*fft(eye(N)); 48 | A = sqrt(2)*[real(FT(OMEGA,:)); imag(FT(OMEGA,:))]; 49 | A = [1/sqrt(N)*ones(1,N); A]; 50 | At = []; 51 | % observations 52 | b = A*x; 53 | % initial point 54 | x0 = A'*b; 55 | end 56 | 57 | 58 | epsilon = 5e-3; 59 | 60 | 61 | 62 | tvI = sum(sum(sqrt([diff(I,1,2) zeros(n,1)].^2 + [diff(I,1,1); zeros(1,n)].^2 ))); 63 | disp(sprintf('Original TV = %.3f', tvI)); 64 | 65 | time0 = clock; 66 | xp = tvdantzig_logbarrier(x0, A, At, b, epsilon, 1e-3, 5, 1e-8, 1500); 67 | Ip = reshape(xp, n, n); 68 | disp(sprintf('Total elapsed time = %f secs\n', etime(clock,time0))); 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /l1magic/tveq_example.m: -------------------------------------------------------------------------------- 1 | % tveq_example.m 2 | % 3 | % Test out tveq code (TV minimization with equality constraints). 4 | % 5 | % Written by: Justin Romberg, Caltech 6 | % Email: jrom@acm.caltech.edu 7 | % Created: October 2005 8 | % 9 | 10 | % use implicit, matrix-free algorithms ? 11 | largescale = 0; 12 | 13 | path(path, './Optimization'); 14 | path(path, './Measurements'); 15 | path(path, './Data'); 16 | 17 | 18 | % test image = 32x32 piece of cameraman's arm 19 | load camera 20 | I = camera(81:112,37:68); 21 | n = 32; 22 | N = n*n; 23 | I = I/norm(I(:)); 24 | I = I - mean(I(:)); 25 | x = reshape(I,N,1); 26 | 27 | 28 | % num obs 29 | K = 300; 30 | 31 | % permutation P and observation set OMEGA 32 | P = randperm(N)'; 33 | q = randperm(N/2-1)+1; 34 | OMEGA = q(1:K/2)'; 35 | 36 | 37 | 38 | % measurement matrix 39 | if (largescale) 40 | A = @(z) A_f(z, OMEGA, P); 41 | At = @(z) At_f(z, N, OMEGA, P); 42 | % obsevations 43 | b = A(x); 44 | % initial point 45 | x0 = At(b); 46 | else 47 | FT = 1/sqrt(N)*fft(eye(N)); 48 | A = sqrt(2)*[real(FT(OMEGA,:)); imag(FT(OMEGA,:))]; 49 | A = [1/sqrt(N)*ones(1,N); A]; 50 | At = []; 51 | % observations 52 | b = A*x; 53 | % initial point 54 | x0 = A'*b; 55 | end 56 | 57 | tvI = sum(sum(sqrt([diff(I,1,2) zeros(n,1)].^2 + [diff(I,1,1); zeros(1,n)].^2 ))); 58 | disp(sprintf('Original TV = %.3f', tvI)); 59 | 60 | time0 = clock; 61 | xp = tveq_logbarrier(x0, A, At, b, 1e-3, 5, 1e-8, 200); 62 | Ip = reshape(xp, n, n); 63 | disp(sprintf('Total elapsed time = %f secs\n', etime(clock,time0))); 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /l1magic/tveq_phantom_example.m: -------------------------------------------------------------------------------- 1 | % tveq_phantom_example.m 2 | % 3 | % Phantom reconstruction from samples on 22 radial lines in the Fourier 4 | % plane. 5 | % 6 | % Written by: Justin Romberg, Caltech 7 | % Email: jrom@acm.caltech.edu 8 | % Created: October 2005 9 | % 10 | 11 | 12 | path(path, './Optimization'); 13 | path(path, './Measurements'); 14 | path(path, './Data'); 15 | 16 | 17 | % Phantom 18 | n = 256; 19 | N = n*n; 20 | X = phantom(n); 21 | x = X(:); 22 | 23 | % number of radial lines in the Fourier domain 24 | L = 22; 25 | 26 | % Fourier samples we are given 27 | [M,Mh,mh,mhi] = LineMask(L,n); 28 | OMEGA = mhi; 29 | A = @(z) A_fhp(z, OMEGA); 30 | At = @(z) At_fhp(z, OMEGA, n); 31 | 32 | % measurements 33 | y = A(x); 34 | 35 | % min l2 reconstruction (backprojection) 36 | xbp = At(y); 37 | Xbp = reshape(xbp,n,n); 38 | 39 | % recovery 40 | tic 41 | tvI = sum(sum(sqrt([diff(X,1,2) zeros(n,1)].^2 + [diff(X,1,1); zeros(1,n)].^2 ))); 42 | disp(sprintf('Original TV = %8.3f', tvI)); 43 | xp = tveq_logbarrier(xbp, A, At, y, 1e-1, 2, 1e-8, 600); 44 | Xtv = reshape(xp, n, n); 45 | toc 46 | -------------------------------------------------------------------------------- /l1magic/tvqc_example.m: -------------------------------------------------------------------------------- 1 | % tvqc_example.m 2 | % 3 | % Test out tvqc code (TV minimization with quadratic constraint). 4 | % 5 | % Written by: Justin Romberg, Caltech 6 | % Email: jrom@acm.caltech.edu 7 | % Created: October 2005 8 | % 9 | 10 | % use implicit, matrix-free algorithms ? 11 | largescale = 0; 12 | 13 | path(path, './Optimization'); 14 | path(path, './Measurements'); 15 | path(path, './Data'); 16 | 17 | 18 | % test image = 32x32 piece of cameraman's arm 19 | load camera 20 | I = camera(81:112,37:68); 21 | n = 32; 22 | N = n*n; 23 | I = I/norm(I(:)); 24 | I = I - mean(I(:)); 25 | x = reshape(I,N,1); 26 | 27 | 28 | % num obs 29 | K = 300; 30 | 31 | % permutation P and observation set OMEGA 32 | P = randperm(N)'; 33 | q = randperm(N/2-1)+1; 34 | OMEGA = q(1:K/2)'; 35 | 36 | 37 | 38 | % measurement matrix 39 | if (largescale) 40 | A = @(z) A_f(z, OMEGA, P); 41 | At = @(z) At_f(z, N, OMEGA, P); 42 | % obsevations 43 | b = A(x); 44 | % initial point 45 | x0 = At(b); 46 | else 47 | FT = 1/sqrt(N)*fft(eye(N)); 48 | A = sqrt(2)*[real(FT(OMEGA,:)); imag(FT(OMEGA,:))]; 49 | A = [1/sqrt(N)*ones(1,N); A]; 50 | At = []; 51 | % observations 52 | b = A*x; 53 | % initial point 54 | x0 = A'*b; 55 | end 56 | 57 | 58 | epsilon = 5e-3; 59 | 60 | 61 | tvI = sum(sum(sqrt([diff(I,1,2) zeros(n,1)].^2 + [diff(I,1,1); zeros(1,n)].^2 ))); 62 | disp(sprintf('Original TV = %.3f', tvI)); 63 | 64 | time0 = clock; 65 | xp = tvqc_logbarrier(x0, A, At, b, epsilon, 1e-3, 5, 1e-8, 200); 66 | Ip = reshape(xp, n, n); 67 | disp(sprintf('Total elapsed time = %f secs\n', etime(clock,time0))); 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /l1magic/tvqc_quantization_example.m: -------------------------------------------------------------------------------- 1 | % tvqc_quantization_example.m 2 | % 3 | % Takes random measurements of the 'boats' image, quantizes, and 4 | % reconstructs using quadractically constrained TV. 5 | % 6 | % Written by: Justin Romberg, Caltech 7 | % Email: jrom@acm.caltech.edu 8 | % Created: October 2005 9 | % 10 | 11 | path(path, './Optimization'); 12 | path(path, './Measurements'); 13 | path(path, './Data'); 14 | 15 | % boats 16 | n = 256; 17 | N = n*n; 18 | load boats 19 | img = boats; 20 | I = img/norm(img(:)); 21 | I = I - mean(I(:)); 22 | x = reshape(I,N,1); 23 | 24 | % num obs 25 | K = 25000; 26 | 27 | % permutation P and observation set OMEGA 28 | P = randperm(N)'; 29 | q = randperm(N/2-1)+1; 30 | OMEGA = q(1:K/2)'; 31 | 32 | % measurement implicit matrices 33 | A = @(z) A_f(z, OMEGA, P); 34 | At = @(z) At_f(z, N, OMEGA, P); 35 | 36 | % take measurements 37 | Ax = A(x); 38 | % quantization codebook 39 | mxax = max(abs(Ax)); 40 | bins = 10; 41 | C = 2*mxax*(linspace(1/(2*bins),1-1/(2*bins),bins)-1/2); 42 | % quantize 43 | b = zeros(K,1); 44 | symbols = zeros(K,1); 45 | for kk = 1:K 46 | [mn,mni] = min(abs(Ax(kk)-C)); 47 | b(kk) = C(mni); 48 | symbols(kk) = mni; 49 | end 50 | % error (just for future reference) 51 | e = b - Ax; 52 | 53 | % the error should be roughly this size 54 | epsilon = (2*mxax/bins)/sqrt(12)*sqrt(K); 55 | 56 | 57 | % initial point = min l2 58 | x0 = At(b); 59 | 60 | 61 | tvI = sum(sum(sqrt([diff(I,1,2) zeros(n,1)].^2 + [diff(I,1,1); zeros(1,n)].^2 ))); 62 | disp(sprintf('original TV = %8.3f', tvI)); 63 | 64 | time0 = clock; 65 | xp = tvqc_logbarrier(x0, A, At, b, epsilon, 1e-1, 5); 66 | Ip = reshape(xp, n, n); 67 | disp(sprintf('Total elapsed time = %f secs\n', etime(clock,time0))); 68 | --------------------------------------------------------------------------------