Home > matlab > Example_weighted_BPDN.m

Example_weighted_BPDN

PURPOSE ^

% Exampled_weighted_L1

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% Exampled_weighted_L1
 Example to demonstrate use of BPDN solver when incorporating weights
 (performs one re-weighting of previous solution).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% Exampled_weighted_L1
0002 % Example to demonstrate use of BPDN solver when incorporating weights
0003 % (performs one re-weighting of previous solution).
0004 
0005 
0006 %% Clear workspace
0007 clc;
0008 clear;
0009 
0010 %% Define paths
0011 addpath misc/
0012 addpath prox_operators/
0013 
0014 %% Parameters
0015 N = 64;
0016 input_snr = 30; % Noise level (on the measurements)
0017 randn('seed', 1); rand('seed', 1);
0018 
0019 %% Create an image with few spikes
0020 im = zeros(N); ind = randperm(N^2); im(ind(1:100)) = 1;
0021 %
0022 figure(1);
0023 subplot(221), imagesc(im); axis image; axis off;
0024 colormap gray; title('Original image'); drawnow;
0025 
0026 %% Create a mask
0027 % Mask
0028 mask = rand(size(im)) < 0.095; ind = find(mask==1);
0029 % Masking matrix (sparse matrix in matlab)
0030 Ma = sparse(1:numel(ind), ind, ones(numel(ind), 1), numel(ind), numel(im));
0031 % Masking operator
0032 A = @(x) Ma*x(:);
0033 At = @(x) reshape(Ma'*x(:), size(im));
0034 
0035 %% Reconstruct from a few Fourier measurements
0036 
0037 % Composition (Masking o Fourier)
0038 A = @(x) Ma*reshape(fft2(x)/sqrt(numel(im)), numel(x), 1);
0039 At = @(x) ifft2(reshape(Ma'*x(:), size(im))*sqrt(numel(im)));
0040 
0041 % Sparsity operator
0042 Psit = @(x) x; Psi = Psit;
0043 
0044 % Select 33% of Fourier coefficients
0045 y = A(im);
0046 
0047 % Add Gaussian i.i.d. noise
0048 sigma_noise = 10^(-input_snr/20)*std(im(:));
0049 y = y + (randn(size(y)) + 1i*randn(size(y)))*sigma_noise/sqrt(2);
0050 
0051 % Display the downsampled image
0052 figure(1);
0053 subplot(222); imagesc(real(At(y))); axis image; axis off;
0054 colormap gray; title('Measured image'); drawnow;
0055 
0056 % Tolerance on noise
0057 epsilon = sqrt(chi2inv(0.99, 2*numel(ind))/2)*sigma_noise;
0058 
0059 % Parameters for BPDN
0060 param.verbose = 1; % Print log or not
0061 param.gamma = 1e-1; % Converge parameter
0062 param.rel_obj = 1e-4; % Stopping criterion for the TVDN problem
0063 param.max_iter = 300; % Max. number of iterations for the TVDN problem
0064 param.nu_B2 = 1; % Bound on the norm of the operator A
0065 param.tol_B2 = 1e-4; % Tolerance for the projection onto the L2-ball
0066 param.tight_B2 = 1; % Indicate if A is a tight frame (1) or not (0)
0067 param.tight_L1 = 1; % Indicate if Psit is a tight frame (1) or not (0)
0068 param.pos_l1 = 1; %
0069 
0070 % Solve BPDN problem (without weights)
0071 sol = sopt_mltb_solve_BPDN(y, epsilon, A, At, Psi, Psit, param);
0072 
0073 % Show reconstructed image
0074 figure(1);
0075 subplot(223); imagesc(real(sol)); axis image; axis off;
0076 colormap gray; title(['First estimate - ', ...
0077     num2str(sopt_mltb_SNR(im, real(sol))), 'dB']); drawnow;
0078 
0079 % Refine the estimate
0080 param.weights = 1./(abs(sol)+1e-5);
0081 sol = sopt_mltb_solve_BPDN(y, epsilon, A, At, Psi, Psit, param);
0082 
0083 % Show reconstructed image
0084 figure(1);
0085 subplot(224); imagesc(real(sol)); axis image; axis off;
0086 colormap gray; title(['Second estimate - ', ...
0087     num2str(sopt_mltb_SNR(im, real(sol))), 'dB']); drawnow;

Generated on Fri 22-Feb-2013 15:54:47 by m2html © 2005