Description of Example_TVDN
Description: % Example_TVDN

Home > matlab > Example_TVDN.m

# Example_TVDN

## PURPOSE

% Example_TVDN

## SYNOPSIS

This is a script file.

## DESCRIPTION

    % Example_TVDN
     Example to demonstrate use of TVDN solver.  A random Fourier sampling
     measurement operator is considered.

## CROSS-REFERENCE INFORMATION

This function calls:

- sopt_mltb_solve_TVDN sopt_mltb_solve_TVDN - Solve TVDN problem

This function is called by:

## SOURCE CODE

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