% test script for TVL2 denoising

% original image Io
clear;
Io = double(checkerboard(32));

% noisy image In
randn('state',0); sigma = 0.1;
In = imnoise(Io,'gaussian',0,sigma);
mu = 2;

% denoised image Idz and Idm
t0 = cputime;
[Idz,Iter,Nf] = zysolve(In,mu);
Tcpuz = cputime - t0;
errz = norm(Idz(:)-Io(:))/norm(Io(:));
fprintf('zysolve:  Iter %3i, Nf %4i, Tcpu  %6.2e, Rel_Err = %6.2e\n\n',...
    Iter,Nf,Tcpuz,errz)
t0 = cputime;
[Idm,Iter,Nf] = mysolve0(In,mu);
Tcpum = cputime - t0;
errm = norm(Idm(:)-Io(:))/norm(Io(:));
fprintf('mysolve:  Iter %3i, Nf %4i, Tcpu  %6.2e, Rel_Err = %6.2e\n\n',...
    Iter,Nf,Tcpum,errm)

% plotting Io, In, Idz, Idm
subplot(221);imshow(Io,[]);
title('Original');
subplot(222);imshow(In,[]); 
title('Noisy');
subplot(223);imshow(Idz,[]);     
title('Denoised by zysolve');
xlabel(sprintf('error %5.3f, time %5.3f',errz,Tcpuz));
subplot(224);imshow(Idm,[]);     
title('Denoised by mysolve');
xlabel(sprintf('error %5.3f, time %5.3f',errm,Tcpum));
