Description of Example_TVDN2
Description: % Example_TVDN2

Home > matlab > Example_TVDN2.m

# Example_TVDN2

## PURPOSE

% Example_TVDN2

## SYNOPSIS

This is a script file.

## DESCRIPTION

    % Example_TVDN2
     Two examples to demonstrate use of TVDN solver.  Simple inpainting and
     Fourier measurement examples are included.

## 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_TVDN2
    0002 % Two examples to demonstrate use of TVDN solver.  Simple inpainting and
    0003 % Fourier measurement examples are included.
    0004
    0005
    0006 %% Clear workspace
    0007 clc;
    0008 clear;
    0009
    0010 %% Define paths
    0011 addpath misc/
    0012 addpath prox_operators/
    0013
    0014 %% Parameters
    0015 input_snr = 30; % Noise level (on the measurements)
    0016
    0017 %% Load an image
    0018 im = im2double(imread('cameraman.tif'));
    0019 %
    0020 figure(1);
    0021 imagesc(im); axis image; axis off;
    0022 colormap gray; title('Original image'); drawnow;
    0023
    0024 %% Create a mask with 33% of 1 (the rest is set to 0)
    0025 % Mask
    0026 mask = rand(size(im)) < 0.33; ind = find(mask==1);
    0027 % Masking matrix (sparse matrix in matlab)
    0028 Ma = sparse(1:numel(ind), ind, ones(numel(ind), 1), numel(ind), numel(im));
    0029 % Masking operator
    0030 A = @(x) Ma*x(:); % Select 33% of the values in x;
    0031 At = @(x) reshape(Ma'*x(:), size(im)); % Adjoint operator + reshape image
    0032
    0033 %% First problem: Inpainting problem
    0034 % Select 33% of pixels
    0035 y = A(im);
    0036 % Add Gaussian i.i.d. noise
    0037 sigma_noise = 10^(-input_snr/20)*std(im(:));
    0038 y = y + randn(size(y))*sigma_noise;
    0039 % Display the downsampled image
    0040 figure(2); clf;
    0041 subplot(121); imagesc(At(y)); axis image; axis off;
    0042 colormap gray; title('Measured image'); drawnow;
    0043 % Parameters for TVDN
    0044 param.verbose = 1; % Print log or not
    0045 param.gamma = 1e-1; % Converge parameter
    0046 param.rel_obj = 1e-4; % Stopping criterion for the TVDN problem
    0047 param.max_iter = 200; % Max. number of iterations for the TVDN problem
    0048 param_TV.max_iter_TV = 100; % Max. nb. of iter. for the sub-problem (proximal TV operator)
    0049 param.nu_B2 = 1; % Bound on the norm of the operator A
    0050 param.tol_B2 = 1e-4; % Tolerance for the projection onto the L2-ball
    0051 param.tight_B2 = 0; % Indicate if A is a tight frame (1) or not (0)
    0052 param.max_iter_B2 = 500;
    0053 % Tolerance on noise
    0054 epsilon = sqrt(chi2inv(0.99, numel(ind)))*sigma_noise;
    0055 % Solve TVDN problem
    0056 sol = sopt_mltb_solve_TVDN(y, epsilon, A, At, param);
    0057 % Show reconstructed image
    0058 figure(2);
    0059 subplot(122); imagesc(sol); axis image; axis off;
    0060 colormap gray; title('Reconstructed image'); drawnow;
    0061
    0062 %% Second problem: Reconstruct from 33% of Fourier measurements
    0063 % Composition (Masking o Fourier)
    0064 A = @(x) Ma*reshape(fft2(x)/sqrt(numel(im)), numel(x), 1);
    0065 At = @(x) ifft2(reshape(Ma'*x(:), size(im))*sqrt(numel(im)));
    0066 % Select 33% of Fourier coefficients
    0067 y = A(im);
    0068 % Add Gaussian i.i.d. noise
    0069 sigma_noise = 10^(-input_snr/20)*std(im(:));
    0070 y = y + (randn(size(y)) + 1i*randn(size(y)))*sigma_noise/sqrt(2);
    0071 % Display the downsampled image
    0072 figure(3); clf;
    0073 subplot(121); imagesc(real(At(y))); axis image; axis off;
    0074 colormap gray; title('Measured image'); drawnow;
    0075 % Tolerance on noise
    0076 epsilon = sqrt(chi2inv(0.99, 2*numel(ind))/2)*sigma_noise;
    0077 % Solve TVDN problem
    0078 sol = sopt_mltb_solve_TVDN(y, epsilon, A, At, param);
    0079 % Show reconstructed image
    0080 figure(3);
    0081 subplot(122); imagesc(real(sol)); axis image; axis off;
    0082 colormap gray; title('Reconstructed image'); drawnow;