np = 32; I = double(checkerboard(np)); m = size(I,1); Noisy = imnoise(I,'gaussian',0,.1); subplot(221);imshow(I,[]); title('Original'); subplot(222);imshow(Noisy,[]); title('Noisy'); tol = 5.e-8; maxit = 100; u0 = Noisy(:); t = 3; if 1; t0 = cputime; [u1,iter,nf] = myGD(@TVL2N,u0,tol,maxit,u0,t,m); tcpu = cputime - t0; [f,g] = TVL2N(u1,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)) end; if exist('myCG'); t0 = cputime; [u2,iter,nf] = myCG(@TVL2N,u0,tol,maxit,u0,t,m); tcpu = cputime - t0; [f,g] = TVL2N(u2,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(u1,m,m); subplot(223);imshow(U,[]); title('Denoised by GD'); U = reshape(u2,m,m); subplot(224);imshow(U,[]); title('Denoised by CG-PR');