Description of Example_weighted_TVDN
Description: % Exampled_weighted_TVDN

Home > matlab > Example_weighted_TVDN.m

# Example_weighted_TVDN

## PURPOSE

% Exampled_weighted_TVDN

## SYNOPSIS

This is a script file.

## DESCRIPTION

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

## CROSS-REFERENCE INFORMATION

This function calls:

- sopt_mltb_solve_TVDNoA sopt_mltb_solve_TVDNoA - Solve augmented TVDN problem

This function is called by:

## SOURCE CODE

    0001 %% Exampled_weighted_TVDN
    0002 % Example to demonstrate use of TVDN 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 %% Load image
    0020 im = phantom(N);
    0021 %
    0022 figure(1); clf;
    0023 subplot(141), 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.33; 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
    0032 %% Measure a few Fourier measurements
    0033
    0034 % Composition (Masking o Fourier)
    0035 A = @(x) Ma*reshape(fft2(x)/sqrt(numel(im)), numel(x), 1);
    0036 At = @(x) ifft2(reshape(Ma'*x(:), size(im))*sqrt(numel(im)));
    0037
    0038 % TV sparsity operator
    0039 Psit = @(x) x; Psi = Psit;
    0040
    0041 % Select 33% of Fourier coefficients
    0042 y = A(im);
    0043
    0044 % Add Gaussian i.i.d. noise
    0045 sigma_noise = 10^(-input_snr/20)*std(im(:));
    0046 y = y + (randn(size(y)) + 1i*randn(size(y)))*sigma_noise/sqrt(2);
    0047
    0048 % Display the downsampled image
    0049 figure(1);
    0050 subplot(142); imagesc(real(At(y))); axis image; axis off;
    0051 colormap gray; title('Measured image'); drawnow;
    0052
    0053 %% Reconstruct with TV
    0054
    0055 % Tolerance on noise
    0056 epsilon = sqrt(chi2inv(0.99, 2*numel(ind))/2)*sigma_noise;
    0057
    0058 % Parameters for TVDN
    0059 param.verbose = 1; % Print log or not
    0060 param.rel_obj = 1e-4; % Stopping criterion for the TVDN problem
    0061 param.max_iter = 200; % Max. nb. of iterations for the TVDN problem
    0062 param.gamma = 1e-1; % Converge parameter
    0063 param.nu_B2 = 1; % Bound on the norm of the operator A
    0064 param.tol_B2 = 1e-4; % Tolerance for the projection onto the L2-ball
    0065 param.tight_B2 = 1; % Indicate if A is a tight frame (1) or not (0)
    0066 param.max_iter_TV = 500; %
    0067 param.zero_weights_flag_TV = 0; %
    0068 param.identical_weights_flag_TV = 1; %
    0069
    0070 % Solve TVDN problem (without weights)
    0071 sol_1 = sopt_mltb_solve_TVDNoA(y, epsilon, A, At, Psi, Psit, param);
    0072
    0073 % Show first reconstructed image
    0074 figure(1);
    0075 subplot(143); imagesc(real(sol_1)); axis image; axis off;
    0076 colormap gray;
    0077 title(['First estimate: ', ...
    0078     num2str(sopt_mltb_SNR(im, real(sol_1))), 'dB']);
    0079 drawnow;
    0080 clc;
    0081
    0082 %% Re-fine the estimate with weighted TV
    0083 % Weights
    0084 [param.weights_dx_TV param.weights_dy_TV] = sopt_mltb_gradient_op(real(sol_1));
    0085 param.weights_dx_TV = 1./(abs(param.weights_dx_TV)+1e-3);
    0086 param.weights_dy_TV = 1./(abs(param.weights_dy_TV)+1e-3);
    0087 param.identical_weights_flag_TV = 0;
    0088 param.gamma = 1e-3;
    0089
    0090 % First reconstruction with weights in the gradient
    0091 param.zero_weights_flag_TV = 1;
    0092 sol_2 = sopt_mltb_solve_TVDNoA(y, epsilon, A, At, Psi, Psit, param);
    0093 % Show second reconstructed image
    0094 figure(1);
    0095 subplot(144); imagesc(real(sol_2)); axis image; axis off;
    0096 colormap gray;
    0097 title(['Second estimate: ', ...
    0098     num2str(sopt_mltb_SNR(im, real(sol_2))), 'dB']);
    0099 drawnow;