Description of Example_BPDN
Description: % Example_BPDN

Home > matlab > Example_BPDN.m

# Example_BPDN

## PURPOSE

% Example_BPDN

## SYNOPSIS

This is a script file.

## DESCRIPTION

    % Example_BPDN
     Example to demonstrate use of BPDN solver.  A random Fourier sampling
     measurement operator is considered.  Daubechies 8 wavelets are used for
     the sparsifying operator.

## CROSS-REFERENCE INFORMATION

This function calls:

- sopt_mltb_solve_BPDN sopt_mltb_solve_BPDN - Solve BPDN problem

This function is called by:

## SOURCE CODE

    0001 %% Example_BPDN
    0002 % Example to demonstrate use of BPDN solver.  A random Fourier sampling
    0003 % measurement operator is considered.  Daubechies 8 wavelets are used for
    0004 % the sparsifying operator.
    0005
    0006
    0007 %% Clear workspace
    0008
    0009 clc
    0010 clear;
    0011
    0012
    0013 %% Define paths
    0014
    0015 addpath misc/
    0016 addpath prox_operators/
    0017
    0018
    0019 %% Define parameters
    0020
    0021 % Coverages (half the plane for Fourier sampling)
    0022 p = [0.50];
    0023
    0024 % Noise level (on the measurements)
    0025 input_snr = 30;
    0026
    0027
    0028 %% Read image
    0029
    0030 % Load image
    0031 im = im2double(imread('cameraman.tif'));
    0032
    0033 % Normalise
    0034 im = im/max(max(im));
    0035
    0036 % Enforce positivity
    0037 im(im<0) = 0;
    0038
    0039
    0040 %% Define sparsity operator
    0041
    0042 dwtmode('per');
    0043
    0044 % Decomposition level of the wavelet transform.
    0045 nlevel = 4;
    0046
    0047 % Daubechies 8 wavelet operator
    0048 [C,S] = wavedec2(im,nlevel,'db8');
    0049
    0050 Psit = @(x) wavedec2(x, nlevel, 'db8');
    0051 Psi = @(x) waverec2(x, S, 'db8');
    0052
    0053
    0054 %% Run simulations
    0055
    0056 % Random Fourier sampling example
    0057 %  Define mask
    0058 %  Uniform sampling of the half Fourier plane
    0059 mask = rand(size(im)) < p;
    0060 mask(:,1:floor(size(im,2)/2))=0;
    0061 mask = ifftshift(mask);
    0062 mask(1,1)=0;
    0063 mask(floor(size(im,1)/2):end,1)=0;
    0064
    0065 ind = find(mask==1);
    0066 Ma = sparse(1:numel(ind), ind, ...
    0067   ones(numel(ind), 1), numel(ind), numel(im));
    0068
    0069 % Composition (Masking o Fourier)
    0070 A = @(x) Ma*reshape(fft2(x)/sqrt(numel(ind)), numel(x), 1);
    0071 At = @(x) (ifft2(reshape(Ma'*x(:), size(im))*sqrt(numel(ind))));
    0072
    0073 % Apply measurement operator
    0074 y = A(im);
    0075
    0076 % Add Gaussian i.i.d. noise
    0077 sigma_noise = 10^(-input_snr/20)*std(im(:));
    0078 noise = (randn(size(y)) + 1i*randn(size(y)))*sigma_noise/sqrt(2);
    0079 y = y + noise;
    0080
    0081 % Tolerance on noise
    0082 epsilon = sqrt(numel(y) + 2*sqrt(numel(y)))*sigma_noise;
    0083 epsilon_up = sqrt(numel(y) + 2.1*sqrt(numel(y)))*sigma_noise;
    0084 tol_B2 = (epsilon_up/epsilon)-1; % Tolerance for the projection onto the L2-ball
    0085
    0086 % Solve optimisation problem
    0087
    0088 % Parameters for BPDN
    0089 param.verbose = 1; % Print log or not
    0090 param.gamma = 1e-1; % Convergence parameter
    0091 param.rel_obj = 5e-4; % Stopping criterion for the L1 problem
    0092 param.max_iter = 200; % Max. number of iterations for the L1 problem
    0093 param.nu_B2 = 1; % Bound on the norm of the operator A
    0094 param.tight_B2 = 0; % Indicate if A is a tight frame (1) or not (0)
    0095 param.max_iter_B2 = 200; %Max. number of iterations of the L2-ball projection
    0096 param.pos_B2 = 1; %Positivity flag
    0097 param.tol_B2 = tol_B2; % Tolerance for the projection onto the L2-ball
    0098 param.tight_L1 = 1; % Indicate if Psit is a tight frame (1) or not (0)
    0099 %Optional parameters when Psit is not a tight frame:
    0100 %param.nu_L1 = 1; % Bound on the norm of the operator Psit
    0101 %param.max_iter_L1 = 200; %Max. number of iterations of the L1 prox
    0102 %param.rel_obj_L1 = 1e-3; % Tolerance for the prox L1
    0103
    0104 % Solve BPDN problem with positivity constraint
    0105 sol1 = sopt_mltb_solve_BPDN(y, epsilon, A, At, Psi, Psit, param);
    0106
    0107 % Compute SNR
    0108 RSNR1 = 20*log10(norm(im,'fro') ...
    0109   / norm(im-sol1,'fro'));
    0110
    0111 % Example with only reality constraint
    0112 param.pos_B2 = 0; %Positivity flag
    0113 param.real_B2 = 1; %Reality flag
    0114
    0115 % Solve BPDN problem
    0116 sol2 = sopt_mltb_solve_BPDN(y, epsilon, A, At, Psi, Psit, param);
    0117
    0118 % Compute SNR
    0119 RSNR2 = 20*log10(norm(im,'fro') ...
    0120   / norm(im-sol2,'fro'));
    0121
    0122
    0123 %% Show results
    0124
    0125 figure
    0126 imagesc(sol1), axis off, axis image, colorbar
    0127 title(['Rec. with positivity const. SNR=',num2str(RSNR1), 'dB'])
    0128 colormap gray
    0129
    0130 figure
    0131 imagesc(sol2), axis off, axis image, colorbar
    0132 title(['Rec. with reality const. SNR=',num2str(RSNR2), 'dB'])
    0133 colormap gray