np = 32; I = double(checkerboard(np)); m = size(I,1); Noisy = imnoise(I,'gaussian',0,.1); subplot(131);imshow(I,[]); title('Original'); subplot(132);imshow(Noisy,[]); title('Noisy'); tol = 1.e-8; maxit = 200; u0 = Noisy(:); t = 3; t0 = cputime; [u,iter,nf] = zGD(@TVL2N,u0,tol,maxit,u0,t,m); tcpu = cputime - t0; [f,g] = TVL2N(u,u0,t,m); fprintf(' zGD: iter %3i, nf = %4i, tcpu = %6.2e\n',iter,nf,tcpu) fprintf(' zGD: f = %12.6e, norm(g) = %9.3e \n\n',f,norm(g)) if exist('myGD'); t0 = cputime; [u,iter,nf] = myGD(@TVL2N,u0,tol,maxit,u0,t,m); tcpu = cputime - t0; [f,g] = TVL2N(u,u0,t,m); fprintf('myGD: iter %3i, nf = %4i, tcpu = %6.2e\n',iter,nf,tcpu) fprintf('myGD: f = %12.6e, norm(g) = %9.3e \n\n',f,norm(g)) end U = reshape(u,m,m); subplot(133);imshow(U,[]); title('Denoised');